# Create workflow

> Create a workflow from a template or a plan. It is saved as a draft.

Source: https://docs.mycrmsim.com/docs/automations/create-workflow

```http
POST https://backend.mysmsgateway.app/api/v1/ext/workflows
```

- Category: myCRMSIM Automations / Automations
- Auth: Bearer access token
- Scope: `automations.write`

Send either `template_id` (a copy of one of your templates) or `plan` (see Validate a plan), not both. A plan is validated first; if it has problems nothing is created and the issues come back (400 `INVALID_PLAN`).

The new workflow is always a **draft**: it does not run and messages nobody until you activate it (Activate workflow).

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `workspace_id` | body | number | yes | A workspace of the installer. Example: `7` |
| `template_id` | body | number | no | A template from List workflow templates. |
| `plan` | body | object | no | A plan: `{ steps: [...], envelope?: {...} }`. |
| `name` | body | string | no | Default: the plan's `envelope.name`, or "<template name> (copy)". |
| `stop_on_reply` | body | boolean | no | A contact who replies leaves the workflow. |
| `allow_re_entry` | body | boolean | no | A contact who finished can start it again. |
| `execution_window` | body | object \| null | no | Only send between these hours: `{ "enabled": true, "timezone": "Australia/Sydney", "start_time": "09:00", "end_time": "18:00", "skip_weekends": true }`. `null` (or `enabled: false`) turns it off. |

## Request body

```json
{
  "workspace_id": 7,
  "plan": {
    "steps": [
      {
        "name": "contactCreated",
        "type": "contactCreated",
        "next": "welcome"
      },
      {
        "name": "welcome",
        "type": "sendSMS",
        "data": {
          "message": "Hi {{contact.first_name}}, thanks for signing up!"
        },
        "next": "wait1"
      },
      {
        "name": "wait1",
        "type": "wait",
        "data": {
          "waitType": "duration",
          "delay": 86400000,
          "delayValue": 1,
          "delayUnit": "days"
        },
        "next": "tag"
      },
      {
        "name": "tag",
        "type": "addTag",
        "data": {
          "tags": [
            "welcomed"
          ]
        },
        "next": null
      }
    ],
    "envelope": {
      "name": "Welcome new contacts",
      "stopOnReply": true
    }
  },
  "execution_window": {
    "enabled": true,
    "timezone": "Australia/Sydney",
    "start_time": "09:00",
    "end_time": "18:00",
    "skip_weekends": true
  }
}
```

## Response fields (workflow)

| Field | Type | Description |
| --- | --- | --- |
| `id` | number | Workflow id. |
| `name` | string | Workflow name. |
| `status` | string | `draft` (not running) or `active` (running). |
| `workspace_id` | number | The workspace it runs in. |
| `stop_on_reply` | boolean | A contact who replies leaves the workflow. |
| `allow_re_entry` | boolean | A contact who finished can start it again. |
| `execution_window` | object | The hours it may send in: `enabled`, `timezone`, `start_time`, `end_time`, `skip_weekends`. |
| `step_count` | number | How many steps (canvas nodes) it has, the trigger included. |
| `nodes` | array<object> | The steps as the canvas stores them (`id`, `type`, `data`, `position`). Get and create only. |
| `edges` | array<object> | The connections between steps (`source`, `target`, `sourceHandle`). Get and create only. |
| `created_at` | string (ISO 8601) | Created. |
| `updated_at` | string (ISO 8601) | Last saved. |

## Response 201

Created (draft)

```json
{
  "success": true,
  "message": "Workflow created as a draft. It runs once activated (POST /workflows/{id}/activate).",
  "data": {
    "id": 1201,
    "name": "Welcome new contacts",
    "status": "draft",
    "workspace_id": 7,
    "stop_on_reply": true,
    "allow_re_entry": true,
    "execution_window": {
      "enabled": true,
      "timezone": "Australia/Sydney",
      "start_time": "09:00",
      "end_time": "18:00",
      "skip_weekends": true
    },
    "step_count": 4,
    "nodes": [
      {
        "id": "contactCreated",
        "type": "contactCreated",
        "position": {
          "x": 0,
          "y": 0
        },
        "data": {
          "note": ""
        }
      },
      {
        "id": "welcome",
        "type": "sendSMS",
        "position": {
          "x": 0,
          "y": 220
        },
        "data": {
          "phone": "{{contact.number}}",
          "message": "Hi {{contact.first_name}}, thanks for signing up!"
        }
      },
      {
        "id": "wait1",
        "type": "wait",
        "position": {
          "x": 0,
          "y": 440
        },
        "data": {
          "waitType": "duration",
          "delay": 86400000,
          "delayValue": 1,
          "delayUnit": "days"
        }
      },
      {
        "id": "tag",
        "type": "addTag",
        "position": {
          "x": 0,
          "y": 660
        },
        "data": {
          "tags": [
            "welcomed"
          ]
        }
      }
    ],
    "edges": [
      {
        "id": "e-contactCreated-welcome",
        "source": "contactCreated",
        "target": "welcome",
        "sourceHandle": "out"
      },
      {
        "id": "e-welcome-wait1",
        "source": "welcome",
        "target": "wait1",
        "sourceHandle": "out"
      },
      {
        "id": "e-wait1-tag",
        "source": "wait1",
        "target": "tag",
        "sourceHandle": "out"
      }
    ],
    "created_at": "2026-10-28T09:00:00.000Z",
    "updated_at": "2026-10-28T09:00:00.000Z"
  }
}
```

## Response 400

The plan has problems; nothing was created

```json
{
  "success": false,
  "code": "INVALID_PLAN",
  "message": "The plan has 1 problem(s); nothing was created.",
  "issues": [
    {
      "step": "welcome",
      "type": "sendSMS",
      "message": "The SMS message is empty."
    }
  ]
}
```

## Response 400

Neither or both of template_id and plan

```json
{
  "success": false,
  "message": "Send either template_id or plan (not both)"
}
```

## Response 401

Missing or invalid token

```json
{
  "success": false,
  "message": "Invalid or expired access token."
}
```

## Response 403

Missing scope

```json
{
  "success": false,
  "message": "Missing scope(s): automations.write. This integration was granted: …"
}
```

## Response 404

workspace_id does not exist or is not the installer's (same response for both)

```json
{
  "success": false,
  "message": "Workspace not found or not accessible to this token"
}
```

## Response 404

The template is not the installer's

```json
{
  "success": false,
  "message": "Template not found or not accessible to this token"
}
```
