webhook

View as MarkdownOpen in Claude

Add an API call. Multiple webhooks can be chained — they execute in order, and if earlier webhooks fail, later ones act as fallbacks.

Parameters

method
stringRequired

HTTP method for the request.

  • "GET" — retrieve a resource
  • "POST" — create a resource or submit data
  • "PUT" — replace a resource
  • "DELETE" — remove a resource
  • "PATCH" — partially update a resource
url
stringRequired

API endpoint URL. Supports ${variable} substitutions (use ${enc:args.param} for URL-encoded values).

opts
object

Optional configuration.

opts.headers
Record<string, string>

HTTP headers to include in the request.

opts.formParam
string

Send the JSON body as a single form parameter with this name.

opts.inputArgsAsParams
boolean

Merge function arguments into the request parameters automatically.

opts.requireArgs
string[]

Only execute this webhook if all listed arguments are present.

Returns

DataMap — Self for method chaining.

Example

1import { DataMap, FunctionResult } from '@signalwire/sdk';
2
3const weather = new DataMap('get_weather');
4weather
5 .purpose('Get current weather for a city')
6 .parameter('city', 'string', 'City name', { required: true })
7 .webhook('GET', 'https://api.weatherapi.com/v1/current.json?key=YOUR_API_KEY&q=${enc:args.city}', {
8 headers: { Accept: 'application/json' },
9 })
10 .output(new FunctionResult('Weather: ${response.current.condition.text}'));
11
12console.log(weather.toSwaigFunction());

Chained webhooks act as fallbacks — if the first webhook fails, the second is tried:

1import { DataMap, FunctionResult } from '@signalwire/sdk';
2
3const search = new DataMap('search');
4search
5 .purpose('Search across multiple providers')
6 .parameter('query', 'string', 'Search query', { required: true })
7 .webhook('GET', 'https://primary-api.example.com/search?q=${enc:args.query}')
8 .output(new FunctionResult('Primary: ${response.result}'))
9 .webhook('GET', 'https://backup-api.example.com/search?q=${enc:args.query}')
10 .output(new FunctionResult('Backup: ${response.result}'))
11 .fallbackOutput(new FunctionResult('All search providers are unavailable.'));