- 1 Introduction
- 2 Example of HTTP Error and Status Code
- 3 Common HTTP Error Status Codes / Reasons / Possible Fix
- 4 Debugging HTTP Web Requests
Any time you send HTTP Request according to HTTP Standard using tools like ZappySys REST API Drivers or SSIS Connectors you may receive web response along with HTTP Status Codes. Dealing with REST / SOAP API calls you may face errors and you may find it challenging to understand generic error message from server along with some Numeric value (Called HTTP Status Code). In this article we will try to decode certain status codes and discuss various way to solve it.
Example of HTTP Error and Status Code
Before we dive deep on this topic of HTTP Errors Status Codes let’s check an example HTTP Error with Status Code 400 (BadRequest). As you notice we passed some bad data in Request Body to produce this error. As you may see in below screenshot there are few parts we need to configure to call REST API request.
- URL (and optionally parameters in URL)
- Request Method (i.e. GET / POST)
- Request Body (Optional – Not needed for GET request but for POST /PUT API requests you may need to pass)
- Request Content Type ( Optional – i.e. application/xml . This is not needed for GET Request)
- Request Headers (Optional – Many tools generate default headers behind the scene. In our example we passed only two headers but see how many more added automatically in below Raw View obtained by tools like Fiddler )
>>>> HEADERS <<<<<
Accept-Encoding: gzip, deflate
>>>> BODY <<<<<
some bad data
HTTP/1.1 400 Bad Request
"message": "Invalid JSON payload received. Unexpected token.\nsome bad data\n^",
Here is a screenshot of SSIS REST API Task which can be used for calling XML / JSON API to automate ETL workflows.
Common HTTP Error Status Codes / Reasons / Possible Fix
Status codes can be anywhere between 100 to 505. Most of them documented here also here (RFC2616 – HTTP / 1.1). Out of these status codes we will discuss few most common ones in this article and how to fix them.
Microsoft has also provided great explanation for most common HTTP Status Code here.
Status Code 400 – Bad Request
- One or more URL Parameter is wrong
- Request body may be wrong (For example: Either data is invalid in Body or Syntax is invalid – such as JSON Property name misspelled or missing closing brackets)
- Make sure you passing URL Parameters correct way (Refer your API help file or some sample code)
- For POST / PUT request check your Parameter names, Data format, JSON / XML syntax (Refer your API help file or some sample code)
- If you want to validate JSON / XML Syntax use some FREE online validators for JSON or XML
- You did not pass userid / password or session token
- Your credentials are invalid or session token is expired
- Some tool may not save Sensitive Information unless you set Save Sensitive Information option. For example in SSIS if you set PackageProtectionLevel= DoNotSaveSensitive then password will not be sent along with your API request.
- Make sure you passing credentials either directly via HTTP Headers or URL Parameter
- For ZappySys Products use HTTP or OAuth connection manager to pass credentials securely without worrying about manual HTTP Headers
- If you configured PackageProtectionLevel= DoNotSaveSensitive in SSIS then Check this and this article to learn how to pass sensitive information in SSIS at runtime / design time.
Status Code 404 – Page Not Found
- You entered invalid URL
- URL is intranet only and you trying to access from outside network
- Check your URL and correct it so its not throwing 404 error when you test in Browser (It must return data or throw some other error – E.g. 400 – Bad request or 401-Unauthorized)
Status Code 405 – Method Is Not Allowed
- You selected invalid Request Method (see #2 in above screenshot)
- Select correct Request Method. Refer to your API see it supports the method you selected. For example You selected POSt method to update some data but your API is expecting PUT method rather than POST.
Status Code 411 – Length Required
- You selected request method as POST or PUT but did not pass any body
- Make sure you supply some value in the Request Body field as per API specification. See #4 in the screenshot above.
Status Code 415 – Media Type Is Not Supported
- You did not pass correct Content-Type Header or your API was expecting different content-type setting than what you passed.
- Pass HTTP Header Content-Type with correct value (Check API documentation). Typically for JSON API its application/json and for XML SOAP API its text/xml
- If you are using Zappysys REST API Drivers or SSIS Connectors you will see Content Type Dropdown on UI see #4 in above screenshot. Change it to correct setting. If your content type not in the dropdown then you can set direct HTTP Header
Example => Content-Type: application/json see #5 in screenshot.
Debugging HTTP Web Requests
If you want to make sure what’s being passed to web server you can use this tool (Fiddler) and debug your web requests. It will show you all parts of your HTTP Request / Response (i.e. Headers, Body, URL Parameters)