Get Courses API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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