Skip to main content

    Build foundational API knowledge

    Course overview
    Lesson
    4 min read

    Identify status codes

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

    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.

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

    Categorize the three main categories of status codes

    There are a number of different status codes all with unique meanings, but it is helpful to remember the 3 main classes of status codes to immediately interpret your next course of action. 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.

    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.

    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

    A status code in the 400s signifies that there was some sort of error in the data you sent over. For example, if you receive a 401 status code, your API call was not properly authenticated. Double check the headers to make sure you are using the correct public or private API key for the API call you are making.

    If you receive a 400 status code, this means there was an error in the parameters you included. This is often a JSON syntax error.

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

    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.

    Identify status codes