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

# create

> Create a new SWML webhook resource.

Create a new SWML webhook resource.

### Schema

```yaml
openapi: 3.1.0
info:
  title: API
  version: 1.0.0
paths:
  /api/fabric/resources/swml_webhooks:
    post:
      operationId: create_swml_webhook
      summary: Create SWML webhook
      description: >-
        Creates an SWML Webhook


        #### 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).
      tags:
        - subpackage_swmlWebhook
      responses:
        '201':
          description: >-
            The request has succeeded and a new resource has been created as a
            result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SWMLWebhookResponse'
        '401':
          description: Access is unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Types.StatusCodes.StatusCode401'
        '404':
          description: The server cannot find the requested resource.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Types.StatusCodes.StatusCode404'
        '422':
          description: The request contains invalid parameters. See errors for details.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SwmlWebhookCreateStatusCode422'
        '500':
          description: An internal server error occurred.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Types.StatusCodes.StatusCode500'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SWMLWebhookCreateRequest'
servers:
  - url: https://%7BYour_Space_Name%7D.signalwire.com
    description: SignalWire API
components:
  schemas:
    SwmlWebhookCreateRequestUsedFor:
      type: string
      enum:
        - calling
        - messaging
      default: calling
      description: >-
        Indicates whether this SWML Webhook handles inbound calls or inbound
        messages. Determines the payload SignalWire POSTs to
        `primary_request_url`.
      title: SwmlWebhookCreateRequestUsedFor
    RequestUrlMethodType:
      type: string
      enum:
        - GET
        - POST
      description: The method type to use for the URL
      title: RequestUrlMethodType
    SWMLWebhookCreateRequest:
      type: object
      properties:
        name:
          type: string
          description: Name of the SWML Webhook.
        used_for:
          $ref: '#/components/schemas/SwmlWebhookCreateRequestUsedFor'
          default: calling
          description: >-
            Indicates whether this SWML Webhook handles inbound calls or inbound
            messages. Determines the payload SignalWire POSTs to
            `primary_request_url`.
        primary_request_url:
          type: string
          format: uri
          description: >-
            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/swml-webhook/webhooks/inbound-call-webhook);
            for `messaging`, see the [SWML inbound message
            webhook](/docs/apis/rest/swml-webhook/webhooks/inbound-message-webhook).
        primary_request_method:
          $ref: '#/components/schemas/RequestUrlMethodType'
          default: POST
          description: Primary request method of the SWML Webhook.
        fallback_request_url:
          type: string
          format: uri
          description: >-
            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/swml-webhook/webhooks/inbound-call-webhook)
            or [SWML inbound message
            webhook](/docs/apis/rest/swml-webhook/webhooks/inbound-message-webhook)
            depending on `used_for`.
        fallback_request_method:
          $ref: '#/components/schemas/RequestUrlMethodType'
          default: POST
          description: Fallback request method of the SWML Webhook.
        status_callback_url:
          type: string
          format: uri
          description: >-
            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/messages/webhooks/message-status-callback)
            webhook for the payload your URL will receive.
        status_callback_method:
          $ref: '#/components/schemas/RequestUrlMethodType'
          default: POST
          description: Status callback method of the SWML Webhook.
      required:
        - primary_request_url
      title: SWMLWebhookCreateRequest
    uuid:
      type: string
      format: uuid
      description: Universal Unique Identifier.
      title: uuid
    SwmlWebhookResponseType:
      type: string
      enum:
        - swml_webhook
      description: Type of the Fabric Resource
      title: SwmlWebhookResponseType
    SwmlWebhookUsedFor:
      type: string
      enum:
        - calling
        - messaging
      description: >-
        Indicates whether this SWML Webhook handles inbound calls or inbound
        messages. Determines the payload SignalWire POSTs to
        `primary_request_url`.
      title: SwmlWebhookUsedFor
    SWMLWebhook:
      type: object
      properties:
        id:
          $ref: '#/components/schemas/uuid'
          description: Unique ID of the SWML Webhook.
        name:
          type: string
          description: Name of the SWML Webhook.
        used_for:
          $ref: '#/components/schemas/SwmlWebhookUsedFor'
          description: >-
            Indicates whether this SWML Webhook handles inbound calls or inbound
            messages. Determines the payload SignalWire POSTs to
            `primary_request_url`.
        primary_request_url:
          type: string
          format: uri
          description: >-
            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/swml-webhook/webhooks/inbound-call-webhook);
            for `messaging`, see the [SWML inbound message
            webhook](/docs/apis/rest/swml-webhook/webhooks/inbound-message-webhook).
        primary_request_method:
          $ref: '#/components/schemas/RequestUrlMethodType'
          description: Primary request method of the SWML Webhook.
        fallback_request_url:
          type:
            - string
            - 'null'
          format: uri
          description: >-
            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/swml-webhook/webhooks/inbound-call-webhook)
            or [SWML inbound message
            webhook](/docs/apis/rest/swml-webhook/webhooks/inbound-message-webhook)
            depending on `used_for`.
        fallback_request_method:
          $ref: '#/components/schemas/RequestUrlMethodType'
          description: Fallback request method of the SWML Webhook.
        status_callback_url:
          type:
            - string
            - 'null'
          format: uri
          description: >-
            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/messages/webhooks/message-status-callback)
            webhook for the payload your URL will receive.
        status_callback_method:
          $ref: '#/components/schemas/RequestUrlMethodType'
          description: Status callback method of the SWML Webhook.
      required:
        - id
        - name
        - used_for
        - primary_request_url
        - primary_request_method
        - fallback_request_url
        - fallback_request_method
        - status_callback_url
        - status_callback_method
      title: SWMLWebhook
    SWMLWebhookResponse:
      type: object
      properties:
        id:
          $ref: '#/components/schemas/uuid'
          description: Unique ID of the SWML Webhook.
        project_id:
          $ref: '#/components/schemas/uuid'
          description: Unique ID of the Project.
        display_name:
          type: string
          description: Display name of the SWML Webhook Fabric Resource
        type:
          $ref: '#/components/schemas/SwmlWebhookResponseType'
          description: Type of the Fabric Resource
        created_at:
          type: string
          format: date-time
          description: Date and time when the resource was created.
        updated_at:
          type: string
          format: date-time
          description: Date and time when the resource was updated.
        swml_webhook:
          $ref: '#/components/schemas/SWMLWebhook'
          description: SWML Webhook data.
      required:
        - id
        - project_id
        - display_name
        - type
        - created_at
        - updated_at
        - swml_webhook
      title: SWMLWebhookResponse
    TypesStatusCodesStatusCode401Error:
      type: string
      enum:
        - Unauthorized
      title: TypesStatusCodesStatusCode401Error
    Types.StatusCodes.StatusCode401:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/TypesStatusCodesStatusCode401Error'
      required:
        - error
      description: Access is unauthorized.
      title: Types.StatusCodes.StatusCode401
    TypesStatusCodesStatusCode404Error:
      type: string
      enum:
        - Not Found
      title: TypesStatusCodesStatusCode404Error
    Types.StatusCodes.StatusCode404:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/TypesStatusCodesStatusCode404Error'
      required:
        - error
      description: The server cannot find the requested resource.
      title: Types.StatusCodes.StatusCode404
    Types.StatusCodes.RestApiErrorItem:
      type: object
      properties:
        type:
          type: string
          description: The category of error.
        code:
          type: string
          description: A specific error code.
        message:
          type: string
          description: A description of what caused the error.
        attribute:
          type:
            - string
            - 'null'
          description: The request parameter that caused the error, if applicable.
        url:
          type: string
          description: A link to documentation about this error.
      required:
        - type
        - code
        - message
        - url
      description: Details about a specific error.
      title: Types.StatusCodes.RestApiErrorItem
    SwmlWebhookCreateStatusCode422:
      type: object
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/Types.StatusCodes.RestApiErrorItem'
          description: List of validation errors.
      required:
        - errors
      description: The request contains invalid parameters. See errors for details.
      title: SwmlWebhookCreateStatusCode422
    TypesStatusCodesStatusCode500Error:
      type: string
      enum:
        - Internal Server Error
      title: TypesStatusCodesStatusCode500Error
    Types.StatusCodes.StatusCode500:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/TypesStatusCodesStatusCode500Error'
      required:
        - error
      description: An internal server error occurred.
      title: Types.StatusCodes.StatusCode500

```

## **Response Example**

### Response (201)

```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"
  }
}
```

## **Example**

```typescript {9}
import { RestClient } from "@signalwire/sdk";

const client = new RestClient({
  project: "your-project-id",
  token: "your-api-token",
  host: "your-space.signalwire.com",
});

const result = await client.fabric.swmlWebhooks.create({
  name: "my-webhook",
  primary_request_url: "https://example.com/swml",
});
console.log("Created:", result.id);
```