Handling Pages Externally - Finally a page_id

jweedling
Community Novice
4
2538

It’s no secret that externally handling pages was difficult with Canvas. The problem was the API didn’t expose an ID for the page, so you needed to look it up by title.

https://<ORG>.instructure.com/courses/<COURSE ID>/pages/<MY-PAGE-TITLE>

Simple enough if you know the title and the users never change it, but that’s just wishful thinking.

I’m not sure when this was released, but Mark mentioned it and I couldn’t be happier.  So now the page details include a page_id field you can store if your external system needs to link back to a specific page.

{     
   "title": "My Page Title",    
   "created_at": "2018-01-05T15:54:00Z",    
   "url": "my-page-title",    
   "editing_roles": "teachers",    
   "page_id": 1234,
   
   "last_edited_by": {        
      "id": 4321,        
      "display_name": "Jason",        
      "avatar_image_url": "...",        
      "html_url": "..."    
   }
}

The API call is just as you would expect.

https://<ORG>.instructure.com/api/v1/courses/<COURSE ID>/pages/<PAGE ID>

Or, if you still need to use the page title.

https://<ORG>.instructure.com/api/v1/courses/<COURSE ID>/pages?search_term=<My Page Title>

Thanks Canvas for continuing to make things better!

Originally posted by me at codesequences.com, Canvas LMS Page Handling Improvements – Code Sequences 

Tags (2)
4 Comments
James
Community Champion

The page ID has been there for a while, I kept on seeing it but wondering what to do with it. Thanks for explaining that it works instead of the URL that is in the documentation.

A couple of small points and a question ...

The wording in your post is a little confusing, though. You wrote 

The API call is just as you would expect.

but then gave an example of a non-API call. It works for both the API and non-API versions.

The other thing is that it's not <My Page Title> as much as the page URL, which is a reasonable approximation of the page title.

And finally, why does your last example use search_term= parameter? That's another one that I didn't know about, but it makes some sense given the push at Project Khaki to make Canvas searchable. Using the search_term= query parameter allows you to return a list of pages that contain the search term in the title, but if you want a specific page, there's no need to the search_term, just put the url like we always have.

jweedling
Community Novice
Author

Thanks James, I've corrected the API url (it got mangled when I was writing the post. 

And you are correct that it's more of an approximation for the page url based on the original title.

pklove
Community Champion

Its interesting that the page_id isn't in the API documentation (Pages - Canvas LMS REST API Documentation).  Given that it isn't in there, is it something that has just been overlooked for inclusion, or is it something that isn't officially supported and we use at our own risk?

jweedling
Community Novice
Author

I'm not sure if this is a case of the documentation being out of date or not.