API Calls: What They Are & How to Make Them in 5 Easy Steps (2024)

APIs, short for Application Programming Interfaces, are software-to-software interfaces. Meaning, they allow different applications to talk to each other and exchange information or functionality. This allows businesses to access another business’s data, piece of code, software, or services in order to extend the functionality of their own products —all while saving time and money.

API Calls: What They Are & How to Make Them in 5 Easy Steps (1)

Now that you understand the benefits, you might be wondering how you can exactly use an API to request and get data from another application. That’s where API calls come in.

What is an API Call?

An API call is the process of a client application submitting a request to an API and that API retrieving the requested data from the external server or program and delivering it back to the client.

Let’s say your app uses Facebook APIsto extract data and functionality from the platform. In that case, when broadcasting a live Facebook video stream, creating a post, or building a custom dashboard for your ads, you are actually making an API call.

Now that we understand what an API call is, let’s break down the process of making one.

How to Make API calls

  1. Find the URI of the external server or program.
  2. Add an HTTP verb.
  3. Include a header.
  4. Include an API key or access token.
  5. Wait for the response.

1. Find the URI of the external server or program.

To make an API call, the first thing you need to know is the Uniform Resource Identifier (URI) of the server or external program whose data you want. This is basically the digital equivalent of a home address. Without this, you won’t know where to send your request.

The HubSpot API’s URI, for example, is https://api.hubapi.com.

It’s important to note that most APIs have different endpoints, each with their own end paths. For example, let’s say you want to stream public tweets in real-time. Then you could use Twitter’s filtered stream endpoint. The base path, which is common to all endpoints, is https://api.twitter.com. The filtered stream endpoint is /2/tweets/search/stream. You can either add that to the end of the base path, or just list the endpoint in your request.

We're committed to your privacy. HubSpot uses the information you provide to us to contact you about our relevant content, products, and services. You may unsubscribe from these communications at any time. For more information, check out our Privacy Policy.

API Calls: What They Are & How to Make Them in 5 Easy Steps (3)

Free Ebook: How to Use an API

Everything you need to know about the history and use of APIs.

  • A History of APIs
  • Using APIs
  • Understanding API Documentation
  • And more!

Loading your download form

You're all set!

Click this link to access this resource at any time.

Access now

Learn more

2. Add an HTTP verb.

Once you have the URI, then you need to know how to formulate the request.

The first thing you need to include is a request verb. The four most basic request verbs are:

  • GET: To retrieve a resource
  • POST: To create a new resource
  • PUT: To edit or update an existing resource
  • DELETE: To delete a resource

For example, let’s say you use NREL’s Alternative Fuel Station’s API and want to see a list of the nearest alternative fuel stations in Denver, Colorado. Then you’d make a GET request that might look like:

GET https://developer.nrel.gov/api/alt-fuel-stations/v1/nearest.json?api_key=XXXXXXXXX&location=Denver+CO

This tells the server to search the database to find a list of alternative fuel stations in Denver. If that list exists, the server will send back a copy of that resource in XML or JSON and an HTTP response code of 200 (OK). If that list doesn’t, then it will send back the HTTP response code 404 (not found).

Here’s a look at the output in JSON:

API Calls: What They Are & How to Make Them in 5 Easy Steps (4)

If you’re not familiar with JSON, that might look intimidating. So you can use Excel to make the call and get a simple list of five alternative stations.

API Calls: What They Are & How to Make Them in 5 Easy Steps (5)

3. Include a header.

The next thing you need to include is a header, which tells the API about your request and the response you’re expecting. Including a header ensures the API understands what you’re asking and responds in a way that’s expected and easy for you to understand and use. Three common headers are user-agent, content-type, and accept. Let’s define each below.

User-Agent

This header enables servers to identify the application, operating system, vendor, and/or version of the user agent making the request.

For example, let’s say you want your application to work with New Relic's RESTful APIs. Then you need an HTTP agent to manage the information exchange between your application and New Relic and you need to identify that integration. In that case, you’d submit the following user-agent header in Java using the GET verb:

get.setHeader("User-Agent", "my-integration/1.2.3");

Content-Type

This header explains what type of information is in the body of the request. It might explain that the request was formatted in XML, for example, or JSON. Without this header, the API might receive your request and not understand what it is or how to decode it. As a result, you won’t get a response.

Accept

This header explains what format you’d like to receive your response back from the API. Without this header, the API could return the data requested in XML when you wanted it in JSON, or vice versa.

It’s important to note that an API might not be capable of returning data in the format you requested. That might be frustrating but you’ll still receive a response. So you should always include this header in your API call in case you can get the exact response you want.

4. Include an API key or access token.

An API key and access token serve the same purpose: they are unique identifiers used to authenticate calls to an API. Made up of a string of letters and numbers that identify the client application making the request, an API key or access token is used to grant or deny requests based on the client’s access permissions, and track the number of requests made for usage and billing purposes.

To make an API call to Google’s Cloud Natural Language API, you must include an API key as a query parameter. For example, let’s say you want to find named entities (ie. proper names and common nouns) in a body of text. Then you’d make the following API request, replacing API_KEY with your actual API key:

POST https://language.googleapis.com/v1/documents:analyzeEntities?key=API_KEY

5. Wait for a response.

Now all that’s left to do is wait for a response from the API. You can expect a status code that lets you know the request was either processed successfully or unsuccessfully. In the latter case, the status code will explain the issue so you can correct it and try again. The most common codes are 2XX codes (“success codes”) and 4XX codes (“error codes”). Let’s take a brief look at some of the most common:

2XX Codes

These codes convey that the server has received the client’s request and processed it successfully. Here are the most common examples:

  • 200 OK: The request was successful.
  • 201 Created: The resource has been created on the server. This response is typically returned for POST requests.
  • 202 Accepted: The request has been received but is still being processed.
  • 204 No Content: The request has been successfully processed but no content will be returned.

4XX Codes

These codes convey that the client’s request has an error. It’s possible that the request is written incorrectly, or the resource which the client is requesting doesn't exist.

  • 400 Bad Request: There is something wrong in the client’s request.
  • 401 Unauthorized: The client is not authorized to make this request.
  • 403 Forbidden: The request is correct but can’t be processed. Likely, the problem is that the client does not have required permissions.
  • 404 Not Found: The resource being requested doesn't exist.

We're committed to your privacy. HubSpot uses the information you provide to us to contact you about our relevant content, products, and services. You may unsubscribe from these communications at any time. For more information, check out our Privacy Policy.

API Calls: What They Are & How to Make Them in 5 Easy Steps (6)

Free Ebook: How to Use an API

Everything you need to know about the history and use of APIs.

  • A History of APIs
  • Using APIs
  • Understanding API Documentation
  • And more!

Loading your download form

You're all set!

Click this link to access this resource at any time.

Access now

Learn more

Test API Calls

There are APIs for seemingly everything today, from embedding Instagram photos on your ecommerce siteto providing access to thousands of hotels on your blog.

With so many APIs to choose from, it’s important to evaluate them carefully in terms of functionality, reliability, performance, and security so you know they meet your app’s and user’s needs. If you’re the one developing, providing, and maintaining an API, then testing is equally important. Testing frequently will ensure the API is functional and meets consumer expectations.

Now that we understand the importance of API testing, let’s define what it is exactly.

How to Do API Testing

API testing consists of making API calls to different endpoints, getting responses, and validating the status codes, response times, and data in those responses.

This type of testing is usually performed by a software tool or web service, like ReqBin. The process is relatively similar, but the exact steps will vary depending on which tool or service you use. Below are the steps to test an API using ReqBin. For the sake of this demo, we’ll test a free and open API.

1. Enter the URL of the API endpoint.

Let’s say you want to use The New York Times’s Article Search API to look up articles by the keyword “dog.” Then you’d use the following URL: https://api.nytimes.com/svc/search/v2/articlesearch.json?q=dog.

API Calls: What They Are & How to Make Them in 5 Easy Steps (7)

2. Select the appropriate HTTP method.

Since you want to retrieve the articles with this keyword, you’d use the GET method.

API Calls: What They Are & How to Make Them in 5 Easy Steps (8)

Note that if you were using the POST, PUT, or PATCH methods, then you’d enter data into the Content tab.

3. Enter your credentials in the Authorization tab.

If the API server requires authorization, then you need to enter your credentials in the Authorization tab. Let’s see what happens if you skip that step.

API Calls: What They Are & How to Make Them in 5 Easy Steps (9)

4. Click Send to submit your API request.

Once you submit your API request, you can see the returned API status code, response time, and content.

API Calls: What They Are & How to Make Them in 5 Easy Steps (10)

Notice in this case, you’ve received a 401 Unauthorized response. That’s because you need an API key to use this NYT API.

Once you’ve gotten an API key, you can continue testing by changing the API endpoint URL, HTTP method, and request data.

Making the Call

Now that you understand how to test an API call, you can start evaluating different APIs and narrow down which suit your app and users best. Then, when you’re ready to connect your application to the rest of the software world, you can make the call.

Topics: Application Programming Interface (API)

API Calls: What They Are & How to Make Them in 5 Easy Steps (2024)

FAQs

API Calls: What They Are & How to Make Them in 5 Easy Steps? ›

An API call, or API request, allows one application to request data or services from another application. Most web applications regularly make API calls.

What are API calls and how do they work? ›

An API call, or API request, allows one application to request data or services from another application. Most web applications regularly make API calls.

How API works step by step? ›

How do I use an API?
  • Find an API. The first step in using an API is to find an API that provides the functionality you need. ...
  • Read the documentation. ...
  • Understand the API's terms of use. ...
  • Obtain an API key. ...
  • Make API requests. ...
  • Process the API response. ...
  • Follow best practices.
Jul 25, 2023

What is API in simple words? ›

API stands for Application Programming Interface. In the context of APIs, the word Application refers to any software with a distinct function. Interface can be thought of as a contract of service between two applications. This contract defines how the two communicate with each other using requests and responses.

What is the easiest way to call an API? ›

API Call in JavaScript Using the fetch() method

fetch is a method to call an API in JavaScript. It is used to fetch resources from a server. All modern browsers support the fetch method. It is much easy and simple to use as compared to XMLHttpRequest.

What are API examples? ›

Public API examples include social media bots, third-party login, e-commerce transactions, and weather apps. Private API examples include streaming services, ensuring media compatibility on various devices, and financial apps that connect different aspects of managing finances in a bank.

What are the methods of API calling? ›

These particular approaches usually revolve around acquiring and manipulating information stored in those systems. To be specific, there exist five popular kinds of API request methods: GET, POST, PUT, PATCH, and DELETE.

How API works for beginners? ›

APIs serve as a software intermediary, allowing two applications to talk to each other. However, they can also do much more. APIs allow two software applications to communicate using pre-established rules and protocols. The API serves as a software interface for the two different applications that need to communicate.

How to make API for beginners? ›

How to Build an API: a Comprehensive Guide
  1. Step #1. Start with your goals and intended users.
  2. Step #2. Design the API.
  3. Step #3. Develop your API.
  4. Step #4.Test your API.
  5. Step #5. Monitor your API and iterate on feedback.
  6. Conclusion.

How to understand API? ›

An API, short for Application Programming Interface, is a software-to-software interface. APIs provide a secure and standardized way for applications to work together. They deliver the information or functionality requested without user intervention. An error occurred.

What is API real time example? ›

Real-Time API Examples

Google Maps API: The Google Maps API provides real-time location data for applications, such as ride-sharing services, food delivery apps, and location-based games.

How does an API work diagram? ›

An API diagram visually represents the relationships between different components in an application's architecture. This includes understanding how servers, clients, databases, web services, and APIs interact with one another.

What do APIs do two correct answers? ›

Answer. Answer: Explanation:An API takes a request, transmits it to the system, and delivers the response back. This is the basic function of an API - to facilitate communication between different software components.

How do I create a call API? ›

Creating API calls
  1. Select API Calls from the left Navigation Menu.
  2. Click on the + Add button and select Create API Call.
  3. Enter the API Call Name.
  4. Select the Method Type: GET, POST, DELETE, PUT, or PATCH.
  5. Enter the API URL of the service you want to access.
Dec 12, 2023

What are the most common API calls? ›

To be specific, there exist five popular kinds of API request methods: GET, POST, PUT, PATCH, and DELETE. Consequently seeking information is made easy via GET requests, while creating fresh details may only be accomplished through POST logic.

What counts as 1 API call? ›

For the data endpoints, one API call gets all time steps of a data type (realtime/forecast/historical) for a specific time period for one location. For example, /realtime returns the requested data fields for a lat/lon right now.

What is the purpose of API call? ›

An API call refers to the specific request initiated by one software application to another, aiming to access its functionality or data. At its core, an API call facilitates interactions between different software entities, enabling tasks like retrieving data or triggering specific functions.

What is the difference between API call and service call? ›

A key difference between web service and API is the way that software applications or machines communicate. With web service, a network is required to transfer information. However, with an API a network is optional. APIs are also commonly leveraged on internal databases and do not require a network.

What is the difference between API and call? ›

"API" is a quite general term. It refers to simply a set of things a program can do, and how to do them. They may be system calls or function calls, but web developers also speak of web APIs, where you can do things by sending HTTP requests to specific addresses.

What is difference between API and function call? ›

The main difference are in terms of behavior and the way it use in marketing. Mostly API are complete pack of protocol,rules and functions which can be shared with third parties where as functions call are just internal calls within certain scope.

Top Articles
Latest Posts
Article information

Author: Manual Maggio

Last Updated:

Views: 5631

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Manual Maggio

Birthday: 1998-01-20

Address: 359 Kelvin Stream, Lake Eldonview, MT 33517-1242

Phone: +577037762465

Job: Product Hospitality Supervisor

Hobby: Gardening, Web surfing, Video gaming, Amateur radio, Flag Football, Reading, Table tennis

Introduction: My name is Manual Maggio, I am a thankful, tender, adventurous, delightful, fantastic, proud, graceful person who loves writing and wants to share my knowledge and understanding with you.