update_product
PUT https://api.bootic.net/v1/shops/:shop_id/products/:id_or_slug
Use this relation to update or create a product for a given shop.
This relation is available only for products owned by your current scope and credentials (required scope: admin
).
Consider this a BETA feature.
HTTP PUT
$ curl -XPUT -H'Accept:application/json' -H'Content-Type:application/json' -H "Authorization: Bearer xxxx" -i https://api.bootic.net/v1/shops/:shop_id/products/:id -d[REQUEST_BODY]
Request body
{
"title": "iPhone 5",
"price": 20020,
"price_comparison": 20122,
"description": "iPhone 5 by Apple",
"status": "visible",
"product_type_name": "Smart phones",
"tags": [
"communications",
"handheld"
],
"vendor": "Acme",
"_policies": {
"keep_variants": false
},
"variants": [
{
"id": 1234,
"title": "White",
"sku": "1234R",
"available_if_no_stock": 1,
"stock": 102,
"weight_in_grams": 340
},
{
"title": "Dark blue",
"sku": "1244R",
"available_if_no_stock": 0,
"stock": 10,
"weight_in_grams": 340
}
],
"custom_attributes": [
{
"name": "Colour",
"value": "red",
"field_type": "string",
"required": true
}
],
"collections": [
{
"id": 1234
},
{
"title": "A new collection"
}
]
}
- title
- Product title. optional.
- price
- Product price in cents (integer, no punctuation). Optional.
- price_comparison
- “Price before”, in cents (integer, no punctuation). Optional.
- description:
- Product description. Optional.
- status
- Product status (“visible” or “hidden”). Optional, default “hidden”.
- product_type_name
- Name for new or existing product type. If new it will be created. Optional.
- collections
- Array of collections with “id” or “title”. New ones (with only “title”) will be created. Optional.
- tags
- Array of tag names. New ones will be created. Optional.
- vendor
- Vendor name. It will be created it it doesn’t exist. Optional.
- variants
- Array of variant objects. It will delete any existing variants not present in this array (except the default variant).
You can use an empty array to clear all variants. Optional. - _policies
- Object of policy directives that change the default behaviour. Ex. use
keep_variants: true
if you don’t want thevariants
array to delete existing variants in the product. - custom_attributes:
- Array of custom attributes. It will delete any existing attributes not present in this array.Attributes will be updated by name, or new ones created.
You can use an empty array to clear all custom attributes.
variant
- id
- The ID for a variant to update inline. If missing the variant will be found by slug, name, or a new one created.
- title
- Variant title. Required.
- sku
- SKU code, optional. Must be unique in the product’s shop.
- available_if_no_stock
- Variant availability policy.
0
for unavailable if out of stock.1
for always available. Default1
- stock
- Variant stock number. Default
1
. - weight_in_grams
- Variant weight in grams, no punctuation. Optional.
Collection
- title
- Collection title. Pass this if you want to create and assign a new collection to the product.
- id
- Collection unique ID. Pass this to assign an existing collection in your shop to a product.
Custom attribute
- name
- The attribute’s name, ex. “Colour”, “Material”, etc.
- value
- The attribute’s value, ex. “red”
- field_type
- One of “string”, “email”, “url”, “int”, “boolean”. Default “string”.
- required
- Required field boolean. Default
false
Successful response
When an existing product has been updated, the response has a code of 200
.
Existing product
Status: 200 OK
Content-Type: application/json; charset=utf-8
Connection: keep-alive
ETag: "0728e2965bd03e20a7f1c33add2f8775"
Last-Modified: Fri, 20 Jun 2014 22:34:14 GMT
Cache-Control: must-revalidate, private, max-age=0
Date: Wed, 31 Jul 2013 21:11:52 GMT
X-OAuth-Scopes: admin
{
"_links": {
"btc:web": {
"href": "http://www.bootic.net/products/producto-de-ejemplo-de-bootic",
"type": "text/html",
"title": "Web page for this product on its original shop front-end"
},
"self": {
"href": "https://api.bootic.net/v1/products/1234"
},
"btc:update_product": {
"href": "https://api.bootic.net/v1/shops/47/products/1234",
"title": "Update this product",
"method": "put"
},
"btc:delete_product": {
"href": "https://api.bootic.net/v1/products/1234",
"title": "Delete this product",
"method": "delete"
},
"btc:create_variant": {
"href": "https://api.bootic.net/v1/products/1234",
"method": "post",
"title": "Create a product variant"
},
"btc:create_product_asset": {
"href": "https://api.bootic.net/v1/products/1234/assets",
"method": "post",
"title": "Create a product asset"
}
},
"id": "producto-de-ejemplo-de-bootic",
"title": "Producto de ejemplo de Bootic",
"status": "visible",
"vendor": "Bootic",
"description": "Este es un producto de ejemplo en Bootic. Puedes editarlo, agregarle información, o bien borrarlo y empezar desde cero. Bienvenido!",
"price": 900,
"price_comparison": 1000,
"discount_percentage": 10.0,
"currency_code": "CLP",
"tags": [
"tag1",
"tag2"
],
"created_on": "2009-12-12T23:05:49.000Z",
"updated_on": "2012-09-01T19:44:40.000Z",
"_embedded": {
"shop": {
"_links": {
"self": {
"href": "https://api.bootic.net/v1/shops/47"
}
},
"id": "47",
"name": "Bootic",
"subdomain": "www",
"url": "www.bootic.net"
},
"variants": [
{
"_links": {
"btc:update_variant": {
"href": "http://api.bootic.net/v1/shops/455/product-de-ejemplo-de-bootic/variants/6440",
"method": "put"
},
"btc:delete_variant": {
"href": "http://api.bootic.net/v1/shops/455/product-de-ejemplo-de-bootic/variants/6440",
"method": "delete"
}
},
"title": "Default",
"id": 6440,
"stock": 1,
"available_if_no_stock": true,
"sku": null,
"weight_in_grams": 0,
"price": 900,
"price_comparison": 1000
}
],
"collections": [
{
"title": "Catálogo",
"id": 897,
"shop_id": 47,
"slug": "catalogo"
}
],
"custom_attributes": [
{
"id": 123433,
"name": "Colour",
"value": "red",
"field_type": "string",
"required": true,
"key": "colour"
}
],
"images": [
{
"_links": {
"thumbnail": {
"href": "https://o.btcdn.co/47/thumbnail/8848-Photo_2.jpg"
},
"small": {
"href": "https://o.btcdn.co/47/small/8848-Photo_2.jpg"
},
"medium": {
"href": "https://o.btcdn.co/47/medium/8848-Photo_2.jpg"
},
"large": {
"href": "https://o.btcdn.co/47/large/8848-Photo_2.jpg"
},
"original": {
"href": "https://o.btcdn.co/47/original/8848-Photo_2.jpg"
}
},
"file_name": "Photo_2.jpg",
"title": "test"
}
]
}
}
New product
When passing a “slug” instead of an “id”, if a product for that slug doesn’t exist, a new product will be created and the response will have a 201
code.
Example for or updating a product with slug “iphone-5”:
PUT https://api.bootic.net/v1/shops/123/products/iphone-5
Status: 201 Created
Content-Type: application/json; charset=utf-8
Connection: keep-alive
ETag: "0728e2965bd03e20a7f1c33add2f8775"
Last-Modified: Fri, 20 Jun 2014 22:34:14 GMT
Cache-Control: must-revalidate, private, max-age=0
Date: Wed, 31 Jul 2013 21:11:52 GMT
X-OAuth-Scopes: admin
// Same response as above
Invalid response
Status: 422 Unprocessable Entity
Content-Type: application/json; charset=utf-8
Connection: keep-alive
ETag: "0728e2965bd03e20a7f1c33add2f8775"
Last-Modified: Fri, 20 Jun 2014 22:34:14 GMT
Cache-Control: must-revalidate, private, max-age=0
Date: Wed, 31 Jul 2013 21:11:52 GMT
X-OAuth-Scopes: admin
{
"_class": [
"errors",
"product"
],
"_embedded": {
"errors": [
{
"_class": [
"error"
],
"field": "product.title",
"messages": [
"can't be blank"
]
}
]
}
}
Examples
You can use partial request bodies to update partial attributes of a product. Attributes missing from the payload means that you don’t want to modify them.
{
"title": "iPhone 5 - White",
"price": 2300
}
Attributes that expect and array can be used to update, replace of delete elements. The following removes all custom attributes:
{
"custom_attributes": [
]
}
This will replace custom attributes with new ones:
{
"custom_attributes": [
{
"name": "Colour",
"value": "blue"
},
{
"name": "Size",
"value": "XL"
}
]
}
Existing elements are matched and updated in-place:
{
"custom_attributes": [
{
"name": "Colour",
"value": "green"
},
{
"name": "Size",
"value": "XL"
}
]
}
The “Colour” attribute will have its value updated. “Size” will be untouched.
This example updates the stock for a an existing variant with id
“1234” and creates a new variant named “Leather”.
{
"variants": [
{
"id": 1234,
"stock": 4
},
{
"title": "Leather",
"stock": 20,
"available_if_not_stock": 0
}
]
}