Showing results for 
Search instead for 
Did you mean: 

Error when creating pages with Canvas API

Jump to solution

I am writing a tool to move Moodle courses to Canvas.  The basic process is to run SQL scripts to extract data from the Moodle database and then to use the Canvas API to create the corresponding items in Canvas.  I have run into an issue.  Some of my pages will create, others will not.  The error I am getting is shows in the debug output below.  How can I determine what is causing the internal_server_error?  Are there any special rules on the wiki_page[body] content?  (html/css is included in the wiki_page[body])

The debug output below is an example of on of the pages that failed.


Labels (1)
1 Solution

Accepted Solutions

Solution found: the data must be UTF8 encoded prior to passing to Canvas API.

View solution in original post

8 Replies
Community Member

Hi Martin,

I'm just curious, why are you going this route rather than using the course import tool with a Moodle course export package?


We have several reasons for using this method:

1. CSS used in Moodle is different than the CSS in Canvas is different. Thus, each page, discussion and assignment with CSS formatting will need manual editing if we used the import method into Canvas.  Moodle SQL -> transform data with php --> use Canvas API calls to build course

2. The LTI items in Moodle do not build LTI connections in Canvas.  Each Canvas shell would need to be touch to create the LTI connections and to add the external tool to the course.

3. We currently use Alfresco as a repository for files.  We have decided to use the Files section of Canvas to store the course level files.  Again, after a course inport, someone would need to touch each shell to add the file and recreate the links to the files.  With the Canvas API, I can upload files from an external URLnd link them to the appropriate section of the Canvas shell

4. Question import.  It seems that the answers of some of the questions do not match to the correct answer after the import.  Canvas recommended that we not import the question banks, but go back the the publisher and load the question banks from the publisher instead of from Moodle.  The issue is that many of the questions that we have in Moodle were generated by faculty, not by publishers.  Thus, we need a sound method to move the question banks form Moodle to Canvas.

5. Adding Course and Unit home pages to each Canvas shells that do not exist in Moodle. 

Automated processes are much better than manual


Solution found: the data must be UTF8 encoded prior to passing to Canvas API.

View solution in original post

Makes sense, thanks for clearing that up.

I'm wondering if you can help me. I'm teaching myself how to use some of this API stuff and I'm stuck. I can get a new page created but I cannot get the new page to contain text or update the page with text. I also would like to use some HTML rather than just straight text. I'm using Terminal on a MAC.


-d wiki_page[body]=“<p><a href="">Bacteria Grow Lab</a></p>”


-bash: syntax error near unexpected token ‘<‘


-d wiki_page[body]=New+page+2


a blank wiki page

Creating the pages is great but unless I can figure out where I'm going wrong on updating the text I'm not sure I'll be able to use this. Would you be able to offer some direction?

Hi Tricia,

I think the problem with:

-d wiki_page[body]=“<p><a href="">Bacteria Grow Lab</a></p>”

Is the clashing double quotes. It should work it you change the inner double quotes with single quotes:

-d wiki_page[body]=“<p><a href=''>Bacteria Grow Lab</a></p>”

Let me know if this fixes things.


Alex, Thank you for the help. I tried the double quotes outside and single quotes inside. I received the same error message: -bash: syntax error near unexpected token ‘<‘. I then tried single quotes outside and double quotes inside. I received the same error message. I think the problem is the < symbol somehow. Suggestions? - Tricia J.


I think you are right the problem is the '<' specially the fact that '<' is not a proper character for a URL. You will need to use -data--urlencode instead of -d.

-data--urlencode "wiki_page[body]=<p><a href=''>Bacteria Grow Lab</a></p>"

I believe that is the right syntax. There is more information in man curl if you want to check it out yourself.

Let me know if this works.