Hey everyone, I’m working on a .NET Core 6.0 WPF app in VS 2022 Community. I’m trying to create a Miro board using their API, but I’m hitting a snag.
I’ve got my ClientID and ClientSecret, and I’m using RestSharp for the HTTP requests. The authentication part seems to work fine, but when I try to create a board, I keep getting an ‘Unauthorized’ error.
Here’s a simplified version of what I’m doing:
public async Task CreateMiroBoard()
{
var authClient = new RestClient("https://api.miro.com/v1/oauth/token");
var authRequest = new RestRequest().AddJsonBody(new
{
grant_type = "client_credentials",
client_id = "my_client_id",
client_secret = "my_client_secret"
});
var authResponse = await authClient.PostAsync<TokenResponse>(authRequest);
var boardClient = new RestClient("https://api.miro.com/v1/boards");
var boardRequest = new RestRequest()
.AddHeader("Authorization", $"Bearer {authResponse.access_token}")
.AddJsonBody(new { name = "My New Board" });
var boardResponse = await boardClient.PostAsync(boardRequest);
if (boardResponse.StatusCode == System.Net.HttpStatusCode.Unauthorized)
{
Console.WriteLine("Unauthorized! What am I doing wrong?");
}
}
Any ideas what I might be missing? Thanks in advance for your help!
I’ve encountered a similar issue when working with the Miro API. The problem might be related to the scope of your OAuth token. Make sure you’ve included the ‘boards:write’ scope when setting up your app in the Miro developer portal.
Also, double-check that you’re using the correct API endpoint. For board creation, you should be using ‘https://api.miro.com/v2/boards’ instead of the v1 endpoint.
Lastly, ensure your access token is valid and not expired. You can verify this by making a GET request to ‘https://api.miro.com/v2/users/me’ with your token. If it returns user info, your token is valid.
If these suggestions don’t resolve the issue, consider logging the full response from the API to get more detailed error information. This can provide valuable insights into what’s going wrong.
I’ve been down this road before, and it can be frustrating. One thing that might help is to double-check your API version. Miro’s been pushing developers towards v2 of their API, which has some differences from v1.
Try updating your board creation endpoint to ‘https://api.miro.com/v2/boards’ and see if that helps. Also, make sure your app has the right permissions set up in the Miro developer portal. ‘boards:write’ is crucial for creating boards.
If you’re still hitting a wall, I’d recommend using Fiddler or Postman to test your API calls directly. This can help isolate whether the issue is with your C# code or something on Miro’s end.
Lastly, don’t forget to check Miro’s API documentation for any recent changes. They update their API pretty frequently, and sometimes these changes can catch you off guard.