- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am having a issue trying to update a course name in c#. I perform the PUT and I get a 200 OK back but the name does not change.
Here are the details:
URL: /api/v1/courses/1724
Content: "{\"id\":1724,\"name\":\"2 Test - 1 Test - Competing in and with China\"}": - this is the data that is used to initialize the StringContent Object
string jsonData = JsonConvert.SerializeObject(data); HttpContent content = new StringContent(jsonData);
var response = (HttpResponseMessage)Task.Run(async () => await client.PutAsync(urlCommand, content)).Result;
This returns a 'StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1' but the data is never updated
Does anyone have any ideas??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@aday ,
I can't help with C#, but your parameters are improperly formed. Canvas is accepting the call, ignoring anything it doesn't recognize (which is the entire payload), saying "OK" to the empty list of changes, and not making any changes.
The Update a course endpoint requires that all of the parameters be wrapped inside the course property.
ID is not supported as a parameter, but it is specified in the path portion of the URL. Do not include it in your content as it will be ignored.
The course name is course[name] as a query parameter. In JSON, it would look like: { "course" : { "name" : "2 Test - 1 Test - Competing in and with China" } }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@aday ,
I can't help with C#, but your parameters are improperly formed. Canvas is accepting the call, ignoring anything it doesn't recognize (which is the entire payload), saying "OK" to the empty list of changes, and not making any changes.
The Update a course endpoint requires that all of the parameters be wrapped inside the course property.
ID is not supported as a parameter, but it is specified in the path portion of the URL. Do not include it in your content as it will be ignored.
The course name is course[name] as a query parameter. In JSON, it would look like: { "course" : { "name" : "2 Test - 1 Test - Competing in and with China" } }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks I had started down the route also but was still getting the same issues. Turns out i needed to set the encoding and media type.
Snippet
HttpContent content = new StringContent(jsonData, Encoding.UTF8, "application/json");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
this might help in the near future:
using static Newtonsoft.Json.Formatting;
