# สร้างและอัปเดต

endpoints เหล่านี้ใช้สร้างและแก้ไขคำจำกัดความของ journey: ชื่อ, การตั้งค่า, และจุดต่างๆ บน canvas แต่ไม่ได้ใช้เริ่ม journey หากต้องการเริ่ม journey ให้ใช้ [Lifecycle](/th/developer/api-reference/customer-journey-api/lifecycle/)

ทั้งสอง endpoint รับและส่งคืน [อ็อบเจกต์ Journey](/th/developer/api-reference/customer-journey-api/journey-object/)

<Aside type="tip">
การเขียนกราฟ journey ทั้งหมดในรูปแบบ JSON นั้นทำได้ยาก แต่ละจุดมีฟิลด์และเงื่อนไขของช่องทางของตัวเอง ([การอ้างอิง Point](/th/developer/api-reference/customer-journey-api/point-reference/)) เวิร์กโฟลว์ที่น่าเชื่อถือที่สุดคือการสร้าง journey หนึ่งครั้งใน [เครื่องมือสร้าง Customer Journey](/th/product/customer-journey/pushwoosh-journey-overview/) อ่านข้อมูลกลับมาจากการตอบกลับของการสร้าง/อัปเดต จากนั้นใช้ endpoints เหล่านี้เพื่อโคลนหรือปรับเปลี่ยนผ่านโปรแกรม
</Aside>

## สร้าง

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

สร้าง journey ใหม่ในสถานะ `STATUS_DRAFT`

### คำขอ

| ฟิลด์ | จำเป็น | ประเภท | คำอธิบาย |
|---|---|---|---|
| `title` | ใช่ | string | ชื่อ Journey |
| `params` | ใช่ | [`JourneyParams`](/th/developer/api-reference/customer-journey-api/journey-object/#journeyparams) | การกำหนดค่าทั่วทั้ง Journey จำเป็นต้องมี `params.application_code` |
| `points` | ไม่ | อาร์เรย์ของ [`Point`](/th/developer/api-reference/customer-journey-api/journey-object/#point) | องค์ประกอบ Journey บน canvas และการเชื่อมต่อ |
| `comments` | ไม่ | อาร์เรย์ของ [`JourneyComment`](/th/developer/api-reference/customer-journey-api/journey-object/#journeycomment) | ความคิดเห็นบน Canvas |

##### ตัวอย่างคำขอ
```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](/th/developer/api-reference/customer-journey-api/journey-object/) ใหม่ อ่าน UUID ของ journey จาก `info.uuid` และใช้สำหรับเรียกการอัปเดตและ lifecycle ในครั้งต่อไป
##### ตัวอย่างการตอบกลับ
```json
{
  "info": {
    "uuid": "11111111-2222-3333-4444-555555555555",
    "title": "Welcome series",
    "status": "STATUS_DRAFT",
    "params": { "application_code": "XXXXX-XXXXX" }
  },
  "points": [],
  "comments": []
}
```

## ตัวอย่าง journey แบบเต็ม

body ของ `Create` ที่สมบูรณ์สำหรับ welcome flow ขนาดเล็ก กราฟคือ:

```
เริ่มตาม segment ──default──▶ ส่ง push ──default──▶ รอ 1 วัน ──default──▶ ตัวแยก Boolean ──output1──▶ ส่งอีเมล ──default──▶ ออก
                                                                                              └──default───────────────────────────▶ ออก
```

Points จะถูกเชื่อมต่อกันผ่าน `info.next_point_uuid` ของแต่ละ output สังเกต [คีย์ของ output](/th/developer/api-reference/customer-journey-api/journey-object/#output-keys): ทุก point ใช้ `default` ยกเว้นตัวแยก boolean ซึ่งจะเพิ่ม `output1` สำหรับสาขาที่เงื่อนไขตรงกัน (`default` เป็นทางเลือกสำรอง) ส่วน point ทางออกจะไม่มี output

```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 ที่มีอยู่ ส่งคำจำกัดความที่ **สมบูรณ์** points และ comments ที่คุณส่งจะแทนที่ของเดิม

### พารามิเตอร์ของ Path

| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
| `uuid` | string | [Journey ID](/th/developer/api-reference/api-identifiers/#journey-id) ที่จะอัปเดต |

### คำขอ

| ฟิลด์ | ประเภท | คำอธิบาย |
|---|---|---|
| `title` | string | ชื่อ journey ใหม่ |
| `params` | [`JourneyParams`](/th/developer/api-reference/customer-journey-api/journey-object/#journeyparams) | การกำหนดค่าทั่วทั้ง journey ใหม่ |
| `points` | อาร์เรย์ของ [`Point`](/th/developer/api-reference/customer-journey-api/journey-object/#point) | ชุด points ใหม่ทั้งหมด |
| `comments` | อาร์เรย์ของ [`JourneyComment`](/th/developer/api-reference/customer-journey-api/journey-object/#journeycomment) | ชุด comments ใหม่ทั้งหมด |
| `autosave` | bool | เมื่อเป็น `true`, การเปลี่ยนแปลงจะถือเป็นการบันทึกอัตโนมัติของ editor ค่าเริ่มต้นคือ `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](/th/developer/api-reference/customer-journey-api/journey-object/) ที่อัปเดตแล้ว

## อัปเดตและดำเนินการต่อ

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

ใช้การแก้ไขกับ journey และดำเนินการต่อในการเรียกครั้งเดียว ซึ่งเทียบเท่ากับการ [อัปเดต](#update) ตามด้วย lifecycle [Start](/th/developer/api-reference/customer-journey-api/lifecycle/) body ของคำขอจะเหมือนกับ [อัปเดต](#update) ใช้คำสั่งนี้เมื่อแก้ไข journey ที่หยุดชั่วคราวและต้องการให้กลับสู่สถานะ `STATUS_RUNNING`

## เปลี่ยนชื่อ

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

เปลี่ยนเฉพาะชื่อ journey โดยไม่แตะต้อง points หรือการตั้งค่า

| ฟิลด์ | จำเป็น | ประเภท | คำอธิบาย |
|---|---|---|---|
| `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="Lifecycle" href="/developer/api-reference/customer-journey-api/lifecycle/" />
  <LinkCard title="เริ่มโดย API" href="/developer/api-reference/customer-journey-api/start-by-api/" />
</CardGrid>