APIs
Connect automation workflows to apps and AI services through APIs.
Modern automation systems rarely work with only one application. They connect forms, databases, email platforms, payment services, cloud storage, CRM systems, and AI models. APIs provide the common communication layer that lets these systems exchange data and perform actions automatically.
What Is an API?
API stands for Application Programming Interface. It is a documented set of rules that allows one software application to request data or actions from another. The requesting application does not need direct access to the other system's source code or database; it communicates through the interface the provider exposes.
For example, an online store can send payment details to a payment service, receive an approved or declined result, and update the order—all through APIs. The store uses the service without needing to understand its internal payment-processing implementation.
A Simple Analogy
An API is like a waiter in a restaurant. You choose from a menu, give the waiter a valid order, and the waiter carries it to the kitchen. The kitchen processes the request and returns a result. You do not enter the kitchen or control how it operates; you use the agreed interface.
Why APIs Matter in AI Automation
Automation platforms provide ready-made connectors for popular applications, but those connectors are usually built on APIs. When a native connector is unavailable or does not expose a required feature, an HTTP request step can often call the service's API directly.
- Send a support message to an AI model for classification or summarization.
- Create or update a contact in a CRM.
- Read records from a database or business application.
- Send email, SMS, or team notifications.
- Process payments and retrieve transaction status.
- Upload files to cloud storage or start a document-processing job.
- Connect internal tools to n8n, Make, Zapier, or custom workflows.
The Request-and-Response Model
Most web APIs follow a request-and-response model. A client sends a request to an endpoint. The server validates and processes it, then returns a response containing a status code, headers, and usually a data body.
| Part | Purpose | Example |
|---|---|---|
| Base URL | Identifies the API service | https://api.example.com |
| Endpoint | Identifies a resource or action | /v1/customers |
| Method | States the intended operation | GET or POST |
| Headers | Carry metadata and credentials | Content-Type: application/json |
| Parameters | Filter or identify requested data | ?status=active |
| Body | Carries data sent to the service | A JSON customer object |
| Status code | Summarizes the outcome | 200, 404, or 500 |
| Response body | Returns data or error details | A JSON result |
Example Request
POST /v1/leads HTTP/1.1
Host: api.example.com
Authorization: Bearer YOUR_ACCESS_TOKEN
Content-Type: application/json
{
"name": "Asha Rao",
"email": "asha@example.com",
"source": "website"
}Example Response
{
"id": "lead_1042",
"status": "created",
"name": "Asha Rao"
}Common HTTP Methods
| Method | Typical Purpose | Automation Example |
|---|---|---|
| GET | Retrieve data | Fetch open support tickets |
| POST | Create data or start an action | Create a lead or request an AI summary |
| PUT | Replace an existing resource | Replace a complete customer profile |
| PATCH | Update selected fields | Change only a ticket's priority |
| DELETE | Remove a resource | Delete a temporary file |
The API documentation defines which methods each endpoint accepts. A method name suggests intent, but it does not override the provider's documentation or authorization rules.
Parameters, Headers, and JSON Bodies
- Path parameters identify a specific resource, such as /customers/123.
- Query parameters filter, sort, paginate, or customize results, such as ?status=open&limit=20.
- Headers describe the request and commonly carry content type, authorization, tracing, or version information.
- The request body contains structured input for create or update operations. JSON is the most common format in modern web APIs.
- The response body should be parsed only after checking the response status and expected content type.
Authentication and Authorization
Authentication proves who or what is calling an API; authorization determines what that caller may do. Common approaches include API keys, bearer tokens, OAuth 2.0, and signed requests.
| Approach | Typical Use | Important Practice |
|---|---|---|
| API key | Server-to-server or simple integrations | Store it in a secret manager or protected connection |
| Bearer token | Temporary or scoped access | Send it in the Authorization header |
| OAuth 2.0 | Access to a user's account in another service | Use the platform's secure OAuth connection flow |
| Signed request | High-trust service integrations | Protect signing secrets and validate timestamps |
Never hard-code production credentials in source files, prompts, browser-side code, shared workflow exports, or logs. Grant the smallest set of permissions the workflow requires and rotate or revoke credentials when access changes.
Understanding Status Codes
| Range | Meaning | Examples |
|---|---|---|
| 200–299 | The request succeeded | 200 OK, 201 Created, 204 No Content |
| 400–499 | The request has a client-side problem | 400 Invalid input, 401 Unauthenticated, 403 Forbidden, 404 Not found, 429 Rate limited |
| 500–599 | The service failed to complete a valid request | 500 Internal error, 502 Bad gateway, 503 Unavailable |
Do not treat every non-200 result the same. Invalid input usually needs correction, an expired credential needs renewal, a rate limit may need a delayed retry, and a persistent server failure may require escalation.
Calling an API with JavaScript
async function createLead(input, token) {
const response = await fetch("https://api.example.com/v1/leads", {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
name: input.name,
email: input.email,
source: "website"
})
});
if (!response.ok) {
const details = await response.text();
throw new Error(`API request failed (${response.status}): ${details}`);
}
return response.json();
}Calling an API with Python
import requests
def list_products(token):
response = requests.get(
"https://api.example.com/v1/products",
headers={"Authorization": f"Bearer {token}"},
params={"status": "active", "limit": 20},
timeout=15,
)
response.raise_for_status()
return response.json()Using APIs in Workflow Platforms
In n8n, Make, or Zapier, the same concepts usually appear in an HTTP request action: choose a method, enter the endpoint, configure authentication, add headers or parameters, map data into the body, and map the response into later steps.
Form submission
-> Validate required fields
-> POST customer message to an AI API
-> Validate structured AI output
-> POST result to CRM API
-> Notify assigned team
-> Record outcome and request IDAPIs and Webhooks
An API call is commonly used when your workflow wants to request data or perform an action. A webhook is commonly used when another system wants to notify your workflow that an event has happened. Many reliable automations use both: a webhook starts the workflow, then API calls retrieve details and update connected systems.
Pagination, Rate Limits, and Reliability
- Pagination: APIs may return large datasets in pages. Continue using the documented page, cursor, or next-link value until all required records are collected.
- Rate limits: Control request volume and respect retry instructions so the workflow does not overwhelm the service.
- Timeouts: Set a maximum wait time so one slow dependency does not block a workflow indefinitely.
- Retries: Retry temporary failures with increasing delays and randomness; do not blindly retry invalid requests.
- Idempotency: Use an idempotency key or duplicate check for operations such as payments and record creation so a retry does not repeat the action.
- Validation: Verify required response fields and data types before passing results to later steps.
- Fallbacks: Queue work, route to manual review, or notify an owner when a critical integration remains unavailable.
Security Practices
- Use HTTPS and reject untrusted or unexpected endpoints.
- Keep credentials in protected connections, environment secrets, or a secret manager.
- Apply least-privilege scopes and separate development from production credentials.
- Validate and sanitize inputs before sending them to external services.
- Minimize sensitive data and avoid placing secrets or personal data in URLs and logs.
- Allow-list destinations when users or AI-generated output can influence a request URL.
- Redact credentials and sensitive response fields from monitoring data.
- Review vendor retention, privacy, and compliance requirements before transmitting business data.
Testing and Troubleshooting
- Read the official documentation for the endpoint, schema, authentication, limits, and version.
- Test with safe sample data in a development environment before connecting live systems.
- Inspect the status code, response body, request ID, and relevant headers when a call fails.
- Test missing fields, malformed values, empty results, expired credentials, rate limits, and service outages.
- Log enough context to diagnose a run without exposing secrets or unnecessary personal data.
- Monitor latency, success rate, error categories, request volume, and cost.
- Assign an owner and review integrations when an API version or response schema changes.
Best Practices
- Use the correct method and send only the data the endpoint requires.
- Validate inputs before the call and validate the response before using it.
- Handle each important error category deliberately.
- Design retries so they cannot create duplicate records or actions.
- Reuse authenticated connections and avoid unnecessary requests.
- Document endpoints, field mappings, assumptions, owners, and recovery procedures.
- Keep integrations observable and update them when provider APIs change.