What Are HTTP Response Codes in REST APIs?

HTTP response codes are three-digit numbers returned by a server that tell your automation script whether an API request succeeded or failed. This post breaks down the five categories of status codes, the most common ones you will encounter in network automation, and how to check them in a Python s

What Are HTTP Response Codes in REST APIs?

When you start working with REST APIs in network automation, you will quickly encounter three-digit numbers in server responses. These numbers are called HTTP response codes (also called status codes), and understanding them is a foundational skill for anyone working toward the CCNA DevNet certification or diving into network automation for the first time.

What Is an HTTP Response Code?

Every time a client (like your Python script or a browser) sends an HTTP request to a server, the server responds with a status code. This code is a three-digit number that tells you whether the request succeeded, failed, or something else happened in between. Think of it like a postal service: you send a package, and you get a notification back saying "delivered," "address not found," or "return to sender."

In the context of REST APIs, these codes help your automation scripts make smart decisions. Did the API call succeed? Should you retry? Did you send bad data? The response code answers all of these questions at a glance.

The Five Categories of HTTP Response Codes

HTTP response codes are grouped into five classes based on their first digit. Here is a quick breakdown:

  • 1xx (Informational): The server received the request and is continuing to process it. Rarely seen in typical API work.
  • 2xx (Success): The request was received, understood, and accepted. This is what you want to see.
  • 3xx (Redirection): Further action is needed. The resource has moved to a different URL.
  • 4xx (Client Error): Something is wrong with the request you sent. This is your fault (or your script's).
  • 5xx (Server Error): The request looked fine, but the server failed to process it. This is the server's fault.

The Most Common Codes You Will Encounter

While there are dozens of defined status codes, a handful appear repeatedly in network automation and API work. Here are the most important ones to memorize:

  • 200 OK: The request succeeded. Data is returned in the response body.
  • 201 Created: A new resource was successfully created (common after a POST request).
  • 204 No Content: Success, but there is no response body (common after a DELETE).
  • 400 Bad Request: The server could not understand your request, usually due to malformed JSON or missing fields.
  • 401 Unauthorized: Authentication is required. You are missing or using an invalid token or credentials.
  • 403 Forbidden: You are authenticated, but you do not have permission to access this resource.
  • 404 Not Found: The requested resource does not exist. Check your URL.
  • 500 Internal Server Error: Something went wrong on the server side.

Seeing Status Codes in Practice

Here is a simple Python example using the requests library to call a REST API and check the response code:

import requests

url = "https://api.example.com/devices"
headers = {"Authorization": "Bearer YOUR_TOKEN_HERE"}

response = requests.get(url, headers=headers)

print(f"Status Code: {response.status_code}")

if response.status_code == 200:
    print("Success! Here is the data:")
    print(response.json())
elif response.status_code == 401:
    print("Authentication failed. Check your token.")
elif response.status_code == 404:
    print("Resource not found. Check your URL.")
else:
    print(f"Unexpected response: {response.status_code}")

When you run this script, the output might look like:

Status Code: 200
Success! Here is the data:
{'devices': [{'id': '1', 'hostname': 'router-01'}, {'id': '2', 'hostname': 'switch-01'}]}

Notice how the script branches based on the status code. This is a pattern you will use constantly in real-world automation work. Rather than assuming every API call succeeds, good scripts always check the response code and handle errors gracefully.

Why This Matters for CCNA Automation

Exam objective 2.4 specifically covers understanding and using APIs, and HTTP response codes sit right at the core of that knowledge. Whether you are querying Cisco DNA Center, Meraki Dashboard, or any other network management platform via REST APIs, every interaction produces a status code. Reading those codes correctly means the difference between a script that works reliably and one that silently fails.

What's Next

Now that you understand what HTTP response codes are and why they matter, the next step is learning about the HTTP methods themselves: GET, POST, PUT, PATCH, and DELETE. Each method has a specific purpose in REST API design, and knowing when to use each one is the next key concept in mastering API-based network automation.

🔧
Before writing full Python scripts, try testing your API calls in Postman or Insomnia first — they display status codes, headers, and response bodies in a clean interface, which makes it much easier to understand what your automation script should expect. Postman, Insomnia and curl.