{"_id":"56a979dbf834950d0037b369","parentDoc":null,"project":"567f0c06143cc60d00c1fdbe","user":"567f0baca74a1c0d003e1fba","version":{"_id":"567f0c06143cc60d00c1fdc1","__v":9,"project":"567f0c06143cc60d00c1fdbe","createdAt":"2015-12-26T21:52:06.734Z","releaseDate":"2015-12-26T21:52:06.734Z","categories":["567f0c07143cc60d00c1fdc2","56a9783109cb9c0d00f0c7d3","56a97837f834950d0037b363","56a9783b2d8fd90d0036eed6","56a979912d8fd90d0036eed8","5834b5691a80690f00d31faf","5834b5e4f775120f00c45f9d","5bf1a1473031e4005075ae14","5c64c200244bda003204b97f"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1"},"category":{"_id":"56a979912d8fd90d0036eed8","pages":["56a979a12bb3910d000ee941","56a979d5f834950d0037b367","56a979dbf834950d0037b369","56abe05035138c0d005c94da","56abe0670b9e0b0d006162b7"],"version":"567f0c06143cc60d00c1fdc1","__v":5,"project":"567f0c06143cc60d00c1fdbe","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-01-28T02:14:41.926Z","from_sync":false,"order":0,"slug":"api-usage","title":"API Usage"},"__v":7,"githubsync":"","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-01-28T02:15:55.569Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"You can use the HTTP status code of the response to an API call to determine if there is an error.\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"HTTP Status Code\",\n    \"h-1\": \"Meaning\",\n    \"0-0\": \"`200`\",\n    \"1-0\": \"`400`\",\n    \"2-0\": \"`401`\",\n    \"4-0\": \"`500`\",\n    \"h-2\": \"Data Format\",\n    \"0-1\": \"**Success** - The API call was successful - there are no errors.\",\n    \"2-1\": \"**Unauthorized** - The API call failed - authentication via the access_token failed. A `message` attribute will explain the error.\",\n    \"2-2\": \"`JSON` - A \\\"message attribute will explain the error.\",\n    \"4-1\": \"**Internal Server Error** - An unknown error occurred - probably caused by a bug in the API.\",\n    \"4-2\": \"N/A\",\n    \"1-2\": \"`JSON` -\",\n    \"0-2\": \"`JSON`\",\n    \"1-1\": \"**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.\",\n    \"3-0\": \"`404`\",\n    \"3-2\": \"`JSON` - A \\\"message attribute will explain the error.\",\n    \"3-1\": \"**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.\"\n  },\n  \"cols\": 2,\n  \"rows\": 5\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Examples\"\n}\n[/block]\nHere's an example of an API error caused by providing an unrecognized parameter to an API call:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -v -X GET https://tophatter.com/merchant_api/v1/products.json \\\\\\n-d 'access_token=YOUR_ACCESS_TOKEN' \\\\\\n-d 'foo=bar'\\n\\n< HTTP/1.1 400 Bad Request\\n< Access-Control-Allow-Origin: *\\n< Content-Type: application/json; charset=utf-8\\n< Cache-Control: no-cache\\n\\n{\\n  \\\"message\\\": \\\"The following parameters were provided but are not recognized: foo.\\\"\\n}\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nHere's an example of an API error caused by providing an invalid identifier to an API call:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -v -X GET https://tophatter.com/merchant_api/v1/variations/retrieve.json \\\\\\n-d 'access_token=YOUR_ACCESS_TOKEN' \\\\\\n-d 'identifier=6631A'\\n\\n< HTTP/1.1 404 Not Found\\n< Content-Type: application/json; charset=utf-8\\n< Cache-Control: no-cache\\n\\n{\\n  \\\"message\\\": \\\"There is no variation with the unique ID 6631A.\\\"\\n}\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"errors","type":"basic","title":"Errors"}
You can use the HTTP status code of the response to an API call to determine if there is an error. [block:parameters] { "data": { "h-0": "HTTP Status Code", "h-1": "Meaning", "0-0": "`200`", "1-0": "`400`", "2-0": "`401`", "4-0": "`500`", "h-2": "Data Format", "0-1": "**Success** - The API call was successful - there are no errors.", "2-1": "**Unauthorized** - The API call failed - authentication via the access_token failed. A `message` attribute will explain the error.", "2-2": "`JSON` - A \"message attribute will explain the error.", "4-1": "**Internal Server Error** - An unknown error occurred - probably caused by a bug in the API.", "4-2": "N/A", "1-2": "`JSON` -", "0-2": "`JSON`", "1-1": "**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.", "3-0": "`404`", "3-2": "`JSON` - A \"message attribute will explain the error.", "3-1": "**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." }, "cols": 2, "rows": 5 } [/block] [block:api-header] { "title": "Examples" } [/block] Here's an example of an API error caused by providing an unrecognized parameter to an API call: [block:code] { "codes": [ { "code": "curl -v -X GET https://tophatter.com/merchant_api/v1/products.json \\\n-d 'access_token=YOUR_ACCESS_TOKEN' \\\n-d 'foo=bar'\n\n< HTTP/1.1 400 Bad Request\n< Access-Control-Allow-Origin: *\n< Content-Type: application/json; charset=utf-8\n< Cache-Control: no-cache\n\n{\n \"message\": \"The following parameters were provided but are not recognized: foo.\"\n}", "language": "curl" } ] } [/block] Here's an example of an API error caused by providing an invalid identifier to an API call: [block:code] { "codes": [ { "code": "curl -v -X GET https://tophatter.com/merchant_api/v1/variations/retrieve.json \\\n-d 'access_token=YOUR_ACCESS_TOKEN' \\\n-d 'identifier=6631A'\n\n< HTTP/1.1 404 Not Found\n< Content-Type: application/json; charset=utf-8\n< Cache-Control: no-cache\n\n{\n \"message\": \"There is no variation with the unique ID 6631A.\"\n}", "language": "curl" } ] } [/block]