Call Serverless Function
Workflow & Logic
Call Serverless Function
Execute serverless code directly within workflows for complex operations.
POST
Call Serverless Function
Authorizations
Bearer token from your account (https://agent.ai/user/integrations#api)
Body
application/json
Select the language for the serverless function, such as 'Python' or 'Node'.
Available options:
python, node serverless_code
string
default:import json
def lambda_handler(event, context):
agent_context = {}
# Handle POST requests
if event and 'body' in event and event['body']:
try:
event_json = json.loads(event['body'])
agent_context = event_json.get('context', event_json)
except json.JSONDecodeError:
# Handle case where body isn't valid JSON
agent_context = {"error": "Invalid JSON in request body"}
# Handle GET requests
elif event and 'queryStringParameters' in event and event['queryStringParameters']:
agent_context = event['queryStringParameters']
# Handle API Gateway format for both
elif event and 'pathParameters' in event and event['pathParameters']:
agent_context = event['pathParameters']
# Prepare response
body = {
"message": "Go Agent.AI Serverless Python Functions v1.0! Your function executed successfully!",
"input": event,
"context": agent_context
}
# Include CORS headers for browser access
headers = {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Allow-Methods": "OPTIONS,POST,GET"
}
response = {
"statusCode": 200,
"headers": headers,
"body": json.dumps(body)
}
return response
required
Enter the serverless function code here, using Python or Node syntax to perform specific tasks.
Provide a variable name to store the result of the serverless function, like 'function_result' or 'api_response'.
Pattern:
^[a-zA-Z][a-zA-Z0-9_]*$
