n8n has more than 280 nodes that allow you to connect different services together and build automation workflows. All these nodes, under the hood, use APIs to communicate with the respective services. In this article, I will help you understand what APIs are and how n8n uses them to interact with the services you use in your daily life.
What is an API?
An Application Programming Interface (API) allows different programs to communicate with each other. These programs can be running on the same machine or on different machines, but in any case, they need a way to interact with each other.
Basically, an API provides the information that it gets asked for. In fact, we interact with APIs daily and don’t even notice them. For example, you may have seen Tweets or YouTube videos embedded on different web pages. This is possible via the Twitter API or the YouTube API, respectively, which let you share the content from these platforms on your website or other platforms.
How do APIs work?
It’s easier to understand how APIs work with an analogy. Let’s say you want to turn on the lights in your room. You go to the switchboard and turn on the switches. In milliseconds the lights glow in your room. Technically, you made a request (interacting with the switches), a process was carried out (the circuit allowing the current to flow), and you got a result (the lights glowing!). Here, the electric circuit is your API: the electric circuit processed your request and gave you an output.
In the case of n8n, the nodes (integrations) that you see use APIs provided by different services to allow you to interact with these services within your workflows. In this way, you don’t have to write code to interact with APIs, so n8n reduces the friction.
Continuing above example, let’s say that you have upgraded the light bulbs and are now using Philips Hue. With this new acquisition, you want to take your smart home to the next level and make the light bulb glow brighter when you receive a new payment on Stripe. Using n8n, you can connect your Stripe account with the light. When you receive a payment, the Stripe Trigger node tells n8n to start the workflow, which uses the Philips Hue node to instruct the light bulb to glow brighter.
Right from the start of the workflow till the end, the communication between Stripe and Philips Hue happened via APIs.
Types of API
There are different types of API for different purposes. Let’s walk through the 7 most popular types of APIs.
REST API
REpresentational State Transfer (REST) is the most common type of API. It relies on guiding principles like client-server structure, simple and uniform interfaces to communicate across systems, and more. Almost all the regular nodes in n8n use REST APIs.
Webhooks
Webhooks send the data from one system to another when an event occurs. This means that webhooks are event-based, so you don’t have to ask for the data. In n8n, trigger nodes and the Webhook node (obviously) are based on webhooks. For example, if a deal gets created in your Pipedrive CMS or a lead is updated in HubSpot, the Pipedrive Trigger node or the HubSpot Trigger node, respectively, receives the data sent by the CMS.
GraphQL API
Created at Facebook, Graph Query Language (GraphQL) allows you to fetch the data you need. You can use the GraphQL node in n8n to interact with a GraphQL API and execute a query.
SSE API
Server-sent Events (SSE) send updates to a client automatically via an HTTP connection. If you use an SSE API and want to trigger an n8n workflow, you can use the SSE Trigger node.
SOAP API
Simple Object Access Protocol (SOAP) is more structured and formalized than REST. It uses XML as a format to transfer data. If you’re using a SOAP API in n8n, you can use the XML node to convert the data to JSON and vice versa.
WebSocket API
WebSocket communications protocol is a full-duplex communication channel. The WebSocket APIs allow data to be communicated between client and server while keeping the connections open. Multimedia chat applications and multi-player games are the most common examples that consume the WebSocket protocol.
gRPC API
Created by Google, Remote Procedure Call (gRPC) allows a client to call a server and makes it easier for distributed systems to communicate with one another.
What’s next?
In this article, you learned what APIs are and how n8n uses them to communicate with different services. You also got an overview of different types of APIs and how to interact with them in n8n via their dedicated nodes.
With this knowledge, build your automation workflows and share it with the community on the workflows page.
You can also build your API with n8n! Follow the article Learn to Build Powerful API Endpoints Using Webhooks to learn more.
In case you’ve any questions, feel free to reach out to me on Twitter or ask for help on our forum 🧡 And to get more content about automation, subscribe to our newsletter 📧