---
title: "Create SWML Script"
method: POST
path: "/api/fabric/resources/swml_scripts"
tags: ["SWML Scripts"]
---

# Create SWML Script

`POST /api/fabric/resources/swml_scripts`

Creates a SWML Script

#### 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).

## Request body

- union — Body shape for creating a SWML Script. Choose a [Calling Script](#schema/CallingSwmlScriptCreateRequest) for inbound or outbound calls or a [Messaging Script](#schema/MessagingSwmlScriptCreateRequest) for inbound SMS or MMS messages. `script_type` is optional and defaults to `"calling"` when omitted — set it explicitly to `"messaging"` to create a Messaging Script. The script kind determines whether the script can be assigned as a call handler or a message handler on a phone number.
  - CallingSwmlScriptCreateRequest — Request body to create a SWML Script that handles inbound or outbound calls.
    - `name` string, required — Display name of the SWML Script
    - `script_type` 'calling' — Set to `calling` for a Calling Script. This is the default when `script_type` is omitted.
    - `contents` SWMLCallingSWMLObject, required — A SWML document for handling inbound and outbound calls. Contains a `sections` map where each section holds an array of methods that run sequentially. Execution starts at `sections.main`. See the [Calling SWML reference](/docs/swml/reference/calling) for the full list of available methods.
      - `version` '1.0.0'
      - `sections` SWMLCallingSection, required
        - `main` SWMLCallingSWMLMethod[], required
          - union
            - SWMLCallingAnswer
              - …
            - SWMLCallingAI
              - …
            - SWMLCallingAISidecar
              - …
            - SWMLCallingAmazonBedrock
              - …
            - SWMLCallingCond
              - …
            - SWMLCallingConnect
              - …
            - SWMLCallingDenoise
              - …
            - SWMLCallingEnterQueue
              - …
            - SWMLCallingExecute
              - …
            - SWMLCallingGoto
              - …
            - SWMLCallingLabel
              - …
            - SWMLCallingLiveTranscribe
              - …
            - SWMLCallingLiveTranslate
              - …
            - SWMLCallingHangup
              - …
            - SWMLCallingJoinRoom
              - …
            - SWMLCallingJoinConference
              - …
            - SWMLCallingPlay
              - …
            - SWMLCallingPrompt
              - …
            - SWMLCallingReceiveFax
              - …
            - SWMLCallingRecord
              - …
            - SWMLCallingRecordCall
              - …
            - SWMLCallingRequest
              - …
            - SWMLCallingReturn
              - …
            - SWMLCallingSendDigits
              - …
            - SWMLCallingSendFax
              - …
            - SWMLCallingSendSMS
              - …
            - SWMLCallingSet
              - …
            - SWMLCallingSleep
              - …
            - SWMLCallingSIPRefer
              - …
            - SWMLCallingStopDenoise
              - …
            - SWMLCallingStopRecordCall
              - …
            - SWMLCallingStopStream
              - …
            - SWMLCallingStopTap
              - …
            - SWMLCallingStream
              - …
            - SWMLCallingSwitch
              - …
            - SWMLCallingTap
              - …
            - SWMLCallingTranscribe
              - …
            - SWMLCallingTranscribeStop
              - …
            - SWMLCallingTransfer
              - …
            - SWMLCallingUnset
              - …
            - SWMLCallingPay
              - …
            - SWMLCallingDetectMachine
              - …
            - SWMLCallingUserEvent
              - …
    - `status_callback_url` string, uri — URL that receives status callbacks for messages sent or calls made by this script.
  - MessagingSwmlScriptCreateRequest — Request body to create a SWML Script that handles inbound SMS or MMS messages.
    - `name` string, required — Display name of the SWML Script
    - `script_type` 'messaging' — Set to `messaging` to create a Messaging Script. If omitted, the API defaults to `calling`, so this field must be set explicitly for messaging scripts.
    - `contents` SWMLMessagingSWMLObject, required — A SWML document for handling inbound SMS or MMS messages. The document has a top-level `sections` map; execution starts at `sections.main`, and each section is an ordered array of methods. Additional sections can be invoked via `execute`, `transfer`, or `goto`. See the [Messaging SWML reference](/docs/swml/reference/messaging) for the full list of available methods.
      - `version` '1.0.0'
      - `sections` SWMLMessagingSection, required
        - `main` SWMLMessagingSWMLMethod[], required
          - union
            - SWMLMessagingReply
              - …
            - SWMLMessagingReceive
              - …
            - SWMLMessagingRequest
              - …
            - SWMLMessagingExecute
              - …
            - SWMLMessagingTransfer
              - …
            - SWMLMessagingSwitch
              - …
            - SWMLMessagingGoto
              - …
            - SWMLMessagingReturn
              - …
            - SWMLMessagingLabel
              - …

## Response `200`

The request has succeeded.

- SwmlScriptResponse
  - `id` string, uuid, required — Universal Unique Identifier.
  - `project_id` string, uuid, required — Universal Unique Identifier.
  - `display_name` string, required — Display name of the SWML Script Fabric Resource
  - `type` 'swml_script', required — Type of the Fabric Resource
  - `created_at` string, date-time, required — Date and time when the resource was created.
  - `updated_at` string, date-time, required — Date and time when the resource was updated.
  - `swml_script` union, required — A SWML Script — either a [Calling Script](#schema/CallingSwmlScript) for inbound or outbound calls, or a [Messaging Script](#schema/MessagingSwmlScript) for inbound SMS or MMS messages. The `script_type` field on each script (`"calling"` or `"messaging"`) identifies which kind it is.
    - CallingSwmlScript — A SWML Script that handles inbound or outbound calls. The `contents` field carries a [calling SWML document](/docs/swml/reference/calling).
      - `id` string, uuid, required — Universal Unique Identifier.
      - `display_name` string, required — The displayed name of the SWML script.
      - `script_type` 'calling', required — Set to `calling` for SWML Scripts that handle inbound or outbound calls.
      - `request_url` string, uri, required — URL where this SWML Script is hosted.
      - `contents` SWMLCallingSWMLObject, required — A SWML document for handling inbound and outbound calls. Contains a `sections` map where each section holds an array of methods that run sequentially. Execution starts at `sections.main`. See the [Calling SWML reference](/docs/swml/reference/calling) for the full list of available methods.
        - `version` '1.0.0'
        - `sections` SWMLCallingSection, required
          - `main` SWMLCallingSWMLMethod[], required
            - union
              - …
      - `status_callback_url` string, uri — URL that receives status callbacks for messages sent or calls made by this script.
      - `status_callback_method` 'POST' — HTTP method used for status callbacks.
    - MessagingSwmlScript — A SWML Script that handles inbound SMS or MMS messages. The `contents` field carries a [messaging SWML document](/docs/swml/reference/messaging).
      - `id` string, uuid, required — Universal Unique Identifier.
      - `display_name` string, required — The displayed name of the SWML script.
      - `script_type` 'messaging', required — Set to `messaging` for SWML Scripts that handle inbound SMS or MMS messages.
      - `request_url` string, uri, required — URL where this SWML Script is hosted.
      - `contents` SWMLMessagingSWMLObject, required — A SWML document for handling inbound SMS or MMS messages. The document has a top-level `sections` map; execution starts at `sections.main`, and each section is an ordered array of methods. Additional sections can be invoked via `execute`, `transfer`, or `goto`. See the [Messaging SWML reference](/docs/swml/reference/messaging) for the full list of available methods.
        - `version` '1.0.0'
        - `sections` SWMLMessagingSection, required
          - `main` SWMLMessagingSWMLMethod[], required
            - union
              - …

## Other responses

- `401` — Access is unauthorized.
- `404` — The server cannot find the requested resource.
- `422` — The request contains invalid parameters. See errors for details.
- `500` — An internal server error occurred.

---

[API](https://skmtc.net/signalwire/apis/signalwire-rest-api.md) · [All operations](https://skmtc.net/signalwire/apis/signalwire-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/signalwire/signalwire-rest-api/versions/05c5164b85c7/schema)
