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;
}
}