Patch Operation Use Cases

Each product record is accompanied by a patch operation and path.

  • "op" specifies the JSON Patch operation, and can have one of two values: "add" to add or replace data, or "remove" to remove data.
  • "path" specifies the product record to operate on. This could include the entire product record, or a specific property or attribute.

The use cases below provide details on how to modify various portions of your product data.

Products

Product-level operations

  • Add/replace a product: Adds or completely replaces the product, including all of its variants and views data.
  • Remove a product: Removes a product (including all of its variants and views data).
//Adds or completely replaces the product, including all of its variants and views data
{
  "op": "add", 
  "path": "/products/839799", 
  //Path is /products/<product ID>
  "value": {
    "attributes": {  
      "age_group": "n/a",
      "department": "homeware",
      //Enclose string values in quotes
      "code": 42,
      //No quotes for numeric values
      "keywords": ["home", "sale"],    
      //Enclose arrays in square brackets, values should be comma separated
      "currency": "USD",
      ...
    },
    ...
}
//Removes a product (including all of its variants and views data)
{
  "op": "remove",
  "path": "/products/839799" 
  //Path is /products/<product ID>
} 
//"value" is not needed for remove operations

Product attribute-level operations

  • Add/replace all product attributes: Adds or replaces all the attributes of a product (does not modify variants or views data).
  • Remove all product attributes: Removes all the attributes of a product (does not modify variants or views data).
//Adds or replaces all the attributes of a product (does not modify variants or views data).
{
  "op": "add", 
  "path": "/products/839799/attributes",
  //Path is /products/<product ID>/attributes 
  "value": {
    "age_group": "n/a",
    "department": "homeware",
    "code": 42,
    "keywords": ["home", "sale"],
    "currency": "USD",
    ...
  }
}
//Removes all the attributes of a product (does not modify variants or views data).
{
  "op": "remove",
  "path": "/products/839799/attributes" 
  //Path is /products/<product ID>/attributes
}
  • Add/replace a single product attribute: Adds or replaces a single attribute of a product.
  • Remove a single product attribute: Removes a single attribute of a product.
//Adds or replaces a single attribute of a product
{
  "op": "add", 
  "path": "/products/839799/attributes/department",
  //Path is /products/<product ID>/attributes/<attribute name> 
  "value": "homeware"
}
//Removes a single attribute of a product.
{
  "op": "remove", 
  "path": "/products/839799/attributes/department" 
  //Path is /products/<product ID>/attributes/<attribute name>
}

Variants

Variant-level operations

  • Add/replace all variants of a product: Adds or replaces all variants of a product. If you are working on an existing variants object, variants will be deleted if you do not specify them again.
  • Remove all variants of a product: Removes all variants of a product (and all their views data, if it exists).
//Adds or replaces all variants of a product. 
//If you are working on an existing variants object, variants will be deleted if you do not specify them again.
{
  "op": "add", 
  "path": "/products/839799/variants", 
  //Path is /products/<product ID>/variants
  "value": {
    "83979901": {
      "attributes": {      
        "availability": true, 
        "price": 106.00,
        "size": "onesize",
        "color": "blue",
        ...
      }
    },
    "83979902": {
      "attributes": {      
        "availability": true, 
        "price": 52.00,
        "size": "onesize",
        "color": "red",
        ...
      }
    },
    "83979903": {
      "attributes": {      
        "availability": true, 
        "price": 79.00,
        "size": "onesize",
        "color": "green",
        ...
      }
    }
  }
}
//Removes all variants of a product (and all their views data, if it exists). 
{
  "op": "remove", 
  "path": "/products/839799/variants" 
  //Path is /products/<product ID>/variants
}
  • Add/replace a single variant for a product: Adds or replaces a single variant for a product. Other variants of the product are unaffected.
  • Remove a single variant of a product: Removes a variant of a product (and all of its views data, if it exists).
//Adds or replaces a single variant for a product. Other variants of the product are unaffected. 
{
  "op": "add", 
  "path": "/products/839799/variants/83979901", 
  //Path is /products/<product ID>/variants/<variant ID>
  "value": {
    "attributes": {      
      "availability": true, 
      "price": 106.00,
      "size": "onesize",
      "color": "blue",
      ...
    }
  }
}
//Removes a variant of a product (and all of its views data, if it exists)
{
  "op": "remove", 
  "path": "/products/839799/variants/83979901" 
  //Path is /products/<product ID>/variants/<variant ID>
}

Variant attribute-level operations

  • Add/replace all attributes for a variant
  • Remove all attributes from a variant
{
  "op": "add", 
  "path": "/products/839799/variants/83979901/attributes", 
  //Path is /products/<product ID>/variants/<variant ID>/attributes
  "value": {      
    "availability": true, 
    "price": 106.00,
    "size": "onesize",
    "color": "blue",
    ...
  }
}
{
  "op": "remove", 
  "path": "/products/839799/variants/83979901/attributes"
  //Path is /products/<product ID>/variants/<variant ID>/attributes
}
  • Add/replace a single variant attribute
  • Remove a single variant attribute
{
  "op": "add", 
  "path": "/products/839799/variants/83979901/attributes/size", 
  //Path is /products/<product ID>/variants/<variant ID>/attributes/<attribute name>
  "value": "onesize"
}
{
  "op": "remove", 
  "path": "/products/839799/variants/83979901/attributes/size" 
  //Path is /products/<product ID>/variants/<variant ID>/attributes/<attribute name>
}

Views

Attributes specified in a product view or variant view augment the base attributes within the scope of that view. In case of collision, view attributes override the base values in the view where they are defined.

For multi-value fields, all the values are overridden. If the view attribute is a single value and the base attribute is multi-value, the whole array will be replaced by the single value.

View-level operations

  • Add/replace all views of a product: Adds or replaces all views of a product. If you work on an existing views property, views will be deleted if you do not specify them again. Every view a product exists in needs to be specified, even if it does not contain any attribute overrides. However, views don’t need to be specified in one operation, and additional views can be added in subsequent operations.
  • Remove all views of a product: Removes all views of a product, including all of the views data (view attributes, variants view attributes, etc).
//Adds or replaces all views of a product.
//If you work on an existing views property, views will be deleted if you do not specify them again. 
//Every view a product exists in needs to be specified, even if it does not contain any attribute overrides. 
//However, views don’t need to be specified in one operation, and additional views can be added in subsequent operations.
{
  "op": "add",
  "path": "/products/839799/views",
  //Path is /products/<product ID>/views
  "value": {
    "ae": {
    //View ID
      "attributes": {
        "currency": "AED",
        //Overrides currency at the product level
        ...
      },
    "uk": {
      "attributes": { 
        "currency": "GBP",
        ...
      },
    "it": {}
    //Views without any attribute overrides must still be specified if the product exists in the view
    ... 
    }
  }
}
//Removes all views of a product, including all of the views data (view attributes, variants view attributes, etc)
{
  "op": "remove",
  "path": "/products/839799/views"
  //Path is /products/<product ID>/views
}
  • Add/replace a view for a product
  • Remove a view of a product: Also removes the associated view data.
{
  "op": "add",
  "path": "/products/839799/views/ae",
  //Path is /products/<product ID>/views/<view ID>
  "value": { 
    "attributes": {
      "currency": "AED",
      "price": 79.99,
      ...
    }
  }
}
//Also removes the associated view data
{
  "op": "remove",
  "path": "/products/839799/views/ae"
  //Path is /products/<product ID>/views/<view ID>
}

View attribute-level operations

  • Add/replace all view attributes for a product
  • Remove all view attributes of a product: Removes all the view attributes for the product. This does not affect the other view data, like variants view data.
{
  "op": "add",
  "path": "/products/839799/views/ae/attributes",
  //Path is /products/<product ID>/views/<view ID>/attributes
  "value": {
    "currency": "AED",
    "price": 79.99,
    ...
  }
}
//Removes all the view attributes for the product. This does not affect the other view data, like variants view data.
{
  "op": "remove",
  "path": "/products/839799/views/ae/attributes"
  //Path is /products/<product ID>/views/<view ID>/attributes
}
  • Add/replace a view attribute for a product
  • Remove a view attribute for a product
{
  "op": "add",
  "path": "/products/839799/views/ae/attributes/price",
  //Path is /products/<product ID>/views/<view ID>/attributes/<attribute name>
  "value": 79.99
}
{
  "op": "remove",
  "path": "/products/839799/views/ae/attributes/price"
  //Path is /products/<product ID>/views/<view ID>/attributes/<attribute name>
}

Variants and Views

Variant view-level operations

  • Add/replace all variants view data: In order for this operation to succeed, the variants need to exist at the product level, even if they have no attributes. If adding a new variant, you must first add the variant through a variant operation. A variant can not be added only through only a view operation.
  • Remove all variants view data: Removes all the variants view data for a specific view. This resets all the variants to their base data in that view, but does not remove variants from the view.
//In order for this operation to succeed, the variants need to exist at the product level, even if they have no attributes. 
//If adding a new variant, you must first add the variant through a variant operation. 
//A variant can not be added only through only a view operation.
{
  "op": "add",
  "path": "/products/839799/views/ae/variants",
  //Path is /products/<product ID>/views/<view ID>/variants
  "value": { 
    "83979901": {
    //Variant ID
      "attributes": {
      //View-specific variant attributes
        "availability": true,
        "price": 106.00,
        "size": "onesize",
        "color": "blue",
        ...
      }
    },
    "83979902": {
      "attributes": {
        "availability": true,
        "price": 53.00,
        "size": "onesize",
        "color": "red",
        ...
      }
    },
    ...
  }
}
//Removes all the variants view data for a specific view. 
//This resets all the variants to their base data in that view, but does not remove variants from the view.
{
  "op": "remove",
  "path": "/products/839799/views/ae/variants"
  //Path is /products/<product ID>/views/<view ID>/variants
}
  • Add/replace all view data for a specific variant
  • Remove all view data for a specific variant
{
  "op": "add",
  "path": "/products/839799/views/ae/variants/83979901",
  //Path is /products/<product ID>/views/<view ID>/variants/<variant ID>
  "value": {
    "attributes": {
      "availability": true,
      "price": 106.00,
      "size": "onesize",
      "color": "blue",
      ...
    }
  }
}
{
  "op": "remove",
  "path": "/products/839799/views/ae/variants/83979901"
  //Path is /products/<product ID>/views/<view ID>/variants/<variant ID>
}

Variant view attribute-level operations

  • Add/replace all view attributes for a specific variant
  • Remove all view attributes for a specific variant
{
  "op": "add",
  "path": "/products/839799/views/ae/variants/83979901/attributes",
  //Path is /products/<product ID>/views/<view ID>/variants/<variant ID>/attributes
  "value": {
    "availability": true,
    "price": 106.00,
    "size": "onesize",
    "color": "blue",
    ...
  }
}
{
  "op": "remove",
  "path": "/products/839799/views/ae/variants/83979901/attributes"
  //Path is /products/<product ID>/views/<view ID>/variants/<variant ID>/attributes
}
  • Add/replace a variant view attribute
  • Remove a variant view attribute
{
  "op": "add",
  "path": "/products/839799/views/ae/variants/83979901/attributes/price",
  //Path is /products/<product ID>/views/<view ID>/variants/<variant ID>/attributes/<attribute name>
  "value": 106.00
}
{
  "op": "remove",
  "path": "/products/839799/views/ae/variants/83979901/attributes/price"
  //Path is /products/<product ID>/views/<view ID>/variants/<variant ID>/attributes/<attribute name>
}