> For the complete documentation index, see [llms.txt](https://shiply-integration-apis.gitbook.io/shiply-integration-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://shiply-integration-apis.gitbook.io/shiply-integration-documentation/integration-apis/companion-parcels/update-companion-parcel.md).

# Update Companion Parcel

```php
PUT /parcels/companion/{id}
```

This API is used to update an existing companion parcel information.

{% hint style="info" %}
**Note:** Replace <mark style="color:blue;">{id}</mark> with the id of the companion parcel whose information you want to update.
{% endhint %}

#### Headers

<table><thead><tr><th width="374">Key</th><th>Value</th></tr></thead><tbody><tr><td>Accept</td><td>application/json</td></tr><tr><td>Content-Type</td><td>application/json</td></tr></tbody></table>

#### Request body

Request parameters:

<table><thead><tr><th width="183">Field Name</th><th width="104">Required</th><th width="93">Type</th><th>Notes</th></tr></thead><tbody><tr><td>parcel_id</td><td>no</td><td>integer</td><td>This refers to the <mark style="color:blue;">parcel_code</mark> of the parent parcel.</td></tr><tr><td>qr_code</td><td>no</td><td>string</td><td>This is the QR code to be assigned to the companion parcel.</td></tr><tr><td>qr_hash</td><td>no</td><td>string</td><td></td></tr><tr><td>description</td><td>no</td><td>string</td><td>Maximum of 500 characters.</td></tr><tr><td>length</td><td>no</td><td>integer</td><td></td></tr><tr><td>height</td><td>no</td><td>integer</td><td></td></tr><tr><td>width</td><td>no</td><td>integer</td><td></td></tr><tr><td>weight</td><td>no</td><td>numeric</td><td></td></tr><tr><td>parcel_position_id</td><td>no</td><td>integer</td><td>This refers to one of the parcel positions defined in the list provided here<a data-mention href="/shiply-integration-documentation/general-definitions.md">General Definitions</a></td></tr></tbody></table>

Request body example:

{% code lineNumbers="true" %}

```json
{
    "parcel_id": "asnf-000-4280034",
    "description": "edit description",
    "height":40,
    "width": 40,
    "length": 40,
    "Shiply_API_KEY": "your_api_key"
}
```

{% endcode %}

#### Response body

{% tabs %}
{% tab title="Success" %}
Status code: <mark style="color:green;">200 OK</mark>

{% code lineNumbers="true" %}

```json
{
     "success": true,
      "companion_parcel": {
          "id": 1905,
          "qr_code": "",
          "qr_hash": "",
          "description": "edit description",
          "weight": null,
          "height": 40,
          "width": 30,
          "length": 40,
          "parcel_position_id": 1,
          "created_at": "2024-11-16 16:38:14",
          "updated_at": "2024-11-16 16:43:03",
          "cell": null,
          "size": 48000,
          "contents": []
      }
}
```

{% endcode %}

The response includes a <mark style="color:blue;">companion\_parcel</mark> field, which contains the details of the updated companion parcel.
{% endtab %}

{% tab title="Parcel not found" %}
Status code: <mark style="color:green;">200 OK</mark>

{% code lineNumbers="true" %}

```json
{
    "success": false,
    "errors": [
        "parcel not found"
    ]
}
```

{% endcode %}

This response is returned when:

* The <mark style="color:blue;">{id}</mark> provided in the route does not correspond to an existing companion parcel.
* The user cannot access the parent parcel.
  {% endtab %}

{% tab title="Cannot update companion parcel" %}
Status code: <mark style="color:green;">200 OK</mark>

{% code lineNumbers="true" %}

```json
{
    "success": false,
    "error": "cant update companion parcel for not draft or submitted parcel"
}
```

{% endcode %}

{% code lineNumbers="true" %}

```json
{
    "success": false,
    "errors": [
        "cant update companion parcel for closed invoice"
    ]
}
```

{% endcode %}

This response is returned when:

* The <mark style="color:blue;">{id}</mark> provided in the route corresponds to a companion parcel whose parent parcel can no longer be edited (closed invoice, not draft or submitted parcel).
  {% endtab %}

{% tab title="Size limit" %}
Status code: <mark style="color:green;">200 OK</mark>

{% code lineNumbers="true" %}

```json
{
    "success": false,
    "error": "أبعاد الطرد غير متناسبة"
}
```

{% endcode %}

This response is returned when:

* The dimensions (<mark style="color:blue;">height</mark>, <mark style="color:blue;">length</mark>, <mark style="color:blue;">width</mark>) provided in the request body are not valid or accepted.
  {% endtab %}

{% tab title="Fail" %}
Status code: <mark style="color:green;">200 OK</mark>

{% code lineNumbers="true" %}

```json
{
    "success": "error while updating companion parcel"
}
```

{% endcode %}

This response is returned when a database error occurs while attempting to update a companion parcel.
{% endtab %}

{% tab title="Unauthorized" %}
Status code: <mark style="color:green;">200 OK</mark>

{% code lineNumbers="true" %}

```json
{
    "success": false,
    "errors": [
        "unauthorized"
    ]
}
```

{% endcode %}

This response is returned when the <mark style="color:blue;">Shiply\_API\_KEY</mark> is not included in the request body.
{% endtab %}
{% endtabs %}
