Get Product

The products GET function where an individual product id is included returns the complete set of data stored in Bronto for the product matching the given product id in the function call.

Overview

If it is not found, a 404 error code is returned.

URI

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

Parameters

Parameter Type Description
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/{productId}

Response

{
    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 a single product with all of its fields
product_id_1 = "product-0001"
 
url_fmt = "https://rest.bronto.com/products/public/catalogs/{catalog_id}/products/{product_id}"
url = url_fmt.format(catalog_id=catalog_id, product_id=product_id_1)
 
response = session.get(url)
 
if response.ok:
    product = response.json()
    print("Product with all fields:", product)
else:
    print("Could not get product " + product_id_1 + " (status code={}, content='{}', headers={})".format(
        response.status_code, response.text, response.headers
    ))
 
 
# get a single product but only some of its fields
url += "?fieldNames=price&fieldNames=quantity"
 
response = session.get(url)
 
if response.ok:
    product = response.json()
    print("Product with only price and quantity fields:", product)
else:
    print("Could not get product " + product_id_1 + " (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 GetProduct {
 
    // - 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/{productId}";
 
    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 ID
    private static final String PRODUCT_ID = "test_id_123";
 
    //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 Product code ---------------------------------------------------------------------------
 
        // Build the URL
        UriBuilder builder = UriBuilder.fromUri(BRONTO_REST_HOST)
                .path(RELATIVE_ENDPOINT_PATH)
                .resolveTemplate("catalogId", CATALOG_ID)
                .resolveTemplate("productId", PRODUCT_ID);
 
        // 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);
    }
 
}