Showing results for 
Search instead for 
Did you mean: 
Community Member

Parse error on API call


I'm using JavaScript to try and retrieve the list of courses and am receiving a jQuery parse error when using $.getJSON.  I have attached my code for your review.

I modified the access_token to protect the innocent 🙂 I also verified that the JSON being returned is in fact valid.

Thank you in advance for your assistance.

Labels (1)
Tags (3)
11 Replies
Community Participant

I'm trying to use the API from JavaScript as well.  I am trying to use an jquery ajax call:

function getCourses(){



    type: "GET",

    url: "",

  // beforeSend: function (xhr) {

  //   xhr.setRequestHeader ("Authorization", "XXXX");

  // },

    headers: {

      "Authorization": "XXXXXX",

      "Access-Control-Allow-Origin": "*"},

    dataType: 'json',

    async: false,

    success: function (){





I get a cross domain errors.

It would be really helpful to have an example of how to get API calls working from client side JavaScript.

Community Participant

I would guess you should  play around with jsonp instead of json for datatype in your javascript if the cross domain errors are persistent. There's lots of documentation online about it. But I could be wrong.

Community Participant

Here is how I'm using jsonp:

I'm trying to GET an Assignment


            type: "GET",            // Type of request to be send

            url: canvasapi,          // url+token to which the request is sent

            contentType: "application/json; charset=utf-8",

            dataType: "jsonp",     // type of data

            success: function(data, status, jqXHR)


                console.log( "success status: "+status );

                console.log( "success data: "+data );

                console.log( "success xhr text: "+jqXHR.responseText );


            jsonp: false,            // should use Callback below

            jsonpCallback: function(data)


                //var asgndata = JSON.parse(data);

                //console.log( "jsonp asgndata: "+asgndata );

                console.log( "jsonp data: "+data );// undefined - parsererror in returned data


            error: function (jqXHR, status)


                console.log( "ERR status: "+status );

                console.log( "ERR xhr text: "+jqXHR.responseText );



It makes it past the CORS cross domain

But I'm getting a parser error so it data is undefined

Screen Shot 2015-07-09 at 11.01.38 AM.png

Community Member

This is the SAME exact error I am getting.

Community Participant

I tried a different API call to see if it caused an error.

Screen Shot 2015-07-10 at 8.21.52 AM.png

It did.

I've added a new question that may help us get some answers.

How do you call the API from an external server?

Community Member

I do have the API's working in PHP. Just not in JS.

Community Participant

I learned to cURL today. Much better.

Community Participant

Curl is cool indeed!

Community Coach
Community Coach

Hi  @belgort ,

I am going through having a look at some of the early days in the Canvas Developers group, and checking in to see if older enquiries have been answered. I also noticed there hasn’t been any discussion on this question in quite some time.

I am wondering, were you ever able to resolve this with the assistance provided? I am hoping I can assume that it is well and truly resolved by now, but if not, please let us know and we can certainly have another look. Alternatively, if have some insights you may be able to share for others that would be awesome too!

I will mark this as assumed answered for the time being, however, by all means please let us know if you still have an outstanding question and we will take a peek!