Get Products

This returns the complete set of data stored in Bronto for each product matching the given Product IDs in the call.

Overview

If none of the listed products are found, a 404 error code is returned.

URI

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

Parameters

Parameter Type Description
productIds Required A list of the Product IDs you want to get data for. For example: /products/public/products?productIds=X&productIds=X
fieldNames Optional You can filter the data that is returned by specifying which product fields you want to get information about. The list of valid fields can be found on the Product Fields page in the BMP. If you do not include any fieldNames then all of the data for the product is returned. For example:

/products/public/catalogs/{catalogId}/products

Response

[
{
    id:string,
    fields:[
        {
            name:string,
            value:object,
            id:number,
            type:string
        }
    ]
},{
    id:string,
    fields:[
        {
            name:string,
            value:object,
            id:number,
            type:string
        }
    ]
}
]

Python Code Example

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"
session = requests.Session()
session.headers["Authorization"] = "Bearer " + bronto_access_token
 
catalog_id = your catalog ID here
 
 
# get multiple products with all of their fields
product_id_1 = "product-0001"
product_id_2 = "product-0002"
 
url_fmt = "https://rest.bronto.com/products/public/catalogs/{catalog_id}/products"
url = url_fmt.format(catalog_id=catalog_id)
url += "?productIds=" + product_id_1 + "&productIds=" + product_id_2
 
response = session.get(url)
 
if response.ok:
    products = response.json()
    print("Products with all fields:", products)
else:
    print("Could not get products (status code={}, content='{}', headers={})".format(
        response.status_code, response.text, response.headers
    ))
 
 
# get multiple products with only some of their fields
url += "&fieldNames=price&fieldNames=quantity"
 
response = session.get(url)
 
if response.ok:
    products = response.json()
    print("Products with only price and quantity fields:", products)
else:
    print("Could not get products (status code={}, content='{}', headers={})".format(
        response.status_code, response.text, response.headers
    ))

Java Code Example

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.List;
import java.util.Map;
 
public class GetProducts {
 
    // - 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";
 
    // Replace with your product IDs
    private static final List<String> PRODUCT_IDS = Arrays.asList("test_id_1", "test_id_2");
 
    //OPTIONAL: Field name parameters limit the fields returned in the call.
    // If you pass in no field name parameters, ALL fields will be returned.
    private static final List<String> FIELDS = Arrays.asList("title", "description");
 
    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 Get Products code --------------------------------------------------------------------------
 
        // Build the URL
        UriBuilder builder = UriBuilder.fromUri(BRONTO_REST_HOST)
                .path(RELATIVE_ENDPOINT_PATH)
                .resolveTemplate("catalogId", CATALOG_ID);
 
        // Add product id query parameters
        for (String productId : PRODUCT_IDS) {
            builder.queryParam("productIds", productId);
        }
 
        // Add optional field name query parameters
        for (String field : FIELDS) {
            builder.queryParam("fieldNames", field);
        }
 
        URI uri = builder.build();
 
        //Create and execute the authorized get request
        Response productResponse = client.target(uri)
                .request(MediaType.APPLICATION_JSON)
                .header("Authorization", "Bearer " + accessToken)
                .get();
 
        // Retrieve the Product from the response
        String product = productResponse.readEntity(String.class);
        System.out.println(product);
    }
 
}