Search For Orders

Search for orders using a customerOrderId.

Overview

This request requires an access token with “orders/carts-read” scope. If the request is successful and one or more Orders are found, a 200 OK response will be returned including a list of the Orders in the response body. If no results are found, a 204 No Content response will be returned. If there is a problem with any of the query parameters, a 400 Bad Request response will be returned with an explanation of the error in the X-Reason header.

URI

GET: https://rest.bronto.com/orders?cartId={cartId}&customerOrderId={customerOrderId}&startDate={startDate}&endDate={endDate}

Parameters

Note: You need to include at least one parameter in your call.
Parameter Type Description
cartId Optional string The unique identifier of an associated cart.
customerOrderId Optional string The customer’s ID that is associated with the order.
startDate Optional dateTime The start date for your search.
endDate Optional dateTime The end date for your search.

Response Body

A response containing a list of the orders found, if any.

[
  {
    emailAddress:validly formatted email address
    contactId:string
    orderDate:ISO-8601 datetime
    status:PENDING | PROCESSED
    hasTracking:boolean
    trackingCookieName:string
    trackingCookieValue:string
    deliveryId:string
    customerOrderId: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
      }
    ]
    messageId:string
    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
    states: {
      processed:boolean
      shipped:boolean
    }
    orderId:UUID
  }
]

Java Code Example

import java.util.Collections;
import java.util.List;
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 SearchForOrdersExample {
 
  // 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 SEARCH_ORDERS_PATH = "orders";
  private static final String CUSTOMER_ORDER_ID = "customerOrderId";
 
  // 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 Order we are searching for
  private static final String EXAMPLE_CUSTOMER_ORDER_ID = "abc-123";
 
 
  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 search for Orders
    Response orderResponse = client.target(BRONTO_HOST)
        .path(SEARCH_ORDERS_PATH)
        .queryParam(CUSTOMER_ORDER_ID, EXAMPLE_CUSTOMER_ORDER_ID)
        .request(MediaType.APPLICATION_JSON)
        .header("Authorization", "Bearer " + accessToken.toString())
        .get();
 
    // Get Orders from the response
    List<Map<String, Object>> orders = null;
    if (orderResponse.getStatus() == Response.Status.OK.getStatusCode()) {
      orders = orderResponse.readEntity(List.class);
    } else if (orderResponse.getStatus() == Response.Status.NO_CONTENT.getStatusCode()) {
      orders = Collections.EMPTY_LIST;
    } else {
      String reason = orderResponse.getHeaderString(REASON_HEADER);
      throw new RuntimeException("Unable to search for Orders. Reason=" + reason);
    }
 
    System.out.println(orders);
  }
}

cURL Example

# Run the following cURL command after replacing YOUR_ID and YOUR_SECRET with the values from your REST Integration.
curl -X POST -d "grant_type=client_credentials&client_id=YOUR_ID&client_secret=YOUR_SECRET" https://auth.bronto.com/oauth2/token
	      
# Replace YOUR_ACCESS_TOKEN with your returned token and replace YOUR_CUSTOMER_ORDER_ID with a customer order ID.
curl -i -X GET -H "Content-type: application/json" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Cache-Control: no-cache" https://rest.bronto.com/orders?customerOrderId=YOUR_CUSTOMER_ORDER_ID