2xx range indicate success, codes in the 4xx range indicate a client-side error (e.g., a problem with the request or authentication), and codes in the 5xx range indicate a server-side error.
Error Response Structure
When an error occurs, the API will respond with a JSON object containing details about the error. A typical error response follows this structure:statusCode(integer): The HTTP status code for the error.message(string): A human-readable summary of the error. This message is generally not suitable for programmatic parsing but can be helpful for debugging.error(string): The standard HTTP status text (e.g., “Bad Request”, “Unauthorized”).details(array of objects, optional): Provides specific information about what went wrong, often used for validation errors. Each object in the array might contain:field(string): The specific input field that caused the error.message(string): A detailed message about the error related to this field.code(string, optional): A specific error code for programmatic handling.
Common HTTP Status Codes
Here are some of the common HTTP status codes you might encounter:400 Bad Request
This code indicates that the server could not understand the request due to invalid syntax or missing required parameters. This is often due to issues with the request payload. Possible Causes:- Missing required fields in the request body.
- Invalid data types (e.g., sending a string where a number is expected).
- Malformed JSON.
401 Unauthorized
This code means that the request has not been applied because it lacks valid authentication credentials for the target resource. Your API key might be missing, invalid, or expired. Possible Causes:- No API key provided in the
Authorizationheader. - Invalid or revoked API key.
- Expired API key or session token.
403 Forbidden
This code indicates that the server understood the request but refuses to authorize it. This means you are authenticated, but you do not have permission to perform the requested action on the specified resource. Possible Causes:- The authenticated user does not have the necessary roles or permissions.
- Trying to access a resource belonging to another user/account.
404 Not Found
This code means that the server cannot find the requested resource. URLs are case-sensitive. Possible Causes:- The requested URL or endpoint does not exist.
- The resource identified by a parameter (e.g., an ID in the URL path) does not exist.
429 Too Many Requests
This code indicates that the user has sent too many requests in a given amount of time (“rate limiting”). Check theRetry-After header for information on when to retry the request.
Possible Causes:
- Exceeding the API rate limits for your account or API key.
500 Internal Server Error
This code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request. This is a generic error message when no more specific message is suitable. These errors should be reported to Kim360 support if they persist. Possible Causes:- An unhandled exception occurred on the server.
- A problem with a downstream service or database.
Best Practices for Error Handling
- Check the HTTP Status Code: Always check the status code of the response before attempting to parse the body.
- Parse the Error Response: If an error occurs (4xx or 5xx status code), parse the JSON error response to get more details.
- Implement Retries (with backoff): For transient errors like
429 Too Many Requestsor5xxserver errors, implement a retry mechanism with an exponential backoff strategy to avoid overwhelming the server. - Log Errors: Log detailed error information, including the request made and the full error response received, to help with debugging.
- Handle Specific Error Details: For validation errors (
400 Bad Request), use thedetailsarray to provide specific feedback to the user or to guide programmatic corrections. - Do Not Expose Sensitive Information: Ensure your client-side error handling does not expose sensitive information from error messages.