I'm currently trying to implement a Trello integration into Unity using the Trello Rest API. I am able to display the a given board with it's lists and cards. No problem so far. But as soon as I try to create or update a card, I get an unauthorized exception. My Token has write permission and when I run the command through ReqBin Curl tester everything is fine with the command and the card will be added to the board. But the HTTP-Request gives me the unauthorized error.
The curl command that works
curl -X POST https://api.trello.com/1/cards?idList={id_list}&key={app_key}&token={app_token} -d '{"name":"TestCard","desc":"description"}' --header "Content-Type: application/json"
The HTTP-Request function (data is currently an empty string, since I'm currently trying to add the data to the url)
private static async Task<bool> SendTrelloPostHttpRequest(string url, string data) {
Debug.Log(url);
using (var httpClient = new HttpClient()) {
using (var request = new HttpRequestMessage(System.Net.Http.HttpMethod.Post, url)) {
HttpResponseMessage response = await httpClient.PostAsync(url, new StringContent(data));
if (!response.IsSuccessStatusCode) {
Debug.LogError("Failed " + response.StatusCode);
return false;
} else {
Debug.Log("Sucessfully " + response.Content.ToString());
return true;
}
}
}
And this is the url I use to run the request
string url = $"{_trelloAPI}cards?idList={listId}&key={_trelloAppKey}&token={_trelloAppToken} -d '{{\"name\":\"{card.Name}\",\"desc\":\"{card.Desc}\"}}\' --header \"Content-Type: application/json\"";
I have no Idea why the curl request works and the http-request not, I double checkt everything but I can't spot any errors