Jump to:
API headers are like an extra source of information for each API call you make. Their job is to represent the meta-data associated with an API request and response.
If you ever encounter issues with an API, the first place you should look is the headers, since they can help you track down any potential issues. This makes them a very important part of each request.
API Headers tell you about:
You see headers in the message body. That’s the chunk of data that includes everything in the request or response. The headers usually come after the request line or response line.
Now, if you don’t know what those are, don’t worry. Just look for a specific format. Headers all look the same; they have an obvious format that you can spot from a mile away.
Headers are a key
–value
pair in clear-text string format separated by a colon. To see what they look like in practice, check out the example below:
{
"key1": "value1",
"key2": " value2",
"key3": " value3",
}
Real headers usually don’t say key
and value
, though. I just used those terms for clarity. Usually, the strings used are longer and more random, like what happens when your cat sits on your keyboard because it’s warm.
But no matter how long or random a string may look, the general format remains the same: “key
” : “value
“
To see a list of the most common header fields, click here.
Here are some of the most common API Headers you will encounter when testing any API.
To make API headers easier to understand, I’ll show you an example of how API headers are actually used.
Let’s use the Cat Facts API as an example.
We can use the version on RapidAPI to get the full response in JSON format. This lets us see the entire message body — headers and all.
If we test the /facts
endpoint, we get the following list of headers in the response body:
As you can see, it contains important headers like Content-Type, Date, and ETag, among others, which will be very useful for uncovering the cause of any potential issues should they come up.
Sometimes, you’ll need some sort of authentication to make a request. For this, you might need an API Key, which is often provided by the server.
If the API key is listed as a header, then you’ll need to set it in the headers
option of your HTTP request.
Like this:
headers: {'Authorization': '[your API key]'}
That’s if you’re coding in the first place. But with Apipheny, you can set your headers without having to code at all.
Using the Apipheny Headers feature, all you need to do to set your headers is paste in your header’s Key and Value. You can also add new rows should you need them.
Well, I don’t know. But you can find out. You can see which headers an API has by looking inside its documentation.
The most common ones you’ll need are the headers used for authentication. These are often called the API Key and Secret, and the server will provide them early on.
Some APIs don’t need authentication, though, and you can use them right away. But if you get a 401 error after making a request, then it’s likely you need authentication.
But if you ever need to know more about a specific API, just read its documentation.
API Headers contain a wealth of information for tracking down potential issues when using any API.
Most of the time, you won’t be looking at them. But when problems arise, the headers are the first place you should look.
Do a lot of copy-pasting?
We used to, as well.
But it took up too much of our time.
Introducing Apipheny, a Google Sheets add-on that lets you import data directly into Google Sheets — and save up to an hour of your workday.
It lets you connect virtually any API to Google Sheets — in just a matter of seconds.
This means you can now import data directly from your favorite data sources — and finally stop switching between tabs with your fingers stuck on Ctrl + C and Ctrl + V.
Here’s Apipheny CEO & Co-Founder, Meelad, showing you just how easy it is to use the add-on.
Apipheny lets you do the following things:
Try it for free. No credit card needed.
Learn more about APIs by reading these next: