How to generate new boards using C# with Miro REST API integration

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?

Looks like you’re misunderstanding the OAuth 2.0 flow. Don’t try to get a token by posting directly to the app-install URL. Here’s what you need to do: redirect the user to the authorization URL first, then capture the authorization code when the service sends it back. Once you’ve got that code, exchange it with your client credentials for an access token. Make sure you include this valid access token in the Authorization header when creating the board. Just because you get an OK response doesn’t mean your token actually works.

You’re not doing the OAuth flow right. That app-install URL isn’t an API endpoint - you can’t just hit it directly. First, set up a proper redirect URI in your Miro app settings. Then handle the authorization code callback when it comes back. Once you get that auth code, exchange it for an access token at https://api.miro.com/v1/oauth/token using your client credentials and the code. That’s the token you use in your Authorization header for board creation. I dealt with this exact issue last month - nail the OAuth flow and everything else works fine.

you’re missing the auth header when creating the board. make sure to add the bearer token to your createRequest, not just in the auth step. also, consider using v2 instead of v1 - it’s way more reliable now.