cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
vRaj1
Community Participant

Sample Json for Edit & Delete a user for API

Jump to solution

I would like to edit the user through API C#.  Can I have a sample Json for both?

I'm referring to this link for edit a user.

0 Kudos
1 Solution

Accepted Solutions
James
Community Champion

In many cases, you can use both, but the SIS IDs always need prefaced. See SIS IDs in the documentation.

If a person had a SIS User ID of 12345, then you would need to use: { "id" : "sis_user_id:12345" }

There are a few places where SIS IDs are not supported, although it's not always clear where that is. Normally if it says :user_id or :course_id and there is a corresponding sis_id counterpart, then you can use it. If it just says :id then you may have to double check. I keep a copy of the the Canvas IDs for courses, sections, users in a local database after creation so I can refer to them in my API calls and almost never use the SIS IDs directly. I think that was because not as much had a SIS alternative when I started using Canvas.

View solution in original post

0 Kudos
4 Replies
James
Community Champion

@vRaj1 

The JSON works the same was as other snippets we've recently supplied you. Once you  understand the process, you won't need to keep asking for snippets.

For editing a user, everything needs wrapped inside a user property. 

The query parameter form

user[name]=John%20Smith&user[short_name]=Johnny

would be encoded as

{ "user" : { "name" : "John Smith", "short_name" : "Johnny" } }

For deleting a user, there is no JSON needed.

Raj82
Community Participant

Thanks for the reply. I already tried the below way and having an error -> The remote server returned an error: (422) Unprocessable Entity.

For Editing

My sample Endpoint is :  https://xxxx/api/v1/users?123456

Sample Json: "{\"student\":{\"name\":\"yyyyy\",\"short_name\":\"xxx\",\"time_zone\":\"singapore\",\"email\":\"alice.adeney.26@nexus.edu.sg\"}}". i tried both "student" & User

Many Thanks.

Raj82
Community Participant

Dear Navigator,

Please ignore my previous messages. Actually, I was using SIS ID as an id (used as a parameter) but when I use Id from API response, it's working. 

for example :  

[{"id":162,"name":"Rania Adel"

What I assumed is, API use "sis_user_id" as an ID field

If possible, please clarify for me which one is right to use as an ID field (for API point of view).

Many thanks.

James
Community Champion

In many cases, you can use both, but the SIS IDs always need prefaced. See SIS IDs in the documentation.

If a person had a SIS User ID of 12345, then you would need to use: { "id" : "sis_user_id:12345" }

There are a few places where SIS IDs are not supported, although it's not always clear where that is. Normally if it says :user_id or :course_id and there is a corresponding sis_id counterpart, then you can use it. If it just says :id then you may have to double check. I keep a copy of the the Canvas IDs for courses, sections, users in a local database after creation so I can refer to them in my API calls and almost never use the SIS IDs directly. I think that was because not as much had a SIS alternative when I started using Canvas.

View solution in original post

0 Kudos