Update Wiki Page HTML via API

Jump to solution
jared_flaherty
Community Contributor

Heylo-

So, anybody know a way to update the HTML of a Wiki Page via the API?    

We created thousands of Practice Courses for our instructors when we switched to Canvas last year.    In one of the Wiki Pages, there is an iframe that has a google drive doc url placed in it.      Since google drive will no longer support web hosting starting August 31, 2016, I was hoping there was a way to rewrite the HTML for all of the pages via the API and replace the iframe url.

Thanks!

1 Solution
James
Community Champion

 @jared_flaherty ​,

Yes.

If the pages have differing content, then you do a two-step approach. First get the page, make the changes, and then update the page. Note that when you fetch the page, the fields are not prefixed with wiki_page, but when you update them, they need to be. That is, you can't just take the downloaded object, modify it, and send it back. When you fetch the page, you want the body field. When you update it, store that in wiki_page[body]

If the pages have a consistent content that you can just overwrite without worrying about what was already on the page, then you can just update the page without fetching it first. Put the new body in wiki_page[body] parameter for the PUT.

Note that the body is the html that goes within the <body> ... </body> tags, but it does not include those tags.

Both the Show page and Update/create page API endpoints are documented with the Pages documentation.

You'll need to know the Course ID and URL for each page. The only piece you should need to return for an update is the wiki_page[body] field and it will leave the rest alone.

View solution in original post