api

The API block enables you to connect your workflow to external services through HTTP requests. It supports various methods like GET, POST, PUT, DELETE, and PATCH, allowing you to interact with virtually any API endpoint.

Overview

The API block enables you to:

1

Connect to external services

Make HTTP requests to REST APIs and web services

2

Send and receive data

Process responses and transform data from external sources

3

Integrate third-party platforms

Connect with services like Stripe, Slack, or custom APIs

4

Handle authentication

Support various auth methods including Bearer tokens and API keys

Configuration Options

URL

The endpoint URL for the API request. This can be:

  • A static URL entered directly in the block

  • A dynamic URL connected from another block's output

  • A URL with path parameters

Method

Select the HTTP method for your request:

  • GET: Retrieve data from the server

  • POST: Send data to the server to create a resource

  • PUT: Update an existing resource on the server

  • DELETE: Remove a resource from the server

  • PATCH: Partially update an existing resource

Query Parameters

Define key-value pairs that will be appended to the URL as query parameters. For example:

These would be added to the URL as ?apiKey=your_api_key_here&limit=10.

Headers

Configure HTTP headers for your request. Common headers include:

Request Body

For methods that support a request body (POST, PUT, PATCH), you can define the data to send. The body can be:

  • JSON data entered directly in the block

  • Data connected from another block's output

  • Dynamically generated during workflow execution

Accessing Results

After an API request completes, you can access its outputs:

  • <api.data>: The response body data from the API

  • <api.status>: HTTP status code (200, 404, 500, etc.)

  • <api.headers>: Response headers from the server

  • <api.error>: Error details if the request failed

Advanced Features

Dynamic URL Construction

Build URLs dynamically using variables from previous blocks:

Request Retries

The API block automatically handles:

  • Network timeouts with exponential backoff

  • Rate limit responses (429 status codes)

  • Server errors (5xx status codes) with retry logic

  • Connection failures with reconnection attempts

Response Validation

Validate API responses before processing:

Inputs and Outputs

  • URL: The endpoint to send the request to

  • Method: HTTP method (GET, POST, PUT, DELETE, PATCH)

  • Query Parameters: Key-value pairs for URL parameters

  • Headers: HTTP headers for authentication and content type

  • Body: Request payload for POST/PUT/PATCH methods

Example Use Cases

Fetch User Profile Data

Scenario: Retrieve user information from external service

  1. Function block constructs user ID from input

  2. API block calls GET /users/{id} endpoint

  3. Function block processes and formats user data

  4. Response block returns formatted profile

Create Support Ticket

Scenario: Submit support request to ticketing system

  1. Agent analyzes user issue and generates ticket data

  2. API block POSTs ticket to support system

  3. Condition block checks if ticket was created successfully

  4. Response block confirms ticket creation with ID

Payment Processing

Scenario: Process payment through Stripe API

  1. Function block validates payment data

  2. API block creates payment intent via Stripe

  3. Condition block handles payment success/failure

  4. Function block updates order status in database

Best Practices

  • Use environment variables for sensitive data: Don't hardcode API keys or credentials

  • Handle errors gracefully: Connect error handling logic for failed requests

  • Validate responses: Check status codes and response formats before processing data

  • Respect rate limits: Be mindful of API rate limits and implement appropriate throttling

Was this helpful?