I use a C# app to hit the api. I can't figure out how to create a cover. Help appreciated.
Here's a working sample of code I use to add two labels for reference.
To add a cover I've tried several things such as:
url = "https://api.trello.com/1/cards/629b8xxxxxb301af2?key=mykey&token=mytoken&cover={\"color\",\"green\"}";
Rest of the code:
var httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Method = "PUT";
httpRequest.ContentType = "application/json";
var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
Maybe I'm missing something, but I've tried several times to convert this to c# syntax. I'm clueless.
Here is a full C# sample:
string key = "todo";
string token = "todo";
string cardId = "todo";
string coverAsJson = "{\"cover\":{\"color\":\"green\"}}";
Uri uri = new Uri($"https://api.trello.com/1/cards/{cardId}?key={key}&token={token}");
var httpClient = new HttpClient();
await httpClient.PutAsync(uri, new StringContent(coverAsJson, Encoding.UTF8, "application/json"));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@David Bakkers is right. The cover itself need to be a json payload and not a query-parameter
If you do not wish to write all the C# by yourself you can also check out NuGet Package: TrelloDotNet that support manipulation of cover + a lot more: https://www.nuget.org/packages/TrelloDotNet
Or get some inspiration here:
https://github.com/rwjdk/TrelloDotNet/blob/main/TrelloDotNet/TrelloDotNet/TrelloClient.Covers.cs
And here:
https://github.com/rwjdk/TrelloDotNet/blob/main/TrelloDotNet/TrelloDotNet/Model/CardCover.cs
In the source-code as covers can be quite hard to get working correctly
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yep, I found your amazing work after I posted this. I emailed you yesterday. Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Glenn Williams
When doing PUT requests to that endpoint, the cover parameter is a request QUERY parameter, not a request PATH parameter, so it should be into the BODY of the request
Your request should be:
PUT
https://api.trello.com/1/cards/629b8xxxxxb301af2?key=mykey&token=mytoken
BODY
{
"cover": {
"color": "green"
}
}
Yes, you can 'force' query parameters into being path parameters if they have a single value (like key and token) or comma separated values (like idLabels), but everything breaks if they have nested values or an array of values.
Generally speaking, for PUT and POST requests, parameters and their values should be declared in the request body, unless they are mandated to be in the request path (like id for the card's ID).
So, the best format for the request really should be:
PUT
https://api.trello.com/1/cards/629b8xxxxxb301af2
BODY
{
"key": "myKey",
"token": "myToken",
"cover": {
"color": "green"
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.