Get Cart

View the contents of a cart using a cart’s ID.

Overview

This request requires an access token with “orders/carts-write” scope. If the request is successful, a 201 Created response will be returned with the newly created Cart in the response body. If a Cart with the same customerCartId already exists, a 409 Conflict response will be returned.

URI

GET: https://rest.bronto.com/carts/{cartId}?deliveryId={deliveryId}&messageId={messageId}&contactId={contactId}

Parameters

Parameter Type Description
cartId Required String The unique identifier of the cart.
deliveryId Optional String The unique identifier for a single delivery of a message associated with the order. You can use readDeliveries to return deliveryId as part of the deliveryObject.
messageId Optional String The unique identifier for a single message associated with the order. You can use readMessages to return messageId as part of the messageObject.
contactId Optional String The unique identifier for a contact associated with the order. You can use readContacts or readContactsWithLatestUnsubscribeDateto return contactId as part of the contactObject.

Response

{
    url:string
    emailAddress:validly formatted email address
    status:ACTIVE | ABANDONED | EXPIRED | COMPLETE
    phase:SHOPPING | BILLING | PAYMENT | SHIPPING_INFO | SHIPPING_METHOD | ORDER_REVIEW | ORDER_COMPLETE
    hasTracking:boolean
    customerCartId:string
    trackingCookieName:string
    trackingCookieValue:string
    discountAmount:number
    grandTotal:number
    lineItems:[
      {
        name:string
        other:string
        sku:string
        category:string
        imageUrl:string
        productUrl:string
        quantity:number
        salePrice:number
        totalPrice:number
        unitPrice:number
        description:string
        position:number
      }
    ]
    originIp: IPv4 or IPv6 address
    originUserAgent:string
    shippingAmount:number
    shippingDate: ISO-8601 datetime
    shippingDetails:string
    shippingTrackingUrl:string
    subtotal:number
    taxAmount:number
    cartId:UUID
    createdDate:ISO-8601 datetime
    updatedDate:ISO-8601 datetime
    currency:ISO-4217 currency code
}

Java Code Example

import java.util.Map;
import java.util.UUID;
 
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;
 
 
public class GetCartExample {
 
  // Host
  private static final String BRONTO_HOST = "http://rest.bronto.com";
  private static final String BRONTO_AUTH_PATH = "https://auth.bronto.com/oauth2/token";
 
  // Paths
  private static final String GET_CART_PATH = "carts/{cartId}";
  private static final String CART_ID = "cartId";
 
  // OAuth Request property names
  private static final String GRANT_TYPE = "grant_type";
  private static final String CLIENT_ID = "client_id";
  private static final String CLIENT_SECRET = "client_secret";
 
  // OAuth Request property values
  private static final String CLIENT_CREDENTIALS = "client_credentials";
  private static final String EXAMPLE_CLIENT_ID = "XXXXXXXXXXXXXXXXXXXXXXX";
  private static final String EXAMPLE_CLIENT_SECRET = "XXXXXXXXXXXXXXXXXXXXXXX";
 
  private static final String ACCESS_TOKEN = "access_token";
 
  private static final String REASON_HEADER = "X-Reason";
 
  // Id of the Cart we are getting
  private static final String EXAMPLE_CART_ID = "7255c31c-39ac-4611-a2b7-974b0ebfa555";
 
 
  public static void main(String[] args) {
    Client client = ClientBuilder.newClient();
 
    // To be able to access Orders 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, EXAMPLE_CLIENT_ID);
    requestData.param(CLIENT_SECRET, EXAMPLE_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);
    UUID accessToken = UUID.fromString((String) responseData.get(ACCESS_TOKEN));
 
    // Now to get the Cart
    Response cartResponse = client.target(BRONTO_HOST)
        .path(GET_CART_PATH)
        .resolveTemplate(CART_ID, EXAMPLE_CART_ID)
        .request(MediaType.APPLICATION_JSON)
        .header("Authorization", "Bearer " + accessToken.toString())
        .get();
 
    if (cartResponse.getStatus() == Response.Status.NOT_FOUND.getStatusCode()) {
      throw new RuntimeException("No Cart found with cartId=" + EXAMPLE_CART_ID);
    } else if (cartResponse.getStatus() != Response.Status.OK.getStatusCode()) {
      String reason = cartResponse.getHeaderString(REASON_HEADER);
      throw new RuntimeException("Unable to get Cart. Reason=" + reason);
    }
 
    // Retrieve the Cart from the response
    Map<String, Object> cart = cartResponse.readEntity(Map.class);
    System.out.println(cart);
  }
}