API "Resource Definitions" Auth Headers Incorrect

Tagged:

Currently contains 4 posts

Avatar

April 08, 2015 14:48

pcross

Just testing a few things out and this threw me for a loop briefly…

Problem:
Submitting requests via the inline test forms on the PCR Resource Definitions page (http://www.pcrecruiter.net/apidocs_V2/ “Try It Out” button) with a valid authorization token returns status 500 with “Object reference not set to an instance of an object”

Expected:
Submitting requests via this form will respond as a valid request from other API clients. Using a different client with a valid request and the same token returns 200 / correct results.

Possible Cause:
From the “Try it Out” I can see that the token is in the Authorization header, but the header itself does not feature the bearer keyword. I’m speculating that this causes the status 500 result.

Avatar

April 17, 2015 14:12

Wayne-PCRecruiter

You just need to include the string "BEARER " before adding in the valid session to the field. For example the value I just used (with a modified session id) was formatted as followed and seemed to work fine in all of my quick tests. You were correct, our sample puts the value into the header of the request, not as an additional URL parameter as that is not the recommended method:

BEARER 8asdfdafsdfasdfdsfasfasfasdfasd9N0hasdfasdfasddsafdfassdsln+fUGlzhA+asdfasdfasd7iVypg==

Avatar

April 23, 2015 21:45

jimmyhaley

Wayne, I’m unable to get this to work and am getting the same issue with an internal 500 error on the server. I’ve tried multiple methods using:
BEARER longcurrentokenstring
BEARER: longcurrentokenstring
BEARER
longcurrentokenstring

All to no avail. Of note, I can successfully call the API by passing via URL parameters, but as you mention…not the recommended method.

Any recommendations/resolution to this?

Avatar

April 23, 2015 21:50

Wayne-PCRecruiter

Can you send me the header of the request you are trying to make which is not working?

On the active docs it is appending what you add in to the Authorization header. If I was setting the header in something like jquery for an ajax request using their headers option I would have something like the following variable which I would append to the option when making the ajax request.

var restRequestHeaders = {
“Content-Type”: “application/json”,
“Authorization”: "BEARER " + SESSIONIDVARIABLEHERE,
“Accept”: “application/json;”
}

Reply to thread