Frequently Asked Questions: What are APIs, what are their methods, and how do they work?

This topic aims to foster knowledge in our community, primarily regarding general concepts related to APIs, and to provide an introduction to the main terms and examples of respective APIs in the VTEX context.

What are APIs?

Formal definition
API stands for Application Programming Interface.

In practice, APIs are mechanisms that allow two software components to communicate using a set of definitions and protocols.

Visual definition
Imagine two systems whose interaction requires some exchange of information or commands. Also consider that these systems have subprocesses with some similarity or relationship, and these subprocesses need to establish communication with the second system.

One way to build that bridge is through the use of APIs.

Even if the structures of the two systems are not the same, different modules in the second system can benefit from a connection with modules in the first system — for example, a data process forwarding information to a reporting process.

It’s worth noting that this communication can sometimes happen in both directions, but it’s not uncommon for one system to be passive and only process incoming requests. One example is the relationship between VTEX and ERPs: we receive requests from the ERP via API, but we do not send requests to the ERP. This would therefore be an example of the diagram above, not the one below.

What are API methods?

Methods are the types of requests an API can make. They must be declared when making a request, and each one has its own characteristics. Let’s look at the most common ones:

GET
GET is a type of request that retrieves information — its purpose is to access data stored by the target system.


Examples of common GETs in day-to-day VTEX use:

POST
With POST, new information is inserted into the target system — this is new data that could be the creation of a new customer in a customer database or a new order, for example.


Examples of common POSTs in day-to-day VTEX use:

PUT
PUT is similar to POST in that it fills in information, but it updates information within an existing structure, unlike POST which effectively creates a new instance of something.


Examples of common PUTs in day-to-day VTEX use:

PATCH
PATCH is similar to PUT, but is more selective about what gets updated. While PUT requires all parameters to be passed, PATCH lets you select which specific parameter should be updated and change only that one.


Examples of common PATCHes in day-to-day VTEX use:

DELETE
DELETE, as the name suggests, removes existing data without replacing it with new information.

What are Endpoints?

Endpoints are the URLs, or addresses, to which a request is sent. Like the method, the Endpoint is used to establish communication with the API.
Endpoints can have parameters, identified between { }, that point to the correct location for the request. For example, if I want to look up a price, I need to indicate in the Endpoint which account I’m referring to and which item that price belongs to.

What are Headers?

Headers are broader parameters than those found in the Endpoint — they relate not to the route, but to the mandatory criteria required to reach the destination. The clearest example of this is authentication: it is passed through the Headers, so when making a request you need to include your credentials, and the dedicated place for that is the Headers. But they’re not limited to that — things like What content format is accepted? or Result pagination keys can also be passed via Headers.

What is the Body?

For methods like POST, PUT, and PATCH, information is sent along with the request. This information is passed via JSON (objects), and this body containing the detailed information is called the request body. In our API documentation, we provide examples of the accepted formats for the body of each API, since passing the body in an unexpected format will result in a request error.
Highlighted in the red box is a Body template that is accepted for this request. The variable values can be changed as long as the format is respected, but the variable names must be preserved.

What is cURL?

cURL is the combination of all this information: Method, Endpoint, Headers, and Body. With it, you can make a complete request. Here’s an example:


Notice that it combines all the elements — you just need to fill in your authentication and edit the body to be able to make the request.

To learn the practical step-by-step for making requests, check out this topic right here in the Community: Frequently Asked Questions: How to use APIs? | Step-by-step beginner’s guide to using the Developers APIs and applying them to your VTEX store

Cleber Feitosa
Field Software Engineer | VTEX

1 Like