How do you call the API from an exteral server?

Jump to solution
tjones1
Community Novice

I have an LTI tool working on a secure server.

I'm trying to GET a specific Assignment with Jquery ajax so I can PUT it back with an update to the external_tool_tag_attributes: { url:

$.ajax({

            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);// or //json_decode(data);

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

                console.log( "jsonp data: "+data );// undefined  parser error in their return data

            },

            error: function (jqXHR, status)

            {

                console.log( "ERR status: "+status ); // parser error

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

            }

        });

But it returns with errors:

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

I can paste the url+token in the browser and it returns what I need.

I've tried other API calls with no success.

What is the best way to call the API from an external server?

Labels (2)
1 Solution
tjones1
Community Novice
Author

For all noobies like me... Learn to cURL

No more errors.

View solution in original post