API
Connect to external services through API endpoints
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:
- Make HTTP requests to external services and APIs
- Process and transform data from external sources
- Send data to external systems
- Integrate with third-party platforms and services
- Create webhooks and callbacks
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
Inputs and Outputs
Inputs
- URL: The endpoint to send the request to
- Method: The HTTP method to use
- Query Parameters: Key-value pairs for URL parameters
- Headers: HTTP headers for the request
- Body: Data to send with the request (for applicable methods)
Outputs
- Status Code: The HTTP status code returned by the server
- Response Body: The data returned by the server
- Headers: Response headers from the server
- Error: Any error information if the request fails
Example Usage
Here's an example of how an API block might be configured to fetch weather data:
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
- Cache responses when appropriate: For frequently accessed data that doesn't change often