Fiddle Cart

Fiddle a cart with the given id.

Overview

When a cart is fiddled, the Bronto Marketing Platform is notified that the customer’s cart is still ACTIVE and will reset the cart activity timer used by Bronto’s cart abandonment feature. If the cart had previously been abandoned and the customer returns to the website, the fiddle will reset the cart’s status to ACTIVE.

This request requires an access token with “orders/carts-write” scope. If the request is successful, a 204 No Content response will be returned. If no Cart can be found with the given cartId, a 404 Not Found response will be returned. If the Cart’s status is EXPIRED or COMPLETE, a 409 Conflict response will be returned.

URI

PUT: https://rest.bronto.com/carts/{cartId}/fiddle

Parameters

Parameter Type Description
cartId Required String The unique ID of the cart.

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 FiddleCartExample {
 
  // 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 FIDDLE_CART_PATH = "carts/{cartId}/fiddle";
  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 fiddling
  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 fiddle the Cart
    Response cartResponse = client.target(BRONTO_HOST)
        .path(FIDDLE_CART_PATH)
        .resolveTemplate(CART_ID, EXAMPLE_CART_ID)
        .request(MediaType.APPLICATION_JSON)
        .header("Authorization", "Bearer " + accessToken.toString())
        .put(Entity.json(""));  // No body needed
 
    if (cartResponse.getStatus() != Response.Status.NO_CONTENT.getStatusCode()) {
      String reason = cartResponse.getHeaderString(REASON_HEADER);
      throw new RuntimeException("Unable to fiddle Cart. Reason=" + reason);
    }
  }
}