Make your first API call

You will send a real request to a real API from your terminal, then from a Node script, and learn to read every part of what comes back.

An API call is a message from your program to someone else's program, sent over HTTP, the same protocol your browser uses to load this page. You send a request that says what you want. The server sends back a response with the answer. That is the whole idea, and the fastest way to make it concrete is to send one.

By the end of this page you will have called two APIs, from two different tools, and you will know what every line of the answer means.

What you need before the first request

Three things, and you probably have two of them already.

  • A terminal. Terminal on macOS, any shell on Linux, PowerShell or Windows Terminal on Windows.
  • curl. A command-line program that sends HTTP requests. It ships with macOS, nearly every Linux distribution, and Windows 10 and later. Type curl --version to check.
  • An API key. A free APIVerve account gives you one immediately. Sign up, open the API keys page, and copy the key. It is a long string of letters, digits and dashes.

You will learn what the key actually is, and how to keep it safe, in lesson 3. For now, treat it like a password: paste it into your terminal, not into a chat or a public file.

Anatomy of a request

Before typing anything, look at what you are about to send. Every APIVerve request has the same parts:

GET https://api.apiverve.com/v1/numbertowords?number=4021
x-api-key: YOUR_API_KEY

Reading it left to right:

  • GET is the method. It says you want to read something. Lesson 4 covers the other common method, POST.
  • https://api.apiverve.com is the host, the server you are talking to.
  • /v1/numbertowords is the path. v1 is the version of the API, and numbertowords is the id of the specific API you want. Change the id and you are calling a different API on the same server.
  • ?number=4021 is the query string: inputs for the API, written as name=value pairs after a question mark.
  • x-api-key: YOUR_API_KEY is a header, a piece of metadata sent alongside the request. This one tells the server who you are.

The Number to Words API is a good first target for a specific reason: it is deterministic. Send the same number twice and you get the same words twice. When you are learning, that matters more than it sounds, because it means a different result can only come from a different request.

Send it with curl

Replace YOUR_API_KEY with your key and run this:

curl 'https://api.apiverve.com/v1/numbertowords?number=4021' \
  -H 'x-api-key: YOUR_API_KEY'

-H adds a header. The backslash at the end of the first line just continues the command onto the next line; you can write it all on one line if you prefer.

Why the quotes around the URL? Characters like ? and & mean something to your shell. Without quotes, a URL with two parameters, such as ?a=1&b=2, gets cut in half at the &, and the second half runs as a separate command. Quoting every URL is a habit worth forming on day one.

Here is what comes back:

{
  "status": "ok",
  "error": null,
  "data": {
    "number": 4021,
    "words": "four thousand, twenty-one",
    "ordinal": "four thousand, twenty-first",
    "numberOfDigits_numeric": 4,
    "numberOfDigits_words": "four",
    "eachNumber": ["four", "zero", "two", "one"],
    "afterDecimal": null,
    "locale": "en-US"
  }
}

Run the same call here, then change the number and run it again:

Try it liveNumber to Words1 credit
GEThttps://api.apiverve.com/v1/numbertowords
curl "https://api.apiverve.com/v1/numbertowords?number=4021" \
  -H "x-api-key: YOUR_API_KEY"
Sign in or create a free account to run this with your own key.

Look at data.words, then try a decimal such as 12.5 and watch afterDecimal change.

Reading the envelope

The response is JSON, a text format for structured data. Lesson 2 is all about reading it. For now, notice the outer shape, because it never changes.

Every APIVerve response, from every one of its APIs, has exactly three top-level keys:

KeyWhen the call workedWhen it failed
status"ok""error"
errornullA sentence explaining what went wrong
dataThe resultnull

This outer wrapper is called an envelope. The useful part is always inside data, and its contents depend on which API you called. The envelope itself is identical whether you are converting a number, validating an email or looking up a country, which means the code you write to check for success works for every API you will ever call here.

The first thing your code should check is status. Do not look at data and guess. A failed call has data: null, and code that reaches straight for data.words crashes on it with an unhelpful error instead of telling you what actually went wrong.

Check yourself

You call an APIVerve API and the response has "status": "error". Where do you look to find out what went wrong?

Answer the check above to continue.

Run every example on your own key. Free plan, no card.

Scaling up?

Volume pricing, custom SLAs, and dedicated support for high-traffic teams.

Contact sales