Skip to main content

Overview

The API Request node sends HTTP/HTTPS requests to APIs and web services. It supports all HTTP methods, custom headers, various body formats, form data, file uploads, and advanced retry logic. Response data is stored in the workflow context for use in subsequent nodes.

Configuration

url
string
required
The API endpoint URL. Supports variable interpolation: https://api.example.com/users/${data.userId}
method
string
default:"GET"
HTTP method to use.Options:
  • GET - Retrieve data
  • POST - Create resources
  • PUT - Update resources
  • PATCH - Partial update
  • DELETE - Delete resources
  • HEAD - Get headers only
  • OPTIONS - Get supported methods
headers
object
Custom HTTP headers as key-value pairs.Common headers:
  • Authorization: Bearer tokens, API keys
  • Content-Type: Request body format
  • Accept: Response format preference
  • Custom headers for API requirements
Supports variable interpolation in values: { "Authorization": "Bearer ${data.token}" }
body
string
Request body content. Supports variable interpolation.
bodyType
string
default:"json"
Format of the request body:
  • json - JSON format (Content-Type: application/json)
  • text - Plain text
  • xml - XML format
  • form - URL-encoded form data
timeout
number
default:"30000"
Request timeout in milliseconds.
contextKey
string
default:"apiResponse"
Context variable name to store the response.
failSilently
boolean
default:"false"
If true, failed requests log warnings but don’t stop workflow execution.

Form Data & File Uploads

formFields
array
Form fields for multipart/form-data requests.Field structure:
  • name: Field name
  • value: Field value (supports variable interpolation)
formFiles
array
Files for multipart/form-data uploads.File structure:
  • name: Form field name
  • filePath: Path to file (supports variable interpolation)

Retry Configuration

retryEnabled
boolean
default:"false"
Enable automatic retry on failure.
retryStrategy
string
default:"count"
Retry strategy:
  • count - Retry a fixed number of times
  • untilCondition - Retry until a condition is met
retryCount
number
default:"3"
Number of retry attempts (for count strategy).
retryUntilCondition
object
Condition for retry strategy. Checks response status, headers, or body.
retryDelay
number
default:"1000"
Delay between retries in milliseconds.
retryDelayStrategy
string
default:"fixed"
Delay strategy:
  • fixed - Constant delay
  • exponential - Exponentially increasing delay

Response Structure

The API response is stored in the context with this structure:
{
  "status": 200,                    // HTTP status code
  "statusText": "OK",               // Status text
  "headers": {                      // Response headers
    "content-type": "application/json",
    "content-length": "1234"
  },
  "body": { ... },                  // Response body (parsed JSON or raw text)
  "duration": 523,                  // Request duration in milliseconds
  "timestamp": "2024-01-15T10:30:00Z"  // Request timestamp
}

Examples

Basic Requests

{
  "type": "apiRequest",
  "data": {
    "url": "https://api.example.com/users",
    "method": "GET",
    "contextKey": "users"
  }
}

Authentication

{
  "type": "apiRequest",
  "data": {
    "url": "https://api.example.com/protected",
    "method": "GET",
    "headers": {
      "Authorization": "Bearer ${data.accessToken}"
    }
  }
}

With Variables

{
  "type": "apiRequest",
  "data": {
    "url": "https://api.example.com/users/${data.userId}/posts/${data.postId}",
    "method": "GET"
  }
}

Form Data & File Upload

{
  "type": "apiRequest",
  "data": {
    "url": "https://api.example.com/submit",
    "method": "POST",
    "formFields": [
      { "name": "username", "value": "johndoe" },
      { "name": "email", "value": "[email protected]" },
      { "name": "age", "value": "30" }
    ]
  }
}

With Retry

{
  "type": "apiRequest",
  "data": {
    "url": "https://api.example.com/unstable",
    "method": "GET",
    "retryEnabled": true,
    "retryCount": 3,
    "retryDelay": 2000,
    "retryDelayStrategy": "exponential"
  }
}

Accessing Response Data

const response = context.getData('apiResponse');

console.log(`Status: ${response.status}`);
console.log(`Duration: ${response.duration}ms`);

// Access response body
const users = response.body;
console.log(`Found ${users.length} users`);

// Extract specific data
const firstUser = users[0];
context.setData('currentUser', firstUser);

Common Patterns

API Chain

[
  {
    "type": "apiRequest",
    "data": {
      "url": "https://api.example.com/auth/login",
      "method": "POST",
      "body": "{\"username\": \"user\", \"password\": \"pass\"}",
      "contextKey": "authResponse"
    }
  },
  {
    "type": "apiRequest",
    "data": {
      "url": "https://api.example.com/data",
      "method": "GET",
      "headers": {
        "Authorization": "Bearer ${data.authResponse.body.token}"
      }
    }
  }
]

Error Handling

const response = context.getData('apiResponse');
if (response.status >= 400) {
  console.error(`API Error: ${response.status} - ${response.body.message}`);
  context.setData('hasError', true);
}

Notes

Response bodies are automatically parsed as JSON when the Content-Type header indicates JSON. Otherwise, they’re stored as raw text.
File paths for uploads must exist on the machine running the workflow. Relative paths are resolved from the project root.
The contextKey parameter allows storing multiple API responses in the workflow context for later use.

Build docs developers (and LLMs) love