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

How do I retrieve Single Enrollment by id?

Jump to solution

Hi guys, I'm new to Canvas. I'm trying to retrieve Canvas Enrollment record using api.

I could retrieve Enrollments for a user,

/api/v1/users/2/enrollments

and for a course

/api/v1/courses/1/enrollments

What I'm trying to achieve is reading a enrollment independently by id, I tried below too.

/api/v1/enrollments/1

But I'm getting 404 - Not found error.

Appreciate any help to find the correct Api call please.

Cheers!

1 Solution

Accepted Solutions
pklove
Community Champion

I think that, as you have found, you cannot do it unless you also have the account id.  If you want to query an enrolment by id, you are going to have to also store the account_id.

Or, if you are doing this with an admin token and you know who the enrolment belongs to, you might be able to use self and as_user, for example:

    .../api/v1/accounts/self/enrollments/123?as_user=sis_user_id:nktest

View solution in original post

6 Replies
peeriyagama
Community Participant

I'm looking for something similar to,

306354_pastedImage_1.png

But without having to pass account Id. I believe Enrollment object has it's own unique Id. Is this supported by Canvas LMS? Thank you.

Hi Pasan,

Have you looked at the list enrollment api‌?

Here you can get the enrollment id? You can get it by course, section or even user id?

306382_pastedImage_1.png

Also anytime you see account_id you can replace it with the word self.

Ex: /api/v1/accounts/self/terms 

peeriyagama
Community Participant

Thanks for your reply @Brian, Those API calls you have mention are working. Our system stores Enrollment id as external record Id in our system.

Therefore I am trying to retrieve enrollment record just like we can retrieve course account or user (for example get a specific Course: /api/v1/courses/2 will give you only that course).

Not too sure if it's possible in Canvas.

Cheers!

Pasan

pklove
Community Champion

I think that, as you have found, you cannot do it unless you also have the account id.  If you want to query an enrolment by id, you are going to have to also store the account_id.

Or, if you are doing this with an admin token and you know who the enrolment belongs to, you might be able to use self and as_user, for example:

    .../api/v1/accounts/self/enrollments/123?as_user=sis_user_id:nktest

View solution in original post

peeriyagama
Community Participant

I think I'm getting it. Thanks @Peter