Update Products

Allows synchronous batch updates to the products in your catalog. Accepts an array of product update entities, which must contain all the fields (field name : field value) in the product. Normal validation of the product field values will be applied, and individual products updates will be rejected if they fail validation. An array of String errors will be returned for each product that is not updated.

Note: You cannot add new products or archive old using this endpoint. Those updates must be done via a full feed import.

Results of these updates do not trigger email notifications or the creation of a new record in Bronto on the Product Import History page. You will however see changes represented in the Products Search results. To see errors that have occurred with specific product updates, you must view the responses to the API calls.

PUT: https://rest.bronto.com/products/public/catalogs/{catalogId}/products

Request Body

[
    {
        "fields": {
        "product_id": "product-0002",
        "parent_product_id": None,
        "product_url": "http://mysite.com/products/0002",
        "title": "Product 0002 title",
        "description": "Product 0002 description",
        "price": "27.00 USD",
        "quantity": 25,
        "image_url": "http://mysite.com/products/0002.png",
        "additional_images": None,
        "rating": 3.9,
        "inventory_threshold": 5,
        "availability": "Available",
        "availability_date": "",
        "product_category": "Miscellaneous",
        "sale price effective date": "2010-01-10T00:00-0100/2020-01-10T00:00-0100",
        "tax": "US:1111:8.75, US:1111:7.75",
        "gender": "Male",
        "color": "Green",
        "size": "M",
        }
    },
    {
        "fields": {
        "product_id": "product-0002",
        "parent_product_id": None,
        "product_url": "http://mysite.com/products/0002",
        "title": "Product 0002 title",
        "description": "Product 0002 description",
        "price": "27.00 USD",
        "quantity": 25,
        "image_url": "http://mysite.com/products/0002.png",
        "additional_images": None,
        "rating": 3.9,
        "inventory_threshold": 5,
        "availability": "Available",
        "availability_date": "",
        "product_category": "Miscellaneous",
        "sale price effective date": "2010-01-10T00:00-0100/2020-01-10T00:00-0100",
        "tax": "US:1111:8.75, US:1111:7.75",
        "gender": "Male",
        "color": "Green",
        "size": "M",
        }
    }
]

Response

[
"ERROR - id=1 - The following mapped fields were not present in the product: rating",
"ERROR - id=5 - The following mapped fields were not present in the product: margin"
]

Code Samples

from __future__ import print_function
 
# Requests documentation:  http://docs.python-requests.org/
import requests
 
 
# API authorization
bronto_access_token = "a valid rest api access token"
headers = {"Authorization": "Bearer " + bronto_access_token}
 
catalog_id = "your catalog ID here"
 
 
# update multiple products
update_request_1 = {
    "fields": {
        "product_id": "product-0001",
        "parent_product_id": "None",
        "product_url": "http://mysite.com/products/0001",
        "title": "Product 0001 title",
        "description": "Product 0001 description",
        "price": "11.00 USD",
        "quantity": 47,
        "image_url": "http://mysite.com/products/0001.png",
        "additional_images": "None",
        "rating": 4.5,
        "inventory_threshold": 5,
        "availability": "Available",
        "availability_date": "",
        "product_category": "Miscellaneous",
        "sale price effective date": "2010-01-10T00:00-0100/2020-01-10T00:00-0100",
        "tax": "US:1111:8.75, US:1111:7.75",
        "gender": "Male",
        "color": "Blue",
        "size": "XL"
    }
}
 
update_request_2 = {
    "fields": {
        "product_id": "product-0002",
        "parent_product_id": "None",
        "product_url": "http://mysite.com/products/0002",
        "title": "Product 0002 title",
        "description": "Product 0002 description",
        "price": "27.00 USD",
        "quantity": 25,
        "image_url": "http://mysite.com/products/0002.png",
        "additional_images": "None",
        "rating": 3.9,
        "inventory_threshold": 5,
        "availability": "Available",
        "availability_date": "",
        "product_category": "Miscellaneous",
        "sale price effective date": "2010-01-10T00:00-0100/2020-01-10T00:00-0100",
        "tax": "US:1111:8.75, US:1111:7.75",
        "gender": "Male",
        "color": "Green",
        "size": "M"
    }
}
 
url_fmt = "https://rest.bronto.com/products/public/catalogs/{catalog_id}/products"
url = url_fmt.format(catalog_id=catalog_id)
 
update_requests = [update_request_1, update_request_2]
response = requests.put(url, json=update_requests, headers=headers)
 
if response.ok:
    if response.content:
        # some errors or warnings are given
        messages = response.json()
 
        for message in messages:
            print(message)
    else:
        print("Products update successfully (no messages returned)")
else:
    print("Could not update products (status code {}, content='{}', headers={})".format(
        response.status_code, response.text, response.headers
    ))
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
public class UpdateProducts {
 
    // - Do not change ------------------------------------------------------------------------------------------------
    private static final String BRONTO_REST_HOST = "https://rest.bronto.com";
    private static final String RELATIVE_ENDPOINT_PATH = "products/public/catalogs/{catalogId}/products";
 
    private static final String BRONTO_AUTH_PATH = "https://auth.bronto.com/oauth2/token";
    //-----------------------------------------------------------------------------------------------------------------
 
    // Modify the below values for your specific site and catalog
 
    // Replace the below OAuth Request property values with your site specific credentials
    private static final String CLIENT_ID = "1234567890";
    private static final String CLIENT_SECRET = "0987654321";
 
    // Replace with your catalog ID
    private static final String CATALOG_ID = "1";
 
    // Simple class to represent a product update
    private static class UpdateProduct {
 
        private Map<String, Object> fields;
 
        public Map<String, Object> getFields() {
            return fields;
        }
 
        public void setFields(Map<String, Object> fields) {
            this.fields = fields;
        }
    }
 
    public static void main(String[] args) {
 
        Client client = ClientBuilder.newClient();
 
        // To be able to access Any Bronto Rest API, you need an access token.
        // First, we build the request data needed to gain an access token
        Form requestData = new Form();
        requestData.param("grant_type", "client_credentials");
        requestData.param("client_id", CLIENT_ID);
        requestData.param("client_secret", CLIENT_SECRET);
 
        // Then build and send the request
        Response oauthResponse = client.target(BRONTO_AUTH_PATH)
                .request(MediaType.APPLICATION_JSON)
                .accept(MediaType.TEXT_PLAIN_TYPE)
                .post(Entity.form(requestData));
 
        if (oauthResponse.getStatus() != Response.Status.OK.getStatusCode()) {
            throw new RuntimeException("Unable to get access token.");
        }
 
        // Retrieve the access token from the response
        Map<String, Object> responseData = oauthResponse.readEntity(Map.class);
        String accessToken = (String) responseData.get("access_token");
 
        // Here begins the Update Product code ------------------------------------------------------------------------
 
        // Create and populate some products update objects
        Map<String, Object> productFields_1 = new HashMap<String, Object>();
        productFields_1.put("sku", "PRO_0067");
        productFields_1.put("parent", "PAR_0007");
        productFields_1.put("margin", 100.0);
        productFields_1.put("product_url", "http://bronto.com");
        productFields_1.put("title", "Windbreaker Jacket");
        productFields_1.put("description", "The Bronto windbreaker is perfect for those windy, rainy days.");
        productFields_1.put("price", "49.00 USD");
        productFields_1.put("quantity", 0.0);
        productFields_1.put("image_url", "http://brontogear.com/windbreaker.jpg");
        productFields_1.put("additional_images", null);
        productFields_1.put("rating", 4.6);
        productFields_1.put("reviews", 10);
        productFields_1.put("inventory_threshold", 1);
        productFields_1.put("availability", "Out of Stock");
        productFields_1.put("product_category", "Miscellaneous");
        productFields_1.put("Sale_Price_Effective_Date", null);
        productFields_1.put("sale_price", 39.95);
        productFields_1.put("gender", "Unisex");
        productFields_1.put("color", "Black");
        productFields_1.put("size", "M");
 
        Map<String, Object> productFields_2 = new HashMap<String, Object>();
        productFields_2.put("sku", "PRO_0068");
        productFields_2.put("parent", null);
        productFields_2.put("margin", 10.0);
        productFields_2.put("product_url", "http://bronto.com");
        productFields_2.put("title", "Backpack");
        productFields_2.put("description", "The Bronto backpack is great for holding just about anything.");
        productFields_2.put("price", "79.00 USD");
        productFields_2.put("quantity", 10.0);
        productFields_2.put("image_url", "http://brontogear.com/backpack.jpg");
        productFields_2.put("additional_images", null);
        productFields_2.put("rating", 4.4);
        productFields_2.put("reviews", 65);
        productFields_2.put("inventory_threshold", 5);
        productFields_2.put("availability", "In Stock");
        productFields_2.put("product_category", "Miscellaneous");
        productFields_2.put("Sale_Price_Effective_Date", null);
        productFields_2.put("sale_price", 69.95);
        productFields_2.put("gender", "Unisex");
        productFields_2.put("color", "Green");
        productFields_2.put("size", null);
 
        UpdateProduct product1 = new UpdateProduct();
        UpdateProduct product2 = new UpdateProduct();
        product1.setFields(productFields_2);
        product2.setFields(productFields_2);
 
        List<UpdateProduct> updateProductRequests = Arrays.asList(product1, product2);
 
        // Build the URL
        URI uri = UriBuilder.fromUri(BRONTO_REST_HOST)
                .path(RELATIVE_ENDPOINT_PATH)
                .resolveTemplate("catalogId", CATALOG_ID)
                .build();
 
        //Create and execute the authorized get request
        Response productResponse = client.target(uri)
                .request(MediaType.APPLICATION_JSON)
                .header("Authorization", "Bearer " + accessToken)
                // Convert the request into JSON and call the PUT endpoint
                .put(Entity.json(updateProductRequests));
 
        // Retrieve the response
        String product = productResponse.readEntity(String.class);
        System.out.println(product);
    }
 
}


Was this article helpful?

Not HelpfulHelpful (No Ratings Yet)
Loading...

We welcome your feedback!

Please let us know how this article could be improved.
*Name and Email are optional fields.