Skip to main content

    Troubleshoot API-related issues

    Course overview
    Lesson
    1 min read

    Interpret status codes

    Learn to parse the information provided to you in API responses.

    What is a status code?

    You may be familiar with that frustrating inevitability of navigating to a website, only to be hit with "404: Not found."

    In this lesson, we'll learn what codes like this mean and how you can use this knowledge to pinpoint any errors in API calls you are making.

    Interpret response codes

    Every API call returns a response with two parts: a response code, also known as a status code, and a response body. The status code is a 3-digit number that tells you the nature of the response, while the response body provides either the information you requested or detailed information about any errors with the API call.

    Google 404 error

    Walk through an example of some of the status codes you may receive and how they can help you resolve errors.

    Understand the three main status code levels

    There are a number of different status codes all with unique meanings, but it is helpful to remember the three main classes of status codes to immediately interpret your next course of action. Click the arrow on each dropdown to learn more about each class of status code.

    2xx

    A status code in the 200s means that the API call went through successfully. If you receive a status code in the 200s, you can rest assured that Klaviyo's server successfully processed the API call.

    200 status in API logs

    However, this does not necessarily mean that everything is correct. It is generally best practice to double check in Klaviyo to make sure the data was passed correctly.

    The status code just signifies that the API call went through, but it doesn't double check that the data was structured properly. For example, for the Booked Seminar event, you could have accidentally sent that the seminar cost $10 instead of $100. The API call wouldn't catch this error, since it is still valid data, but you can manually double check your work to make sure it is correct.

    A status code in the 200s is what we are looking for after making a payment in the Klaviyo cafe - everything went through as expected. You successfully paid for your meal and can move on to the next task.

    4xx

    Remember that pesky 404 error? Any status code in the 400s means that there was some sort of error in the data you sent over. For example, a 404 error means that the server couldn't find the data you requested, while a 401 status code means that your API call was not properly authenticated.

    A 4xx error code means that it is up to you to resolve the error.

    400 error in Postman

    Often, 400 errors are the result of JSON formatting errors. Use a JSON formatter to verify the body of your API requests.

    In the Klaviyo Cafe, paying your bill is an example of a POST request. You can think of a status code in the 400s like there is an issue with your credit card. The payment did not go through, and it is up to you to resolve the error.

    5xx

    A status code in the 500s means there was some sort of error on the server's end. For example, if Klaviyo's API server is temporarily down, you may receive a 503 status code.

    A 5xx error code means that it is up to the server, or Klaviyo to fix.

    If you receive a status code in the 500s when you pay your bill at the Klaviyo Cafe, there is an issue with the service the Cafe uses to process payments. There is nothing you can do to resolve this error, and it is up to the Cafe to fix things on their end before you can successfully make the payment.

    These status codes can help you understand the nature of the error, and the response body provides more detailed information about how to remedy it.

    Read more about all status codes in our guide to rate limits, status codes, and errors.

    Interpret status codes