> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes. # Create SWML webhook POST https://%7BYour_Space_Name%7D.signalwire.com/api/fabric/resources/swml_webhooks Content-Type: application/json Creates a resource that requests calling or messaging SWML from your server when the handler runs. Use it when instructions must be generated from current application state; use [Create SWML Script](/docs/apis/rest/swml-scripts/create-swml-script) when the SWML can be stored in SignalWire, or [Create cXML webhook](/docs/apis/rest/cxml-webhook/create-cxml-webhook) when the server returns cXML. #### Permissions The API token used to authenticate must have the following scope(s) enabled to make a successful request: _Voice_, _Messaging_, _Fax_, or _Video_. [Learn more about API scopes](/docs/platform/your-signalwire-api-space). Reference: https://signalwire.com/docs/apis/rest/swml-webhook/create-swml-webhook ## Authentication - `Authorization` header (basic auth, required) — SignalWire Basic Authentication using Project ID and API Token. The client sends HTTP requests with the Authorization header containing the word Basic followed by a space and a base64-encoded string of project_id:token. The project ID will be used as the username and the API token as the password. Example: ``` Authorization: Basic base64(project_id:token) ``` ## Request ### Body (application/json) This endpoint expects a SWMLWebhookCreateRequest. - `primary_request_url` (string, required) — Primary URL SignalWire fetches the SWML document from when the webhook fires. The webhook payload depends on `used_for`: for `calling`, see the [SWML inbound call webhook](/docs/apis/rest/webhooks/inbound-call-webhook); for `messaging`, see the [SWML inbound message webhook](/docs/apis/rest/webhooks/inbound-message-webhook). - `name` (string, optional) — Name of the SWML Webhook. - `used_for` (enum, optional, default: calling) — Indicates whether this SWML Webhook handles inbound calls or inbound messages. Determines the payload SignalWire POSTs to `primary_request_url`. - Allowed values: `calling`, `messaging` - `primary_request_method` (enum, optional, default: POST) — Primary request method of the SWML Webhook. - Allowed values: `GET`, `POST` - `fallback_request_url` (string, optional) — Fallback URL SignalWire fetches the SWML document from if the primary URL fails. Receives the same payload as `primary_request_url` — see the [SWML inbound call webhook](/docs/apis/rest/webhooks/inbound-call-webhook) or [SWML inbound message webhook](/docs/apis/rest/webhooks/inbound-message-webhook) depending on `used_for`. - `fallback_request_method` (enum, optional, default: POST) — Fallback request method of the SWML Webhook. - Allowed values: `GET`, `POST` - `status_callback_url` (string, optional) — URL to receive message status callback events for outbound messages sent by this webhook (`reply` or `send_sms`). See the [Message status callback](/docs/apis/rest/webhooks/message-status-callback) webhook for the payload your URL will receive. - `status_callback_method` (enum, optional, default: POST) — Status callback method of the SWML Webhook. - Allowed values: `GET`, `POST` ## Response ### 201 The request has succeeded and a new resource has been created as a result. - `id` (string, required) — Unique ID of the SWML Webhook. - `project_id` (string, required) — Unique ID of the Project. - `display_name` (string, required) — Display name of the SWML Webhook Fabric Resource - `type` (enum, required) — Type of the Fabric Resource - Allowed values: `swml_webhook` - `created_at` (datetime, required) — Date and time when the resource was created. - `updated_at` (datetime, required) — Date and time when the resource was updated. - `swml_webhook` (SWMLWebhook, required) — SWML Webhook data. ## Errors ### 401 Unauthorized Error Access is unauthorized. - `error` (enum, required) - Allowed values: `Unauthorized` ### 404 Not Found Error The server cannot find the requested resource. - `error` (enum, required) - Allowed values: `Not Found` ### 422 Unprocessable Entity Error The request contains invalid parameters. See errors for details. - `errors` (list of Types.StatusCodes.RestApiErrorItem, required) — List of validation errors. ### 500 Internal Server Error An internal server error occurred. - `error` (enum, required) - Allowed values: `Internal Server Error` ## Types ### SWMLWebhook - `id` (string, required) — Unique ID of the SWML Webhook. - `name` (string, required) — Name of the SWML Webhook. - `used_for` (enum, required) — Indicates whether this SWML Webhook handles inbound calls or inbound messages. Determines the payload SignalWire POSTs to `primary_request_url`. - Allowed values: `calling`, `messaging` - `primary_request_url` (string, required) — Primary URL SignalWire fetches the SWML document from when the webhook fires. The webhook payload depends on `used_for`: for `calling`, see the [SWML inbound call webhook](/docs/apis/rest/webhooks/inbound-call-webhook); for `messaging`, see the [SWML inbound message webhook](/docs/apis/rest/webhooks/inbound-message-webhook). - `primary_request_method` (enum, required) — Primary request method of the SWML Webhook. - Allowed values: `GET`, `POST` - `fallback_request_url` (string, required, nullable) — Fallback URL SignalWire fetches the SWML document from if the primary URL fails. Receives the same payload as `primary_request_url` — see the [SWML inbound call webhook](/docs/apis/rest/webhooks/inbound-call-webhook) or [SWML inbound message webhook](/docs/apis/rest/webhooks/inbound-message-webhook) depending on `used_for`. - `fallback_request_method` (enum, required) — Fallback request method of the SWML Webhook. - Allowed values: `GET`, `POST` - `status_callback_url` (string, required, nullable) — URL to receive message status callback events for outbound messages sent by this webhook (`reply` or `send_sms`). See the [Message status callback](/docs/apis/rest/webhooks/message-status-callback) webhook for the payload your URL will receive. - `status_callback_method` (enum, required) — Status callback method of the SWML Webhook. - Allowed values: `GET`, `POST` ### Types.StatusCodes.RestApiErrorItem Details about a specific error. - `type` (string, required) — The category of error. - `code` (string, required) — A specific error code. - `message` (string, required) — A description of what caused the error. - `url` (string, required) — A link to documentation about this error. - `attribute` (string, optional, nullable) — The request parameter that caused the error, if applicable. ## Examples **Request** ```json { "primary_request_url": "https://primary.com" } ``` **Response** ```json { "id": "a87db7ed-8ebe-42e4-829f-8ba5a4152f54", "project_id": "99151cf8-9548-4860-ba70-a8de824f3312", "display_name": "Booking Assistant", "type": "swml_webhook", "created_at": "2024-05-06T12:20:00Z", "updated_at": "2024-05-06T12:20:00Z", "swml_webhook": { "id": "a87db7ed-8ebe-42e4-829f-8ba5a4152f54", "name": "My SWML Webhook", "used_for": "calling", "primary_request_url": "https://primary.com", "primary_request_method": "GET", "fallback_request_url": "https://fallback.com", "fallback_request_method": "GET", "status_callback_url": "https://callback.com", "status_callback_method": "POST" } } ``` **SDK Code** ```python import requests url = "https://{your_space_name}.signalwire.com/api/fabric/resources/swml_webhooks" payload = { "primary_request_url": "https://primary.com" } headers = { "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers, auth=("", "")) print(response.json()) ``` ```javascript const url = 'https://{your_space_name}.signalwire.com/api/fabric/resources/swml_webhooks'; const credentials = btoa(":"); const options = { method: 'POST', headers: { Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json' }, body: '{"primary_request_url":"https://primary.com"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://{your_space_name}.signalwire.com/api/fabric/resources/swml_webhooks" payload := strings.NewReader("{\n \"primary_request_url\": \"https://primary.com\"\n}") req, _ := http.NewRequest("POST", url, payload) req.SetBasicAuth("", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://{your_space_name}.signalwire.com/api/fabric/resources/swml_webhooks") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request.basic_auth("", "") request["Content-Type"] = 'application/json' request.body = "{\n \"primary_request_url\": \"https://primary.com\"\n}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://{your_space_name}.signalwire.com/api/fabric/resources/swml_webhooks") .basicAuth("", "") .header("Content-Type", "application/json") .body("{\n \"primary_request_url\": \"https://primary.com\"\n}") .asString(); ``` ```php request('POST', 'https://{your_space_name}.signalwire.com/api/fabric/resources/swml_webhooks', [ 'body' => '{ "primary_request_url": "https://primary.com" }', 'headers' => [ 'Content-Type' => 'application/json', ], 'auth' => ['', ''], ]); echo $response->getBody(); ``` ```csharp using RestSharp; using RestSharp.Authenticators; var client = new RestClient("https://{your_space_name}.signalwire.com/api/fabric/resources/swml_webhooks"); client.Authenticator = new HttpBasicAuthenticator("", ""); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"primary_request_url\": \"https://primary.com\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let credentials = Data(":".utf8).base64EncodedString() let headers = [ "Authorization": "Basic \(credentials)", "Content-Type": "application/json" ] let parameters = ["primary_request_url": "https://primary.com"] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://{your_space_name}.signalwire.com/api/fabric/resources/swml_webhooks")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```