> For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

# webhook

> Add an API call to the DataMap.

[ref-datamap]: /docs/server-sdks/reference/python/agents/data-map

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`** `str` — required

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`** `str` — required

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`** `bool` — default: 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`][ref-datamap] -- Self for method chaining.

## **Example**

```python {8}
from signalwire import DataMap
from signalwire import FunctionResult

weather = (
    DataMap("get_weather")
    .purpose("Get current weather for a city")
    .parameter("city", "string", "City name", required=True)
    .webhook(
        "GET",
        "https://api.weatherapi.com/v1/current.json"
        "?key=YOUR_API_KEY&q=${enc:args.city}",
        headers={"Accept": "application/json"}
    )
    .output(FunctionResult("Weather: ${response.current.condition.text}"))
)

print(weather.to_swaig_function())
```

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

```python {8,10}
from signalwire import DataMap
from signalwire import FunctionResult

search = (
    DataMap("search")
    .purpose("Search across multiple providers")
    .parameter("query", "string", "Search query", required=True)
    .webhook("GET", "https://primary-api.example.com/search?q=${enc:args.query}")
    .output(FunctionResult("Primary: ${response.result}"))
    .webhook("GET", "https://backup-api.example.com/search?q=${enc:args.query}")
    .output(FunctionResult("Backup: ${response.result}"))
    .fallback_output(FunctionResult("All search providers are unavailable."))
)
```