Getting unauthorized error when calling Miro API
I’m working on a WPF project with .NET Core 6.0 and trying to integrate with Miro’s REST API to create workspaces programmatically. I have my API credentials set up but running into authentication issues.
The first part of my code handles the OAuth flow correctly, but when I try to make the actual API call to create a board, I get an Unauthorized response. I’m using HttpClient for the requests.
public string AppId = "myappid";
public string AppSecret = "myappsecret";
internal async Task GenerateMiroWorkspace()
{
try
{
var authClient = new HttpClient();
var authEndpoint = $"https://miro.com/app-install/?response_type=code&client_id={AppId}";
var authRequest = new HttpRequestMessage(HttpMethod.Post, authEndpoint);
authRequest.Headers.Add("Authorization", $"Bearer {AppSecret}");
var authResponse = await authClient.SendAsync(authRequest);
var authResult = await authResponse.Content.ReadAsStringAsync();
// This part works fine
var apiClient = new HttpClient();
var createRequest = new HttpRequestMessage(HttpMethod.Post, "https://api.miro.com/v1/boards");
createRequest.Headers.Add("Accept", "application/json");
var payload = new
{
title = "New Workspace",
policy = new
{
visibility = "private",
permissions = "private"
}
};
createRequest.Content = new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json");
var createResponse = await apiClient.SendAsync(createRequest);
var createResult = await createResponse.Content.ReadAsStringAsync();
// Getting 401 Unauthorized here
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
What am I missing in the authentication process? Do I need to include additional headers or use a different token format?