I’m working on a WPF project using .NET Core 6.0 in Visual Studio 2022 Community edition. I need to programmatically generate boards through the Miro REST API using C#.
Current Setup
I have my application credentials (AppID and AppSecret) ready for OAuth authentication. I’m using RestSharp library that I installed via NuGet package manager.
The Problem
My authentication step seems to work fine, but when I try to make a POST request to create a new board, I keep getting an “Unauthorized” response from the API endpoint.
My Code
public string MiroAppSettingsUrl = "https://miro.com/app/settings/user-profile/apps";
public string AppID = "myappid";
public string AppSecret = "myappsecret";
internal async void GenerateMiroBoard()
{
try
{
var authClient = new RestClient("https://miro.com/app-install/?response_type=code&client_id=" + AppID);
var authRequest = new RestRequest();
authRequest.Method = Method.Post;
authRequest.AddHeader("Authorization", "Bearer " + AppSecret);
var authResponse = authClient.ExecuteAsync(authRequest);
var authResult = authResponse.Result; // Returns StatusCode: OK
var createClient = new RestClient("https://api.miro.com/v1/boards");
var createRequest = new RestRequest();
createRequest.Method = Method.Post;
createRequest.AddHeader("Accept", "application/json");
createRequest.AddHeader("Content-Type", "application/json");
createRequest.AddParameter("application/json", "{\"name\":\"New Board\",\"sharingPolicy\":{\"access\":\"private\",\"teamAccess\":\"private\"}}", ParameterType.RequestBody);
var createResponse = createClient.ExecuteAsync(createRequest);
var createResult = createResponse.Result; // Returns StatusCode: Unauthorized
}
catch(Exception ex)
{
var errorMsg = ex.Message;
}
}
What am I missing in my authorization flow? How should I properly authenticate to make successful API calls for board creation?