AgentsDataMap

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
strRequired

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
strRequired

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

headers
dict[str, str]

HTTP headers to include in the request.

form_param
str

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

input_args_as_params
boolDefaults to false

Merge function arguments into the request parameters automatically.

require_args
list[str]

Only execute this webhook if all listed arguments are present.

Returns

DataMap — Self for method chaining.

Example

1from signalwire import DataMap
2from signalwire import FunctionResult
3
4weather = (
5 DataMap("get_weather")
6 .purpose("Get current weather for a city")
7 .parameter("city", "string", "City name", required=True)
8 .webhook(
9 "GET",
10 "https://api.weatherapi.com/v1/current.json"
11 "?key=YOUR_API_KEY&q=${enc:args.city}",
12 headers={"Accept": "application/json"}
13 )
14 .output(FunctionResult("Weather: ${response.current.condition.text}"))
15)
16
17print(weather.to_swaig_function())

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

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