cancel
Showing results for 
Search instead for 
Did you mean: 
fpettigrosso
Community Participant

How to get all the courses from an university

Jump to solution

Hello,

I do not know if this possible or not, is there a way to get a list of all the courses in a university's canvas lms regardless if the user accessing the information is enrolled in the course or not either via the interface and/or api?  I just started to research this and I was wondering if anyone found a way or knows of a good place to start.

1 Solution

Accepted Solutions

If your account that you applied for the admin token under is the account with the most privileges and you can see all the institutional courses while logged into the Canvas UI, then your $security_token variable should be okay.

As for the :account_id parameter that's the string of numbers that appears in the request URL after api/v1/accounts. From your code example it's a number 1.

What happens when you are logged in your account and use a web browser to view the API URL in your code example? You should see a string of JSON code equivalent to what your API call would return. 10 results is the default number of JSON objects that the API returns. You can change this by adding a per_page=n parameter to the request. If you're getting less than 10 results in the JSON string, that would indicate that you don't have the correct :account_id or admin credentials to see ALL the courses in your institution.

View solution in original post

10 Replies
themidiman
Community Champion

I believe the API endpoint you would use is accounts/courses

You would need admin credentials and potentially use pagination to get through the entire list.

fpettigrosso
Community Participant

That works, but for some reason I only get 7 course when there is over 2,000 courses in our particular instance... You have any insight on that?

Two possible initial scenarios here:

  1. Are you using a root admin token?
  2. Are you using the root account id for the :account_id parameter in the request?
fpettigrosso
Community Participant

I am using an admin token that I made by going to Account/settings and applying for one. I do not know what you mean by the second one so The best way I think I Can answer is by show you the code :smileygrin:

$url_main="https://laskdhfjkahf.instructure.com/api/v1/accounts/1/courses"

$security_token="Iliketoeat"

$header = @{"Authorization"="Bearer "+ $security_token}

$curlly=Invoke-WebRequest -Headers $header   -Method Get   -Uri $url_main  

$curlly = ConvertFrom-Json $curlly.Content

foreach($course in $curlly)

{

    $course.name

}

If your account that you applied for the admin token under is the account with the most privileges and you can see all the institutional courses while logged into the Canvas UI, then your $security_token variable should be okay.

As for the :account_id parameter that's the string of numbers that appears in the request URL after api/v1/accounts. From your code example it's a number 1.

What happens when you are logged in your account and use a web browser to view the API URL in your code example? You should see a string of JSON code equivalent to what your API call would return. 10 results is the default number of JSON objects that the API returns. You can change this by adding a per_page=n parameter to the request. If you're getting less than 10 results in the JSON string, that would indicate that you don't have the correct :account_id or admin credentials to see ALL the courses in your institution.

View solution in original post

fpettigrosso
Community Participant

If you dont mind showing me... where would you put the "per_page=n" and I am getting exactly 10 so I'm guessing that is the problem.

themidiman
Community Champion

If you're using a GET request then it's a query parameter on the API URL string:

https://institution.instructure.com/api/v1/accounts/:account_id/courses?per_page=50

50 is the max number of objects you can request via the API per request. That's where Pagination is used as you would have to use the 'next' link that is returned in the response header to request the next set of objects. But I will reiterate if you're getting less than 10 without the per_page setting then something is wrong with your account permissions or the :account_id parameter you're sending to the API. If I'm right then setting the per_page to a number greater than 10 will probably not net you more than the 7 objects the API is sending back to you.

fpettigrosso
Community Participant

Yea, The per page to 10000 and I get back 100 so its the right account, thank you! I just have to figure out how to use Pagination and I should be good Smiley Happy

kim
Community Contributor

Hi Franco! It sounds like you were able to successfully get the list of courses through the API. You can also obtain this list from within Canvas. Settings -> Reports tab -> Provisioning report. Click on 'configure' for the Provisioning report. Leave the term at the default (all terms). Check the box next to courses and run the report.