Import Product Data Feed

The feed_import function allows you to import a new product feed into Bronto.

Overview

The feed file imported should represent your entire product data, as any products previously imported not submitted in this feed will be archived. This function is a multi-part form data endpoint that accepts incoming product feeds for asynchronous processing, and returns a transaction UUID. Any valid feed file that you can import via the Product Service inside of the BMP is acceptable input.

Important: Your product feed file cannot contain more than 3 million products.

URI

POST: https://rest.bronto.com/products/public/feed_import

Parameters

Parameter Type Description
catalogId Required ID Your catalog id. This ID can be found on the Products Overview page in the BMP, located on the bottom-right part of the page. It is titled “Products API ID”.
feed Required The file that is being uploaded

Response

Transaction UUID

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"
headers = {"Authorization": "Bearer " + bronto_access_token}
 
# import feed
feed_filepath = "my_products_feed.csv"
catalog_id = "your catalog ID here"
 
with open(feed_filepath, "rb") as feed_file:
    files = {
        "feed": feed_file,
        "catalogId": str(catalog_id)
    }
 
    url = "https://rest.bronto.com/products/public/feed_import"
    response = requests.post(url, files=files, headers=headers)
 
# check response
if response.ok:
    print("New feed import ID is", response.text)
else:
    print("Could not import feed (status code={}, content='{}', headers={})".format(
        response.status_code, response.text, response.headers
    ))

Java Code Example

import org.glassfish.jersey.media.multipart.FormDataMultiPart;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
 
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.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
 
public class ImportFeed {
 
    // - Do not change ------------------------------------------------------------------------------------------------
    private static final String BRONTO_REST_HOST = "https://rest.bronto.com";
    private static final String RELATIVE_ENDPOINT_PATH = "products/public/feed_import";
 
    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 path to your feed file
    private static final String FEED_FILE_PATH = "/path/to/feed/file";
 
    public static void main(String[] args) {
 
        Client client = ClientBuilder.newClient();
        client.register(MultiPartFeature.class);
 
        // 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 Import Product Feed code ---------------------------------------------------------------------------
 
        FormDataMultiPart formDataMultiPart = null;
 
        // Build the URL
        URI uri = UriBuilder.fromUri(BRONTO_REST_HOST)
                .path(RELATIVE_ENDPOINT_PATH)
                .build();
 
        try {
            formDataMultiPart = new FormDataMultiPart();
            formDataMultiPart.field("catalogId", CATALOG_ID);
            formDataMultiPart.bodyPart(new FileDataBodyPart("feed", new File(FEED_FILE_PATH)));
 
            //Create and execute the authorized post request
            Response response = client.target(uri)
                    .request(MediaType.MULTIPART_FORM_DATA_TYPE)
                    .accept(MediaType.TEXT_PLAIN_TYPE)
                    .header("Authorization", "Bearer " + accessToken)
                    .post(Entity.entity(formDataMultiPart, formDataMultiPart.getMediaType()));
 
            // Retrieve the Feed UUID and the returned status code from the response
            String output = response.readEntity(String.class);
            System.out.println(output);
            System.out.println(response.getStatus());
 
        } finally {
            // Make sure you've closed everything
            if (formDataMultiPart != null) {
                try {
                    formDataMultiPart.close();
                } catch (IOException e) {
                    // Handle IOException
                    System.out.println("Oops: " + e.getStackTrace());
                }
            }
        }
    }
 
}