Forums

API error code for expired token?

Is there a master list of API error codes?

I'd like to detect token expiry to automatically refresh the token, but I don't want to wait 2 weeks to see what specific error code it returns.

i.e. not just the 401, but the Elvanto code, like 102 below:

{
'generated_in': '0.018',
'status': 'fail',
'error': {
'code': 102,
'message': 'Invalid API Key.'
}
}

Posted by jon_guyer

Hi Jon,

Apologies for the delay.

At the moment [url=http://elvanto.com/api/getting-started/#response_codes]this is the list of possible response codes[/url] you can receive from the API. The codes are all the same but the message returned may be different depending on what the error is. We do not currently have a master list. Was there any type of errors you were wondering about?

When you generate an OAuth token, it will give you an 'expires_in' parameter. This tells you in how many seconds time the token will expire which you can store locally and ensure the token is renewed.

Let me know if you have any further questions

Ben

Posted by ben

Thanks, Ben. I'm particularly interested in the authentication error that would come if the token is not refreshed before expiry, and then I make a request with the expired token. I take it that I should just receive error code 102 in that case?

I do have logic in my application for refreshing the token based on the 'expires in' parameter, but if the user doesn't run the application for a while, I won't get a chance to refresh it. In that case I need to detect that it's specifically an expired token rather than some other kind of authentication error, so I can refresh the token at that point.

Thanks and regards,

Jon.

Posted by jon_guyer

Hi Jon,

Here are some possible 401 errors you might receive. If the token is invalid (doesn't exist):

[code]{
'generated_in': '0.018',
'status': 'fail',
'error': {
'code': 102,
'message': 'Invalid OAuth Token.'
}
}[/code]

If the token has expired:

[code]{
'generated_in': '0.018',
'status': 'fail',
'error': {
'code': 121,
'message': 'Expired OAuth Token.'
}
}[/code]

Our [url=https://github.com/elvanto/api-php]PHP API[/url] gives an example of how you could check for expired OAuth tokens when the user makes a call. It will save having to check on a regular basis. Scroll down to the 4th code sample in the Read Me.

Hope that helps

Posted by ben

Thanks, Ben. That's exactly what I needed to know!

Posted by jon_guyer


Login or Signup to post a comment