> ## Documentation Index
> Fetch the complete documentation index at: https://docs.parceltracer.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Update Order

> Update specific fields of an existing order.

**Modifiable fields:**
- `reference_id`
- `is_critical`
- `cod`
- `number_of_packages`
- `description`
- `notes`
- `return_reason`

**Important:**
- You **cannot modify** the order once it reaches a terminal state: `DELIVERED`, `DELIVERED_AT_WAREHOUSE`, or `CANCELLED`.
- Attempts to update any other fields will result in a **400** error.



## OpenAPI

````yaml api-reference/schema.yaml patch /orders/{order_id}/
openapi: 3.0.3
info:
  title: ''
  version: 0.0.0
servers:
  - url: https://api.parceltracer.com/v1/external/
    description: Parcel Tracer api endpoint
security: []
paths:
  /orders/{order_id}/:
    patch:
      tags:
        - Orders
      summary: Update Order
      description: >-
        Update specific fields of an existing order.


        **Modifiable fields:**

        - `reference_id`

        - `is_critical`

        - `cod`

        - `number_of_packages`

        - `description`

        - `notes`

        - `return_reason`


        **Important:**

        - You **cannot modify** the order once it reaches a terminal state:
        `DELIVERED`, `DELIVERED_AT_WAREHOUSE`, or `CANCELLED`.

        - Attempts to update any other fields will result in a **400** error.
      operationId: partial_update_order
      parameters:
        - in: path
          name: order_id
          schema:
            type: integer
          required: true
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PatchedPatchOrderSerializerDocs'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/PatchedPatchOrderSerializerDocs'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/PatchedPatchOrderSerializerDocs'
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExternalOrder'
              examples:
                SuccessfulOrderCreation:
                  value:
                    order_id: '179'
                    reference_id: '123'
                    is_exchange: 'false'
                    workflow: STANDARD
                    tracking_link: https://prod.parceltracer.app/tracking/xxxxxxx-yyyyyy
                    is_critical: 'true'
                    merchant_location: 1
                    cod:
                      - - LBP
                        - '2000.00'
                      - - USD
                        - '50.50'
                    number_of_packages: 1
                    description: ''
                    notes: ''
                    return_reason: ''
                    delivery_state: CREATED
                    payment_state: UNPAID
                    merchant_invoice: null
                    customer:
                      id: 9707
                      name: Joelle
                      phone_number: '+96131234567'
                      secondary_phone_number: null
                      email: ''
                    customer_location:
                      id: 9689
                      area:
                        id: 55
                        name_en: Balde
                        name_ar: بلدي
                        lat: 34.56076
                        long: 36.14491
                        district: Akkar
                        maps_link: http://maps.google.com/maps?q=34.56076,36.14491
                      directions: ''
                  summary: Successful order creation
          description: Successful patch
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                ValidationError:
                  value:
                    error: 'true'
                    message: Validation failed.
                    details: 'workflow: "STANDARDS" is not a valid choice.'
                  summary: Example of validation error response
          description: Validation failure
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                NotFoundError:
                  value:
                    error: 'true'
                    message: Resource not found.
                    details: 'detail: Not found.'
                  summary: Example of resource not found error
          description: Order not found
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                ServerError:
                  value:
                    error: 'true'
                    message: Unexpected error.
                    details: Internal server error
                  summary: Example of internal server error response
          description: Server error
      security:
        - MerchantAPIKey: []
components:
  schemas:
    PatchedPatchOrderSerializerDocs:
      type: object
      properties:
        reference_id:
          type: string
          description: Reference ID of the order, for internal tracking by the shop.
        is_critical:
          type: boolean
          description: Mark the order as critical for prioritized handling.
        cod:
          type: array
          items:
            type: array
            items:
              type: string
            maxItems: 2
            minItems: 2
          description: >-
            Cash-on-delivery amount to collect upon delivery in case of STANDARD
            delivery, or to be paid by shop on return for RETURN orders.Format:
            [['USD', '123.5']].


            Can only be modified if:

            - Workflow is 'STANDARD', or

            - Workflow is 'RETURN' **and** the delivery state is 'CREATED'.
        number_of_packages:
          type: integer
          description: Number of packages in the order.
        description:
          type: string
          description: Optional description of the order contents.
        notes:
          type: string
          description: Customer-visible notes about the order.
        return_reason:
          type: string
          description: Applicable if the order is a return. Reason for the return.
    ExternalOrder:
      type: object
      properties:
        order_id:
          type: string
          readOnly: true
          nullable: true
        reference_id:
          type: string
          pattern: ^([A-Za-z0-9]|\.|-)*$
          maxLength: 40
        is_exchange:
          type: boolean
        workflow:
          $ref: '#/components/schemas/ExternalOrderWorkflowEnum'
        tracking_link:
          type: string
          format: uri
          readOnly: true
        is_critical:
          type: boolean
          title: Critical
        customer:
          type: object
          additionalProperties: {}
          writeOnly: true
          description: >-
            Customer object identifying the customer for the order.

            - To identify an existing customer, provide the unique 'id' field.
            Other fields will update the existing record.

            - Alternatively, if 'id' is not provided, provide the unique
            'phone_number' to identify the customer.

            - If neither 'id' nor existing 'phone_number' is found, a new
            customer will be created, and all required customer fields must be
            provided.
        customer_location:
          type: object
          additionalProperties: {}
          writeOnly: true
          description: >-
            Customer location object for order delivery or pickup.

            - To identify an existing location, provide the unique 'id'. Other
            fields will update that location.

            - If 'id' is not provided, a new location will be created and all
            required fields must be present.

            - The location must belong to the specified customer, else the
            request will be rejected.
        resolved_customer:
          allOf:
            - $ref: '#/components/schemas/Customer'
          readOnly: true
        resolved_customer_location:
          allOf:
            - $ref: '#/components/schemas/ExternalLocation'
          readOnly: true
        merchant_location:
          type: integer
        cod:
          type: array
          items:
            type: array
            items:
              type: string
            maxItems: 2
            minItems: 2
          description: >-
            Total amount to be collected upon delivery. Example: [['USD',
            '123.5']]
        delivery_fee:
          type: array
          items:
            type: array
            items:
              type: string
            maxItems: 2
            minItems: 2
          readOnly: true
          description: >-
            Delivery fees charged on the delivery operation. Irrelevant in case
            of `RETURN` orders.
        number_of_packages:
          type: integer
          maximum: 99
          minimum: 1
        description:
          type: string
          maxLength: 300
        notes:
          type: string
        return_reason:
          type: string
          maxLength: 300
        delivery_state:
          allOf:
            - $ref: '#/components/schemas/DeliveryStateEnum'
          readOnly: true
        payment_state:
          type: string
          readOnly: true
        merchant_invoice:
          type: integer
          readOnly: true
          nullable: true
      required:
        - customer
        - customer_location
        - delivery_fee
        - delivery_state
        - merchant_invoice
        - merchant_location
        - order_id
        - payment_state
        - resolved_customer
        - resolved_customer_location
        - tracking_link
    ErrorResponse:
      type: object
      properties:
        error:
          type: boolean
        message:
          type: string
        details: {}
      required:
        - details
        - error
        - message
    ExternalOrderWorkflowEnum:
      enum:
        - STANDARD
        - RETURN
      type: string
      description: |-
        * `STANDARD` - Standard
        * `RETURN` - Return
    Customer:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        name:
          type: string
          maxLength: 255
        phone_number:
          type: string
        secondary_phone_number:
          type: string
        email:
          type: string
          format: email
      required:
        - id
        - name
        - phone_number
    ExternalLocation:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        area:
          $ref: '#/components/schemas/Area'
        directions:
          type: string
      required:
        - area
        - id
    DeliveryStateEnum:
      enum:
        - CREATED
        - PICKUP_REQUESTED
        - PICKUP_ASSIGNED
        - SCANNED_FOR_PICKUP
        - PICKED_UP
        - AT_WAREHOUSE
        - DELIVERY_ASSIGNED
        - SCANNED_FOR_DELIVERY
        - PICKED_UP_FOR_DELIVERY
        - IN_TRANSIT
        - DELIVERED
        - AWAITING_RETURN
        - CANCELLED
        - DELIVERED_AT_WAREHOUSE
      type: string
      description: |-
        * `CREATED` - Created
        * `PICKUP_REQUESTED` - Pickup Requested
        * `PICKUP_ASSIGNED` - Pickup Assigned
        * `SCANNED_FOR_PICKUP` - Scanned for Pickup
        * `PICKED_UP` - Picked Up
        * `AT_WAREHOUSE` - At Warehouse
        * `DELIVERY_ASSIGNED` - Delivery Assigned
        * `SCANNED_FOR_DELIVERY` - Scanned For Delivery
        * `PICKED_UP_FOR_DELIVERY` - Picked Up For Delivery
        * `IN_TRANSIT` - In Transit
        * `DELIVERED` - Delivered
        * `AWAITING_RETURN` - Awaiting Return
        * `CANCELLED` - Cancelled
        * `DELIVERED_AT_WAREHOUSE` - Delivered At Warehouse
    Area:
      type: object
      description: |-
        A ModelSerializer that takes an additional `fields` argument that
        controls which fields should be displayed.
      properties:
        id:
          type: integer
          readOnly: true
        name_ar:
          type: string
          default: ''
          maxLength: 200
        name_en:
          type: string
          default: ''
          maxLength: 200
        district:
          $ref: '#/components/schemas/DistrictEnum'
        lat:
          type: string
          format: decimal
          pattern: ^-?\d{0,3}(?:\.\d{0,15})?$
          nullable: true
        long:
          type: string
          format: decimal
          pattern: ^-?\d{0,3}(?:\.\d{0,15})?$
          nullable: true
        maps_link:
          type: string
          nullable: true
          maxLength: 200
        code:
          type: string
          readOnly: true
      required:
        - code
        - id
    DistrictEnum:
      enum:
        - Zahleh
        - Hasbaya
        - Baalbek
        - Jezzine
        - Baabda
        - Jbeil
        - Zgharta
        - Bint Jbeil
        - Hermel
        - Marjeyoun
        - Bsharri
        - Aley
        - Rashaya
        - Miniyeh-Danniyeh
        - Tripoli
        - Tyre
        - Nabatieh
        - Chouf
        - Maatn
        - Western Beqaa
        - Akkar
        - Sidon
        - Batroun
        - Keserwan
        - Koura
        - Beirut
      type: string
      description: |-
        * `Zahleh` - Zahleh
        * `Hasbaya` - Hasbaya
        * `Baalbek` - Baalbek
        * `Jezzine` - Jezzine
        * `Baabda` - Baabda
        * `Jbeil` - Jbeil
        * `Zgharta` - Zgharta
        * `Bint Jbeil` - Bint Jbeil
        * `Hermel` - Hermel
        * `Marjeyoun` - Marjeyoun
        * `Bsharri` - Bsharri
        * `Aley` - Aley
        * `Rashaya` - Rashaya
        * `Miniyeh-Danniyeh` - Miniyeh-Danniyeh
        * `Tripoli` - Tripoli
        * `Tyre` - Tyre
        * `Nabatieh` - Nabatieh
        * `Chouf` - Chouf
        * `Maatn` - Maatn
        * `Western Beqaa` - Western Beqaa
        * `Akkar` - Akkar
        * `Sidon` - Sidon
        * `Batroun` - Batroun
        * `Keserwan` - Keserwan
        * `Koura` - Koura
        * `Beirut` - Beirut
  securitySchemes:
    MerchantAPIKey:
      type: apiKey
      in: header
      name: X-Api-Key

````