Updating resources

How to update a resource via API

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

The Content-Type header must be application/vnd.api+json.

You can get the list of arguments, with type and examples from the documentation of each resource.

pageAuthentication

Examples

Updating attributes

The following request updates the description of an existing SKU:

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",
    "attributes": {
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
    }
  }
}'

Updating relationships

The following request changes the shipping category of an existing SKU:

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",
    "relationships": {
      "shipping_category": {
        "data": {
          "type": "shipping_categories",
          "id": "ywMJmFPBWA"
        }
      }
    }
  }
}'

Removing relationships

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.

The following request removes a customer from a customer group:

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": {
        "data": null
      }
    }
  }
}'

Last updated