# 创建和更新

这些端点用于创建和编辑 Journey 定义：其标题、设置以及画布上的点。它们不会启动 Journey。要启动 Journey，请使用 [生命周期](/zh/developer/api-reference/customer-journey-api/lifecycle/)。

两者都接受并返回 [Journey 对象](/zh/developer/api-reference/customer-journey-api/journey-object/)。

<Aside type="tip">
在 JSON 中编写完整的 Journey 图谱很困难。每个点都有自己的渠道字段和条件 ([点参考](/zh/developer/api-reference/customer-journey-api/point-reference/))。最可靠的工作流程是在 [Customer Journey 构建器](/zh/product/customer-journey/pushwoosh-journey-overview/) 中构建一次 Journey，从创建/更新响应中读回它，然后使用这些端点以编程方式克隆或调整它。
</Aside>

## 创建

`POST` `https://journey.pushwoosh.com/api/v3/journeygateway`

创建一个处于 `STATUS_DRAFT` 状态的新 Journey。

### 请求

| 字段 | 必需 | 类型 | 描述 |
|---|---|---|---|
| `title` | 是 | string | Journey 名称。 |
| `params` | 是 | [`JourneyParams`](/zh/developer/api-reference/customer-journey-api/journey-object/#journeyparams) | Journey 范围的配置。`params.application_code` 是必需的。 |
| `points` | 否 | array of [`Point`](/zh/developer/api-reference/customer-journey-api/journey-object/#point) | 画布上的 Journey 元素及其连接。 |
| `comments` | 否 | array of [`JourneyComment`](/zh/developer/api-reference/customer-journey-api/journey-object/#journeycomment) | 画布评论。 |

##### 请求示例
```bash title="创建一个 Journey"
curl -X POST https://journey.pushwoosh.com/api/v3/journeygateway \
  -H "Authorization: Api YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Welcome series",
    "params": { "application_code": "XXXXX-XXXXX" },
    "points": [],
    "comments": []
  }'
```

### 响应

返回新的 [Journey 对象](/zh/developer/api-reference/customer-journey-api/journey-object/)。从 `info.uuid` 中读取 Journey 的 UUID，并将其用于后续的更新和生命周期调用。
##### 响应示例
```json
{
  "info": {
    "uuid": "11111111-2222-3333-4444-555555555555",
    "title": "Welcome series",
    "status": "STATUS_DRAFT",
    "params": { "application_code": "XXXXX-XXXXX" }
  },
  "points": [],
  "comments": []
}
```

## 完整 Journey 示例

一个小型欢迎流程的完整 `Create` 主体。图谱如下：

```
Start by segment ──default──▶ Send push ──default──▶ Wait 1 day ──default──▶ Boolean splitter ──output1──▶ Send email ──default──▶ Exit
                                                                                              └──default───────────────────────────▶ Exit
```

点通过每个输出的 `info.next_point_uuid` 连接在一起。请注意 [输出键](/zh/developer/api-reference/customer-journey-api/journey-object/#output-keys)：每个点都使用 `default`，除了布尔分割器，它为匹配条件的分支添加了 `output1`（`default` 是其备用选项）。退出点没有输出。

```json
{
  "title": "Welcome series",
  "params": {
    "application_code": "XXXXX-XXXXX",
    "user_id_track_change_policy": "TRACK"
  },
  "points": [
    {
      "uuid": "11111111-1111-1111-1111-111111111111",
      "title": "New signups",
      "point_type": "POINT_TYPE_START_BY_SEGMENT",
      "position": { "x": 80, "y": 200 },
      "outputs": [
        { "identity": { "key": "default", "order": 0 },
          "info": { "title": "", "next_point_uuid": "22222222-2222-2222-2222-222222222222" } }
      ],
      "point_data": {
        "start_by_segment": {
          "application_code": "XXXXX-XXXXX",
          "filter_code": "AAAAA-BBBBB"
        }
      }
    },
    {
      "uuid": "22222222-2222-2222-2222-222222222222",
      "title": "Welcome push",
      "point_type": "POINT_TYPE_SEND_PUSH",
      "position": { "x": 340, "y": 200 },
      "outputs": [
        { "identity": { "key": "default", "order": 0 },
          "info": { "title": "", "next_point_uuid": "33333333-3333-3333-3333-333333333333" } }
      ],
      "point_data": {
        "send_push": {
          "application_code": "XXXXX-XXXXX",
          "title": "Welcome!",
          "content": "Thanks for joining — here's how to get started."
        }
      }
    },
    {
      "uuid": "33333333-3333-3333-3333-333333333333",
      "title": "Wait 1 day",
      "point_type": "POINT_TYPE_WAIT",
      "position": { "x": 600, "y": 200 },
      "outputs": [
        { "identity": { "key": "default", "order": 0 },
          "info": { "title": "", "next_point_uuid": "44444444-4444-4444-4444-444444444444" } }
      ],
      "point_data": {
        "delay": { "sec": 86400 }
      }
    },
    {
      "uuid": "44444444-4444-4444-4444-444444444444",
      "title": "Opened the push?",
      "point_type": "POINT_TYPE_BOOLEAN_SPLITTER",
      "position": { "x": 860, "y": 200 },
      "outputs": [
        { "identity": { "key": "output1", "order": 1 },
          "info": { "title": "Matched", "next_point_uuid": "55555555-5555-5555-5555-555555555555" } },
        { "identity": { "key": "default", "order": 0 },
          "info": { "title": "Everyone else", "next_point_uuid": "66666666-6666-6666-6666-666666666666" } }
      ],
      "point_data": {
        "boolean_splitter": {
          "application_code": "XXXXX-XXXXX",
          "split_strategy": "SPLIT_FILTER",
          "load_policy": "ALL",
          "filter_code": "CCCCC-DDDDD"
        }
      }
    },
    {
      "uuid": "55555555-5555-5555-5555-555555555555",
      "title": "Follow-up email",
      "point_type": "POINT_TYPE_SEND_EMAIL",
      "position": { "x": 1120, "y": 120 },
      "outputs": [
        { "identity": { "key": "default", "order": 0 },
          "info": { "title": "", "next_point_uuid": "66666666-6666-6666-6666-666666666666" } }
      ],
      "point_data": {
        "send_email": {
          "application_code": "XXXXX-XXXXX",
          "preset_code": "12345-67890"
        }
      }
    },
    {
      "uuid": "66666666-6666-6666-6666-666666666666",
      "title": "Exit",
      "point_type": "POINT_TYPE_EXIT",
      "position": { "x": 1380, "y": 200 },
      "outputs": [],
      "point_data": {
        "terminator": {}
      }
    }
  ],
  "comments": []
}
```

## 更新

`PUT` `https://journey.pushwoosh.com/api/v3/journeygateway/{uuid}`

替换现有 Journey 的定义。发送 **完整** 的定义。您提交的点和评论将替换当前的。

### 路径参数

| 名称 | 类型 | 描述 |
|---|---|---|
| `uuid` | string | 要更新的 [Journey ID](/zh/developer/api-reference/api-identifiers/#journey-id)。 |

### 请求

| 字段 | 类型 | 描述 |
|---|---|---|
| `title` | string | 新的 Journey 名称。 |
| `params` | [`JourneyParams`](/zh/developer/api-reference/customer-journey-api/journey-object/#journeyparams) | 新的 Journey 范围配置。 |
| `points` | array of [`Point`](/zh/developer/api-reference/customer-journey-api/journey-object/#point) | 新的完整点集。 |
| `comments` | array of [`JourneyComment`](/zh/developer/api-reference/customer-journey-api/journey-object/#journeycomment) | 新的完整评论集。 |
| `autosave` | bool | 当为 `true` 时，此更改被视作编辑器自动保存。默认为 `false`。 |

##### 请求示例 

```bash title="重命名并重新配置 Journey"
curl -X PUT https://journey.pushwoosh.com/api/v3/journeygateway/11111111-2222-3333-4444-555555555555 \
  -H "Authorization: Api YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Welcome series v2",
    "params": { "application_code": "XXXXX-XXXXX" },
    "points": [],
    "comments": []
  }'
```

### 响应

返回更新后的 [Journey 对象](/zh/developer/api-reference/customer-journey-api/journey-object/)。

## 更新并恢复

`POST` `https://journey.pushwoosh.com/api/v3/journeygateway/{uuid}/resume`

在单次调用中将编辑应用于 Journey 并恢复它。这相当于一个 [更新](#update) 调用，后跟一个生命周期 [启动](/zh/developer/api-reference/customer-journey-api/lifecycle/) 调用。请求主体与 [更新](#update) 匹配。当您编辑一个已暂停的 Journey 并希望将其恢复到 `STATUS_RUNNING` 状态时，请使用此方法。

## 重命名

`POST` `https://journey.pushwoosh.com/api/v3/journeygateway/{uuid}/rename`

仅更改 Journey 标题，不触及其点或设置。

| 字段 | 必需 | 类型 | 描述 |
|---|---|---|---|
| `title` | 是 | string | 新的 Journey 名称。 |

##### 请求示例

```bash title="重命名 Journey"
curl -X POST https://journey.pushwoosh.com/api/v3/journeygateway/11111111-2222-3333-4444-555555555555/rename \
  -H "Authorization: Api YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "title": "Welcome series (Q3)" }'
```

## 相关内容

<CardGrid>
  <LinkCard title="Journey 对象" href="/developer/api-reference/customer-journey-api/journey-object/" />
  <LinkCard title="生命周期" href="/developer/api-reference/customer-journey-api/lifecycle/" />
  <LinkCard title="通过 API 启动" href="/developer/api-reference/customer-journey-api/start-by-api/" />
</CardGrid>