Issue with Miro API Integration
I’m working on a WPF project using .NET Core 6.0 in Visual Studio 2022. I need to connect to the Miro platform API to generate new boards programmatically.
I’ve set up my application credentials (app ID and secret key) for OAuth authentication. Using HttpClient library, I’m trying to make API calls but running into authorization problems.
The authentication step seems to work fine, but when I try to POST to the boards endpoint, I get a 401 Unauthorized response. What am I missing in my implementation?
public class MiroApiService
{
private string AppId = "myappid";
private string SecretKey = "mysecretkey";
private string BaseAuthUrl = "https://miro.com/oauth/authorize";
public async Task<bool> GenerateNewBoard()
{
try
{
// Authentication request
var authClient = new HttpClient();
var authUrl = $"{BaseAuthUrl}?response_type=code&client_id={AppId}";
var authRequest = new HttpRequestMessage(HttpMethod.Post, authUrl);
authRequest.Headers.Add("Authorization", $"Bearer {SecretKey}");
var authResponse = await authClient.SendAsync(authRequest);
// Board creation request
var apiClient = new HttpClient();
var boardEndpoint = "https://api.miro.com/v1/boards";
var boardRequest = new HttpRequestMessage(HttpMethod.Post, boardEndpoint);
boardRequest.Headers.Add("Accept", "application/json");
var boardData = new
{
name = "My New Board",
policy = new
{
access = "private",
teamAccess = "private"
}
};
var jsonContent = JsonSerializer.Serialize(boardData);
boardRequest.Content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
var boardResponse = await apiClient.SendAsync(boardRequest);
// Getting 401 Unauthorized here
return boardResponse.IsSuccessStatusCode;
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
return false;
}
}
}
Any suggestions on proper authentication flow for this scenario?