# Updating resources

You can update a resource by sending a `PATCH` request to the resources endpoint, with a JSON payload.

{% hint style="warning" %}
The **Content-Type** header must be `application/vnd.api+json`.
{% endhint %}

{% hint style="info" %}
You can get the list of arguments, with type and examples from the documentation of each resource.
{% endhint %}

{% content-ref url="/pages/-LgCGPTjMSTg9sVBpFDk" %}
[Authentication](/core/authentication.md)
{% endcontent-ref %}

### Examples

#### Updating attributes

{% tabs %}
{% tab title="Request" %}
The following request updates the description of an existing SKU:

<pre class="language-sh"><code class="lang-sh">curl -g -X PATCH \
  'https://yourdomain.commercelayer.io/api/skus/xYZkjABcde' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token' \
  -H 'Content-Type: application/vnd.api+json' \
  -d '{
  "data": {
    "type": "skus",
    "id": "xYZkjABcde",
<strong>    "attributes": {
</strong><strong>      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
</strong><strong>    }
</strong>  }
}'
</code></pre>

{% endtab %}

{% tab title="Response" %}
On success, the API responds with a `200 OK` status code, returning the updated resource object:

<pre class="language-javascript"><code class="lang-javascript">{
  "data": {
    "id": "xYZkjABcde",
    "type": "skus",
    "links": {
      "self": "https://yourdomain.commercelayer.io/api/skus/xYZkjABcde"
    },
      "attributes": {
        "code": "TSHIRTMM000000FFFFFFXLXX",
        "name": "Men's Black T-shirt with White Logo (XL)",
<strong>        "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
</strong>        "image_url": null,
        "tag_names": "",
        "pieces_per_pack": null,
        "weight": null,
        "unit_of_weight": null,
        "hs_tariff_number": null,
        "do_not_ship": false,
        "do_not_track": false,
        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "metadata": {}
      },
      "relationships": {
        "shipping_category": {
          "links": {...}
        },
        "prices": {
          "links": {...}
        },
        "stock_items": {
          "links": {...}
        },
        "delivery_lead_times": {
          "links": {...}
        },
        "sku_options": {
          "links": {...}
        }
    },
    "meta": {
      "mode": "test"
    }  
  }
}
</code></pre>

{% endtab %}
{% endtabs %}

#### Updating relationships

{% tabs %}
{% tab title="Request" %}
The following request changes the shipping category of an existing SKU:

<pre class="language-sh"><code class="lang-sh">curl -g -X PATCH \
  'https://yourdomain.commercelayer.io/api/skus/xYZkjABcde' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token' \
  -H 'Content-Type: application/vnd.api+json' \
  -d '{
  "data": {
    "type": "skus",
    "id": "xYZkjABcde",
<strong>    "relationships": {
</strong><strong>      "shipping_category": {
</strong><strong>        "data": {
</strong><strong>          "type": "shipping_categories",
</strong><strong>          "id": "ywMJmFPBWA"
</strong><strong>        }
</strong><strong>      }
</strong><strong>    }
</strong>  }
}'
</code></pre>

{% endtab %}

{% tab title="Response" %}
On success, the API responds with a `200 OK` status code, returning the updated resource object:

<pre class="language-json"><code class="lang-json">{
  "data": {
    "id": "xYZkjABcde",
    "type": "skus",
    "links": {
      "self": "https://yourdomain.commercelayer.io/api/skus/xYZkjABcde"
    },
      "attributes": {
        "code": "TSHIRTMM000000FFFFFFXLXX",
        "name": "Men's Black T-shirt with White Logo (XL)",
        "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
        "image_url": null,
        "tag_names": "",
        "pieces_per_pack": null,
        "weight": null,
        "unit_of_weight": null,
        "hs_tariff_number": null,
        "do_not_ship": false,
        "do_not_track": false,
        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "metadata": {}
      },
      "relationships": {
<strong>        "shipping_category": {
</strong><strong>          "links": {...}
</strong><strong>        },
</strong>        "prices": {
          "links": {...}
        },
        "stock_items": {
          "links": {...}
        },
        "delivery_lead_times": {
          "links": {...}
        },
        "sku_options": {
          "links": {...}
        }
    },
    "meta": {
      "mode": "test"
    }  
  }
}
</code></pre>

{% endtab %}
{% endtabs %}

#### Removing relationships

{% hint style="info" %}
If a relationship is *optional* for the creation of a resource, it can be removed by sending `PATCH` request with the `data` object set as `null`.
{% endhint %}

{% tabs %}
{% tab title="Request" %}
The following request removes a customer from a customer group:

<pre class="language-sh"><code class="lang-sh">curl -g -X PATCH \
  'https://yourdomain.commercelayer.io/api/customers/bQWpdhWxVk' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token' \
  -H 'Content-Type: application/vnd.api+json' \
  -d '{
  "data": {
    "type": "customers",
    "id": "bQWpdhWxVk",
    "relationships": {
      "customer_group": {
<strong>        "data": null
</strong>      }
    }
  }
}'
</code></pre>

{% endtab %}

{% tab title="Response" %}
On success, the API responds with a `200 OK` status code, returning the updated resource object:

```json
{
  "data": {
    "id": "bQWpdhWxVk",
    "type": "customers",
    "links": {
      "self": "https://yourdomain.commercelayer.io/api/customers/bQWpdhWxVk"
    },
    "attributes": {
      "email": "john@example.com",
      "status": "acquired",
      "has_password": true,
      "created_at": "2018-01-01T12:00:00.000Z",
      "updated_at": "2018-01-01T12:00:00.000Z",
      "reference": "",
      "reference_origin": null,
      "metadata": {}
    },
    "relationships": {
      "customer_group": {
        "links": { ... }
      },
      "customer_addresses": {
        "links": { ... }
      },
      "customer_payment_sources": {
        "links": { ... }
      },
      "customer_subscriptions": {
        "links": { ... }
      },
      "orders": {
        "links": { ... }
      },
      "order_subscriptions": {
        "links": { ... }
      },
      "returns": {
        "links": { ... }
      },
      "sku_lists": {
        "links": { ... }
      },
      "attachments": {
        "links": { ... }
      },
      "events": {
        "links": { ... }
      }
    },
    "meta": {
      "mode": "test",
      "organization_id": "EnAvaFOrRe"
    }
  }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.commercelayer.io/core/updating-resources.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
