I want to create a board in C# using the Miro (https://miro.com) API


I am building a .NET Core 6.0 WPF application in Visual Studio 2022 Community. I want to create a board in C# using the Miro https://miro.comtable-sale API. I have obtained CliendID and ClientSecret for authentication. I added RestSharp with NuGet and wrote the code below. It goes through to authentication.

After that, I am posting to api.miro.com/v1/board, but I get the error Unauthorized. How can I post?

        public string MiroUserProfileUrl = "https://miro.com/app/settings/user-profile/apps";
public string ClientID = "myclientid";
public string ClientSecret = "myclientsecret";

internal async void CreateBoardAtMiro()
{
try
{
var client = new RestClient("https://miro.com/app-install/?response_type=code&client_id="+ ClientID);
var request = new RestRequest();
request.Method = Method.Post;
request.AddHeader("Authorization", "Bearer " + ClientSecret);
var response = client.ExecuteAsync(request);
var result = response.Result; //StatusCode: OK, Content-Type: text/html, Content-Length: )

var boardMakeClient = new RestClient("https://api.miro.com/v1/boards");
var boardMakerequest = new RestRequest();
boardMakerequest.Method = Method.Post;
boardMakerequest.AddHeader("Accept", "application/json");
boardMakerequest.AddHeader("Content-Type", "application/json");
boardMakerequest.AddParameter("application/json", "{\"name\":\"Untitled\",\"sharingPolicy\":{\"access\":\"private\",\"teamAccess\":\"private\"}}", ParameterType.RequestBody);
var boardMakeResponse = boardMakeClient.ExecuteAsync(boardMakerequest);
var boardMakeResult = boardMakeResponse.Result; //StatusCode: Unauthorized, Content-Type: application/json, Content-Length: 135)
}
catch(Exception exception)
{
var error = exception.Message;
}
}

enter image description here

enter image description here

enter image description here

 

enter image description here


2 replies

Userlevel 3
Badge

Hey @circle extra!

We’ve converted your post to a support request ticket. Our tech team will reach out to you shortly via email so please stay tuned for updates on this! 🙂

Userlevel 4

Hi @circle extra 

I see you are passing your Client Secret to the Authorization header - this is not the correct authorization you need. 

In order to get a valid Authorization token you will need to first go through the Open Auth2 Flow. You can find a tutorial here: https://developers.miro.com/docs/getting-started-with-oauth

Alternatively, you can hard code the Access Token you have retrieved when you manually installed the app into your team (although it is recommended to set up the OAuth2 flow mentioned above)

Reply