6. Debugging Errors #
The Bright API, if it’s not happy with its input, isn’t going to give you that much information as to why. It doesn’t produce error messages other than HTTP codes. This is primarily for security reasons. Since we listen on public ports, we don’t want people probing the api, and using the error messages as a guide to on how to gain access.
From curl, if you put an invalid response, you’ll get no data back:
curl 'https://[BRIGHT URL]/bright/api/v2/course.json?sc_app_id=RQIBAXU49I
&sc_secret_key=nCwrTDSy1MzaeyhN0TFfi3uH3huzlu6CNmyHUG5N'
We asked for a jsonc format, which of course doesn’t exist.
The only information you will get is an HTTP error code, in this case 406, ‘Not Acceptable’.
6.1. Fetching HTTP Error Codes from a GET Request #
You can see the HTTP response code for a GET request in curl with the -I flag:
curl 'https://[BRIGHT URL]/bright/api/v2/course.json?
sc_app_id=RQIBAXU49I&
sc_secret_key=nCwrTDSy1MzaeyhN0TFfi3uH3huzlu6CNmyHUG5N' -I
HTTP/1.1 406 Not Acceptable
Content-Type: text/html; charset=utf-8
X-Ua-Compatible: IE=Edge,chrome=1
Cache-Control: no-cache
X-Request-Id: d4da4e1010b84640e1657b731ada79a3
X-Runtime: 0.004287
Date: Fri, 07 Dec 2012 23:04:10 GMT
X-Rack-Cache: miss
Content-Length: 0
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
Connection: Keep-Alive
You will also get no data from a request that matches no data. But in this case, the HTTP code will be 200
curl 'https://[BRIGHT URL]/bright/api/v2/course.json?sc_app_id=RQIBAXU49I\
&sc_secret_key=nCwrTDSy1MzaeyhN0TFfi3uH3huzlu6CNmyHUG5N&title=nosuchcourse'
[]
curl 'https://[BRIGHT URL]/bright/api/v2/course.json?sc_app_id=RQIBAXU49I
&sc_secret_key=nCwrTDSy1MzaeyhN0TFfi3uH3huzlu6CNmyHUG5N&title=nosuchcourse' -I
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
X-Ua-Compatible: IE=Edge,chrome=1
Etag: "d751713988987e9331980363e24189ce"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 73a4966a2a62ca4e70316f6a68645b51
X-Runtime: 0.006220
Date: Fri, 07 Dec 2012 23:06:40 GMT
X-Rack-Cache: miss
Content-Length: 0
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
Connection: Keep-Alive
6.2. Fetching HTTP Error Codes from a POST Request #
Since we use a RESTful API, some operations require a POST HTTP verb. For whatever reason, the -I flag in curl will not show you the HTTP return code for a POST.
Instead use the following:
curl -w "%{http_code}" -d 'sc_app_id=RQIBAXU49Ix&sc_secret_key=\
nCwrTDSy1MzaeyhN0TFfi3uH3huzlu6CNmyHUG5N&user_email=newuser@aura-software.com' \
https://[BRIGHT URL]/bright/api/v2/api_key
-w %{http_code} is the key part of that.
6.3. Debugging Authentication Errors #
If you receive a 401 code from the API, the server itself has recorded the authentication error in the server log. If you are completely stumped, this is the place to look.
An error like this should exists:
Processing by ScormCloudCourseController#index as JSON
Parameters: {"api_key"=>"bogus!", "course_guid"=>"course1"}
[1m[36mApiKey Load (0.4ms)[0m [1mSELECT "api_keys".* FROM
"api_keys" WHERE "api_keys"."access_token" = 'bogus!' LIMIT 1[0m
Unauthorized: api token not found
Filter chain halted as :restrict_access rendered or redirected
Completed 401 Unauthorized in 2ms (ActiveRecord: 0.4ms)
Definitely give us a shout if you can’t get an API call to work at support@aura-software.com.