How to Connect AI Agents to External APIs
How API Connections Work in Agent Workflows
An API (Application Programming Interface) is a way for one system to send requests to another and receive data back. When your AI agent connects to an external API, it sends an HTTP request with specific parameters and receives a response containing data or a confirmation that an action was completed.
In a chain command workflow, you add an HTTP request step that calls the external API. The step includes the URL, request method (GET for reading data, POST for sending data), any required headers (like authentication tokens), and the request body. The response comes back as data that the next step in your workflow can use.
In a custom app, the AI-generated code can make HTTP requests directly using standard PHP functions. This gives you more flexibility for complex API interactions that involve multiple calls, pagination, or error retry logic.
Common External API Integrations
CRM Systems
Connect your agent to your CRM (Salesforce, HubSpot, Pipedrive, or others) to create contacts, update deal stages, log activities, and pull customer data. When your lead qualification agent identifies a hot lead, it can create a contact in your CRM automatically with the lead's details and qualification score.
Accounting and Invoicing
Connect to QuickBooks, Xero, FreshBooks, or Stripe to create invoices, record payments, check account balances, or pull financial data for reporting. Your order processing agent can create an invoice in your accounting system at the same time it confirms the order.
Project Management
Connect to Trello, Asana, Monday.com, or Jira to create tasks, update project status, assign team members, or pull project data. When your agent processes a customer support request, it can create a task in your project management tool for the responsible team member.
Communication Services
While the platform handles SMS and email natively, you might want to send messages through other services like Slack, Microsoft Teams, Discord, or WhatsApp. API connections let your agent post updates to a Slack channel, send a Teams message to a specific person, or deliver notifications through any messaging service with an API.
Data and Enrichment Services
Connect to data providers to enrich the information your agent works with. Clearbit or FullContact can provide company information from an email address. Google Maps can geocode addresses. Weather APIs can provide conditions for location-based decisions. Any data available via API can feed into your agent's decision-making process.
Setting Up an API Connection
Most external APIs require authentication. This typically means creating an account with the service, generating an API key or OAuth token, and noting the API base URL and any required headers. Store these credentials securely in your platform settings.
Read the external service's API documentation to identify the specific endpoint you need. Note the URL path, the HTTP method (GET, POST, PUT, DELETE), the required parameters, and the format of the response. Most modern APIs use JSON for both requests and responses.
In your chain command, add an HTTP request step. Configure the URL, method, headers (including your authentication token), and request body. If the API call depends on data from a previous step (like a lead's email address to look up in your CRM), use workflow variables to insert that data into the request.
The API returns data that your workflow needs to use. Parse the response to extract the fields you need for subsequent steps. If the API returns a list of results, you may need to loop through them. If the API returns an error, branch to an error handling path.
External APIs can fail for various reasons: network issues, expired tokens, rate limits, or service outages. Build error handling into your workflow. If an API call fails, log the error and either retry after a delay or fall back to an alternative action. Most APIs impose rate limits, so make sure your agent does not exceed them by spacing out requests appropriately.
Using AI to Interpret API Responses
One powerful pattern is using the AI model to interpret complex API responses. Instead of writing conditional logic to handle every possible response format, send the API response to the AI and ask it to extract the information you need in a standardized format. This is especially useful for APIs that return complex nested data or for integrations where the response format varies.
For example, if you query a CRM API for a contact and it returns a complex object with dozens of fields, you can send that response to the AI with: "Extract the contact's name, email, last activity date, and deal value from this CRM response. Return as JSON." The AI handles the parsing regardless of how the CRM structures its data.
Webhook-Based Integrations
APIs work in two directions. Your agent can call external APIs (outbound), and external services can call your agent via webhooks (inbound). Many services support webhooks that notify your system when something happens: a new payment in Stripe, a form submission in Typeform, a message in Slack, or a commit in GitHub.
Configure the external service to send webhook notifications to your platform's webhook endpoint. Your agent workflow triggers on these incoming webhooks and processes the data. This creates real-time integrations where your agent responds immediately to events in external systems. See How to Trigger a Workflow From a Webhook for setup details.
Connect your AI agents to any external service with an API. Extend your automation beyond the platform.
Get Started Free