# Create Or Update Case

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /v2/cases:
    post:
      summary: Create Or Update Case
      deprecated: false
      description: >-
        สร้าง หรือ แก้ไข ข้อมูลเคส โดยเมื่อส่งรหัสเคสจะเป็นการสร้างเคส
        ถ้าไม่ส่งรหัสเคสจะเป็นการสร้างเคสพร้อมกับสร้างรหัสเคสให้
      tags:
        - Venio/Case Management
      parameters:
        - name: Content-Type
          in: header
          description: ''
          required: true
          example: application/json
          schema:
            type: string
        - name: Ocp-Apim-Subscription-Key
          in: header
          description: รหัส subscription key ลูกค้า
          required: true
          example: <Your Subscription-Key>
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                caseNo:
                  type: string
                  description: |-
                    รหัสเคส
                    ไม่ส่งรหัสเคส = สร้างเคสใหม่
                    ส่งรหัสเคส = อัปเดตเคสตามรหัสเคส
                  nullable: true
                subject:
                  type: string
                  description: หัวข้อเคส
                description:
                  type: string
                  description: รายละเอียดเคส
                categoryId:
                  type: integer
                  description: รหัสหมวดหมู่เคส (จาก GET v2/cases/categories)
                customerCode:
                  type: string
                  description: รหัสลูกค้า
                  nullable: true
                dateCase:
                  type: string
                  description: |-
                    วันที่เกิดเคส
                    Format (YYYY-MM-DDTHH:MM:SS)
                    ตัวอย่าง 2026-06-01T01:00:00
                    ระบบจะบันทึกเวลาเป็น UTC+7 (เวลาตามประเทศไทย)
                dateDue:
                  type: string
                  description: |-
                    วันกำหนดเสร็จ
                    Format (YYYY-MM-DDTHH:MM:SS)
                    ตัวอย่าง 2026-06-01T23:00:00
                    ระบบจะบันทึกเวลาเป็น UTC+7 (เวลาตามประเทศไทย)
                stageId:
                  type: integer
                  description: >-
                    รหัสขั้นตอน

                    (กรณีสร้าง) ไม่ส่งรหัสขั้นตอน = สร้างเคสในขั้นตอน ใหม่

                    ส่งรหัสขั้นตอน  = สร้าง/แก้ไขเคสให้อยู่ขั้นตอนที่ต้องการ
                    (จาก GET v2/cases/stages)
                  nullable: true
                caseTag:
                  type: array
                  items:
                    type: string
                  description: |-
                    แท็ก
                    (กรณีแก้ไข) [] = ล้างทั้งหมด,ไม่ส่ง = ไม่เปลี่ยน
                  nullable: true
                activityNo:
                  type: string
                  description: รหัสกิจกรรมที่เชื่อมต่อ
                  nullable: true
                dealNo:
                  type: string
                  description: รหัสดีลที่เชื่อมต่อ
                  nullable: true
                chatId:
                  type: string
                  description: |-
                    รหัสห้องแช็ตที่เชื่อมต่อ 
                    ตัวอย่าง 00000000-0000-0000-0000-000000000000
                  nullable: true
                owner:
                  type: string
                  description: staffCode เจ้าของเคส
                participants:
                  type: array
                  items:
                    type: string
                    description: staffCode
                  description: |-
                    staffCode ผู้เข้าร่วม
                    (กรณีแก้ไข) ไม่ส่ง = ไม่เปลี่ยน
                  nullable: true
              x-apidog-orders:
                - caseNo
                - subject
                - description
                - categoryId
                - customerCode
                - dateCase
                - dateDue
                - stageId
                - caseTag
                - activityNo
                - dealNo
                - chatId
                - owner
                - participants
              required:
                - subject
                - description
                - categoryId
                - dateCase
                - dateDue
                - owner
              x-apidog-ignore-properties: []
            examples:
              '1':
                value:
                  caseNo: null
                  subject: Subject
                  description: Description
                  categoryId: 1
                  customerCode: CustomerCode
                  dateCase: '2026-06-01T01:00:00'
                  dateDue: '2026-06-01T23:00:00'
                  stageId: 1
                  caseTag:
                    - CaseTag1
                    - CaseTag2
                  activityNo: ActivityNo
                  dealNo: DeaNo
                  chatId: ChatId
                  owner: StaffCode
                  participants:
                    - StaffCode1
                    - StaffCode2
                summary: Full Create
              '2':
                value:
                  subject: Subject
                  description: Description
                  categoryId: 1
                  dateCase: '2026-06-01T01:00:00Z'
                  dateDue: '2026-06-01T23:00:00Z'
                  owner: OWNER01
                summary: Minimal Create
              '3':
                value:
                  caseNo: CASE001
                  subject: Update Subject
                  description: Update Description
                  categoryId: 2
                  dateCase: '2026-06-01T01:00:00Z'
                  dateDue: '2026-06-01T23:00:00Z'
                  stageId: 2
                  caseTag:
                    - CaseTag3
                  activityNo: ActivityNo2
                  dealNo: DealNo2
                  chatId: ChatId2
                  owner: StaffCode3
                  participants:
                    - StaffCode4
                summary: Update Case
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: object
                    properties:
                      code:
                        type: string
                      description:
                        type: string
                    x-apidog-orders:
                      - code
                      - description
                    required:
                      - code
                      - description
                    x-apidog-ignore-properties: []
                  data:
                    type: object
                    properties:
                      caseNo:
                        type: string
                      subject:
                        type: string
                      description:
                        type: string
                      categoryId:
                        type: integer
                      stageId:
                        type: integer
                      customerCode:
                        type: string
                      source:
                        type: string
                      sourceName:
                        type: string
                      dateCase:
                        type: string
                      dateDue:
                        type: string
                      caseTag:
                        type: array
                        items:
                          type: string
                      activityNo:
                        type: array
                        items:
                          type: string
                      dealNo:
                        type: array
                        items:
                          type: string
                      chatId:
                        type: string
                      sla:
                        type: object
                        properties:
                          cycleStartedAt:
                            type: string
                          firstReplyAt:
                            type: 'null'
                          reopenCount:
                            type: integer
                          firstResponse:
                            type: object
                            properties:
                              targetMs:
                                type: integer
                              elapsedMs:
                                type: 'null'
                              breached:
                                type: boolean
                            required:
                              - targetMs
                              - elapsedMs
                              - breached
                            x-apidog-orders:
                              - targetMs
                              - elapsedMs
                              - breached
                            x-apidog-ignore-properties: []
                          resolution:
                            type: object
                            properties:
                              targetMs:
                                type: integer
                              elapsedMs:
                                type: 'null'
                              breached:
                                type: boolean
                            required:
                              - targetMs
                              - elapsedMs
                              - breached
                            x-apidog-orders:
                              - targetMs
                              - elapsedMs
                              - breached
                            x-apidog-ignore-properties: []
                        required:
                          - cycleStartedAt
                          - firstReplyAt
                          - reopenCount
                          - firstResponse
                          - resolution
                        x-apidog-orders:
                          - cycleStartedAt
                          - firstReplyAt
                          - reopenCount
                          - firstResponse
                          - resolution
                        x-apidog-ignore-properties: []
                      owner:
                        type: string
                      participants:
                        type: array
                        items:
                          type: string
                    x-apidog-orders:
                      - caseNo
                      - subject
                      - description
                      - categoryId
                      - stageId
                      - customerCode
                      - source
                      - sourceName
                      - dateCase
                      - dateDue
                      - caseTag
                      - activityNo
                      - dealNo
                      - chatId
                      - sla
                      - owner
                      - participants
                    x-apidog-ignore-properties: []
                x-apidog-orders:
                  - status
                  - data
                required:
                  - status
                x-apidog-ignore-properties: []
              example:
                status:
                  code: '1000'
                  description: Success
                data:
                  caseNo: CASE001
                  subject: Update Subject
                  description: Update Description
                  categoryId: 2
                  stageId: 2
                  customerCode: CustomerCode2
                  source: '4'
                  sourceName: สร้างเอง
                  dateCase: '2026-06-02T01:00:00Z'
                  dateDue: '2026-06-02T23:00:00Z'
                  caseTag:
                    - CaseTag3
                  activityNo:
                    - ActivityNo2
                  dealNo:
                    - DealNo2
                  chatId: ChatId2
                  sla:
                    cycleStartedAt: '2026-06-02T01:00:05Z'
                    firstReplyAt: null
                    reopenCount: 0
                    firstResponse:
                      targetMs: 1800000
                      elapsedMs: null
                      breached: false
                    resolution:
                      targetMs: 86400000
                      elapsedMs: null
                      breached: false
                  owner: StaffCode3
                  participants:
                    - StaffCode4
                    - StaffCode5
          headers: {}
          x-apidog-name: Update Success
        '201':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: object
                    properties:
                      code:
                        type: string
                      description:
                        type: string
                    x-apidog-orders:
                      - code
                      - description
                    required:
                      - code
                      - description
                    x-apidog-ignore-properties: []
                  data:
                    type: object
                    properties:
                      caseNo:
                        type: string
                      subject:
                        type: string
                      description:
                        type: string
                      categoryId:
                        type: integer
                      stageId:
                        type: integer
                      customerCode:
                        type: string
                      source:
                        type: string
                      sourceName:
                        type: string
                      dateCase:
                        type: string
                      dateDue:
                        type: string
                      caseTag:
                        type: array
                        items:
                          type: string
                      activityNo:
                        type: array
                        items:
                          type: string
                      dealNo:
                        type: array
                        items:
                          type: string
                      chatId:
                        type: string
                      sla:
                        type: object
                        properties:
                          cycleStartedAt:
                            type: string
                          firstReplyAt:
                            type: 'null'
                          reopenCount:
                            type: integer
                          firstResponse:
                            type: object
                            properties:
                              targetMs:
                                type: integer
                              elapsedMs:
                                type: 'null'
                              breached:
                                type: boolean
                            required:
                              - targetMs
                              - elapsedMs
                              - breached
                            x-apidog-orders:
                              - targetMs
                              - elapsedMs
                              - breached
                            x-apidog-ignore-properties: []
                          resolution:
                            type: object
                            properties:
                              targetMs:
                                type: integer
                              elapsedMs:
                                type: 'null'
                              breached:
                                type: boolean
                            required:
                              - targetMs
                              - elapsedMs
                              - breached
                            x-apidog-orders:
                              - targetMs
                              - elapsedMs
                              - breached
                            x-apidog-ignore-properties: []
                        required:
                          - cycleStartedAt
                          - firstReplyAt
                          - reopenCount
                          - firstResponse
                          - resolution
                        x-apidog-orders:
                          - cycleStartedAt
                          - firstReplyAt
                          - reopenCount
                          - firstResponse
                          - resolution
                        x-apidog-ignore-properties: []
                      owner:
                        type: string
                      participants:
                        type: array
                        items:
                          type: string
                    x-apidog-orders:
                      - caseNo
                      - subject
                      - description
                      - categoryId
                      - stageId
                      - customerCode
                      - source
                      - sourceName
                      - dateCase
                      - dateDue
                      - caseTag
                      - activityNo
                      - dealNo
                      - chatId
                      - sla
                      - owner
                      - participants
                    x-apidog-ignore-properties: []
                x-apidog-orders:
                  - status
                  - data
                required:
                  - status
                x-apidog-ignore-properties: []
              example:
                status:
                  code: '1000'
                  description: Success
                data:
                  caseNo: CASE001
                  subject: Subject
                  description: Description
                  categoryId: 1
                  stageId: 1
                  customerCode: CustomerCode
                  source: '4'
                  sourceName: สร้างเอง
                  dateCase: '2026-06-01T01:00:00Z'
                  dateDue: '2026-06-01T23:00:00Z'
                  caseTag:
                    - CaseTag1
                    - CaseTag2
                  activityNo:
                    - ActivityNo
                  dealNo:
                    - DealNo
                  chatId: ChatId
                  sla:
                    cycleStartedAt: '2026-06-01T01:00:05Z'
                    firstReplyAt: null
                    reopenCount: 0
                    firstResponse:
                      targetMs: 1800000
                      elapsedMs: null
                      breached: false
                    resolution:
                      targetMs: 86400000
                      elapsedMs: null
                      breached: false
                  owner: StaffCode
                  participants:
                    - StaffCode1
                    - StaffCode2
          headers: {}
          x-apidog-name: Create Success
        '400':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: object
                    properties:
                      code:
                        type: string
                      description:
                        type: string
                    x-apidog-orders:
                      - code
                      - description
                    required:
                      - code
                      - description
                    x-apidog-ignore-properties: []
                  data:
                    type: object
                    properties:
                      errors:
                        type: array
                        items:
                          type: object
                          properties:
                            subCode:
                              type: string
                            description:
                              type: string
                            metadata:
                              type: 'null'
                          x-apidog-orders:
                            - subCode
                            - description
                            - metadata
                          required:
                            - subCode
                          x-apidog-ignore-properties: []
                    x-apidog-orders:
                      - errors
                    required:
                      - errors
                    x-apidog-ignore-properties: []
                x-apidog-orders:
                  - status
                  - data
                required:
                  - status
                  - data
                x-apidog-ignore-properties: []
              example:
                status:
                  code: '4001'
                  description: Business error with 1 or more errors
                data:
                  errors:
                    - subCode: '400'
                      description: >-
                        subject is required.; categoryId is required.; owner is
                        required.
                      metadata: null
          headers: {}
          x-apidog-name: Missing Required Field
        '404':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: object
                    properties:
                      code:
                        type: string
                      description:
                        type: string
                    required:
                      - code
                      - description
                    x-apidog-orders:
                      - code
                      - description
                    x-apidog-ignore-properties: []
                  data:
                    type: object
                    properties:
                      errors:
                        type: array
                        items:
                          type: object
                          properties:
                            subCode:
                              type: string
                            description:
                              type: string
                            metadata:
                              type: 'null'
                          x-apidog-orders:
                            - subCode
                            - description
                            - metadata
                          x-apidog-ignore-properties: []
                    required:
                      - errors
                    x-apidog-orders:
                      - errors
                    x-apidog-ignore-properties: []
                required:
                  - status
                  - data
                x-apidog-orders:
                  - status
                  - data
                x-apidog-ignore-properties: []
              example:
                status:
                  code: '4001'
                  description: Business error with 1 or more errors
                data:
                  errors:
                    - subCode: '404'
                      description: >-
                        Case "CaseNo0" not found or does not belong to your
                        company.
                      metadata: null
          headers: {}
          x-apidog-name: Case Not Found (Update)
        x-200:User authentication required V2.:
          description: ''
          content:
            application/json:
              schema:
                title: ''
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/Required%20authorization'
                  status:
                    $ref: '#/components/schemas/Response%20Error%20Msg%20'
                required:
                  - data
                  - status
                x-apidog-orders:
                  - data
                  - status
                x-apidog-ignore-properties: []
              example:
                data:
                  subCode: E9103
                  description: Authorization credentials required
                  metadata: {}
                status:
                  code: '4001'
                  description: Business error with 1 errors
          headers: {}
          x-apidog-name: User authentication required V2.
        5XX:
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: object
                    properties:
                      code:
                        type: string
                      description:
                        type: string
                    required:
                      - code
                      - description
                    x-apidog-orders:
                      - code
                      - description
                    x-apidog-ignore-properties: []
                  data:
                    type: object
                    properties:
                      errors:
                        type: array
                        items:
                          type: object
                          properties:
                            subCode:
                              type: string
                            description:
                              type: string
                            metadata:
                              type: 'null'
                          x-apidog-orders:
                            - subCode
                            - description
                            - metadata
                          x-apidog-ignore-properties: []
                    required:
                      - errors
                    x-apidog-orders:
                      - errors
                    x-apidog-ignore-properties: []
                required:
                  - status
                  - data
                x-apidog-orders:
                  - status
                  - data
                x-apidog-ignore-properties: []
              examples:
                '5':
                  summary: Example 1
                  value:
                    status:
                      code: '4001'
                      description: Business error with 1 or more errors
                    data:
                      errors:
                        - subCode: '500'
                          description: >-
                            [DEBUG] HttpRequestException: No connection could be
                            made because the target machine actively refused it.
                          metadata: null
                '6':
                  summary: Example 2
                  value:
                    status:
                      code: '4001'
                      description: Business error with 1 or more errors
                    data:
                      errors:
                        - subCode: '502'
                          description: 'CaseManagement returned 502: (empty body)'
                          metadata: null
          headers: {}
          x-apidog-name: Server Error
      security:
        - bearer: []
      x-apidog-folder: Venio/Case Management
      x-apidog-status: developing
      x-run-in-apidog: https://app.apidog.com/web/project/351895/apis/api-38552388-run
components:
  schemas:
    'Response Error Msg ':
      type: object
      properties:
        code:
          type: string
          x-apidog-mock: '4001'
        description:
          type: string
          x-apidog-mock: Business error with 1 errors
      required:
        - code
        - description
      x-apidog-orders:
        - code
        - description
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
    Required authorization:
      type: object
      properties:
        subCode:
          type: string
          x-apidog-mock: E9103
        description:
          type: string
          x-apidog-mock: Authorization credentials required
        metadata:
          type: object
          properties: {}
          x-apidog-orders: []
          x-apidog-ignore-properties: []
      required:
        - subCode
        - description
        - metadata
      x-apidog-orders:
        - subCode
        - description
        - metadata
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
  securitySchemes:
    bearerAuth:
      type: jwt
      scheme: bearer
      bearerFormat: JWT
      description: ใส่ JWT Token ในรูปแบบ Bearer {token}
    bearer:
      type: http
      scheme: bearer
servers:
  - url: https://api.gofive.co.th
    description: Production
security:
  - bearerAuth: []
    x-apidog:
      schemeGroups:
        - id: uyL_cJmK7q60QJZRTi5ot
          schemeIds:
            - bearerAuth
      required: true
      use:
        id: uyL_cJmK7q60QJZRTi5ot
      scopes:
        uyL_cJmK7q60QJZRTi5ot:
          bearerAuth: []

```
