The Instructure Community will enter a read-only state on November 22, 2025 as we prepare to migrate to our new Community platform in early December.
Read our blog post for more info about this change.
Found this content helpful? Log in or sign up to leave a like!
Hello all,
I am trying to find out why my API is not pulling all courses for an account. I just created ~275 courses and I used the following API:
GET: MYCANVAS/api/v1/accounts/1/courses?enrollment_term_id=8&per_page=500
and I get a list of about 100 of the courses but I know there is more. I even searched manually via the URL code for courses and I know they exist in this account. Any idea what I may be doing wrong? I searched on the API site and could not find anything useful.
Jason
Solved! Go to Solution.
That is correct. You run a get call for each page that is returned by the Link header until the Link header tells you that you are on the last page. In python, it looks something like this:
url = MYCANVAS/api/v1/accounts/1/courses?enrollment_term_id=8&per_page=100
r = requests.get(url, headers = header, data = payload)
j = json.loads(r.text)
# insert stuff to do with object j here.
while r.links['current']['url'] != r.links['last']['url']:
r = requests.get(r.links['next']['url'], headers=header)
j = json.loads(r.text)
# do more stuff with the new object j
I believe the maximum return value for per page is 100. You'll have to include some pagination code in your GET script to return the rest of them:
This makes sense, but I am an admitted API novice. Would I have to run separate APIs for each page?
That is correct. You run a get call for each page that is returned by the Link header until the Link header tells you that you are on the last page. In python, it looks something like this:
url = MYCANVAS/api/v1/accounts/1/courses?enrollment_term_id=8&per_page=100
r = requests.get(url, headers = header, data = payload)
j = json.loads(r.text)
# insert stuff to do with object j here.
while r.links['current']['url'] != r.links['last']['url']:
r = requests.get(r.links['next']['url'], headers=header)
j = json.loads(r.text)
# do more stuff with the new object j
Very cool. This looks like it uses Requests in Python right? It is not Python 3?
That is correct. You can find numerous examples of how to use it here:
Unfortunately I am using Python 3 and having issues updating the code. Do you have any suggestions on conversion? I tried the 2to3 module but it doesnt seem to take.
I don't have any suggestions unfortunately, I'm using Python 2.7 on a Windows machine. I only learned enough Python to do some basic API stuff. I'm not actually a programmer.
Me either. I found it one of the more straightforward languages. It is quick and useful. Thanks for all the insight though.
Community helpTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in