czehner1
Community Participant

API Get User by Login_ID

Jump to solution

Hello!

Having a bit of trouble with the REST API. We are attempting to get a singular user from an API, but need to do so from a specific field, that field being the login_id.

We have found success is using this call:

 

 

{domain}/api/v1/users/sis_user_id:{sis_id}

 

 

but when we try to do the same with login_id instead of sis_user_id, we get a message saying "The specified resource does not exist." 

Is there another way we can phrase this call to make it work? I haven't found anything on the community forums nor documentation as of yet.

Thanks!

Tags (3)
0 Kudos
1 Solution
James
Community Champion

@czehner1 

The sis_ notation is specific to SIS IDs. There is a list of ones that you can use in the API documentation.

If the token making the API call has admin rights, then you can use the List users in account endpoint of the Users API and use the search_term parameter. The description mentions " Queries by administrative users will search on SIS ID, login ID, name, or email address."

Note that searching is not as fast as a direct reference by Canvas ID or SIS ID.

The search looks at multiple fields, matches partial values, and may return multiple responses. You will need to filter the responses to find the one that you're looking for. For example, if I search for "jsmith" at our institution, I come up with 11 responses, only one of which has a login id of jsmith. The others might be cjsmith or jsmith1.

Also note that you need at least 3 characters to do a search and using a short search can return a lot of responses. The search appears to be capped at 15 responses per search, so you may need to use pagination to get the correct response.

Depending on your application, you may want to store IDs locally rather than searching by login id on a regular basis. I have a local database that contains the login ID, Canvas ID, and SIS ID so that I can don't have to use Canvas for that information.

View solution in original post

2 Replies
James
Community Champion

@czehner1 

The sis_ notation is specific to SIS IDs. There is a list of ones that you can use in the API documentation.

If the token making the API call has admin rights, then you can use the List users in account endpoint of the Users API and use the search_term parameter. The description mentions " Queries by administrative users will search on SIS ID, login ID, name, or email address."

Note that searching is not as fast as a direct reference by Canvas ID or SIS ID.

The search looks at multiple fields, matches partial values, and may return multiple responses. You will need to filter the responses to find the one that you're looking for. For example, if I search for "jsmith" at our institution, I come up with 11 responses, only one of which has a login id of jsmith. The others might be cjsmith or jsmith1.

Also note that you need at least 3 characters to do a search and using a short search can return a lot of responses. The search appears to be capped at 15 responses per search, so you may need to use pagination to get the correct response.

Depending on your application, you may want to store IDs locally rather than searching by login id on a regular basis. I have a local database that contains the login ID, Canvas ID, and SIS ID so that I can don't have to use Canvas for that information.

dsmith73
New Member
if by login_id, you mean their email, then you can pass this:
https://<canvas_baseURL>/api/v1/accounts/<canvas_account>/users?search_term=<login_id>

Since email addresses are unique, it will return an array with 1 result
[
{
"created_at": "2022-10-26T19:19:01-1:00",
"id": 999999,
"integration_id": null,
"login_id": "email@domain.com",
"name": "xxxxxxxxxxxxx",
"short_name": "xxxxxxxxxxx",
"sis_import_id": 9999999,
"sis_user_id": "XXXXXXX9999999",
"sortable_name": "xxxxxxxxxx"
}
]

Then you just load your response[0].id and whatever else you need for your next step in the flow.

Hope this helps!
0 Kudos