You can use the HTTP status code of the response to an API call to determine if there is an error.
HTTP Status Code | Meaning |
---|---|
200 | Success - The API call was successful - there are no errors. |
400 | Bad Request - The API call failed - the API call is being used incorrectly. A parameters is missing, unexpected, or incorrectly formatted. A message attribute will explain the error. |
401 | Unauthorized - The API call failed - authentication via the access_token failed. A message attribute will explain the error. |
404 | Resource Not Found - The requested resource does not exist. This might mean the identifier you're using to access a resource is incorrect. A message attribute will explain the error. |
500 | Internal Server Error - An unknown error occurred - probably caused by a bug in the API. |
Examples
Here's an example of an API error caused by providing an unrecognized parameter to an API call:
curl -v -X GET https://tophatter.com/merchant_api/v1/products.json \
-d 'access_token=YOUR_ACCESS_TOKEN' \
-d 'foo=bar'
< HTTP/1.1 400 Bad Request
< Access-Control-Allow-Origin: *
< Content-Type: application/json; charset=utf-8
< Cache-Control: no-cache
{
"message": "The following parameters were provided but are not recognized: foo."
}
Here's an example of an API error caused by providing an invalid identifier to an API call:
curl -v -X GET https://tophatter.com/merchant_api/v1/variations/retrieve.json \
-d 'access_token=YOUR_ACCESS_TOKEN' \
-d 'identifier=6631A'
< HTTP/1.1 404 Not Found
< Content-Type: application/json; charset=utf-8
< Cache-Control: no-cache
{
"message": "There is no variation with the unique ID 6631A."
}