Delete Order

Deletes an order with the given Bronto-generated order id.

Overview

If you want to update an order using the order ID generated by your system, use Delete Order By Customer Order Id instead.

This request requires an access token with “orders/carts-write” scope. A 204 No Content response will always be returned.

URI

DELETE: https://rest.bronto.com/orders/{orderId}

Parameters

Parameter Type Description
orderId Required String The Bronto-generated unique order ID of the order to be deleted.

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 DeleteOrderExample {
 
  // 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 DELETE_ORDER_PATH = "orders/{orderId}";
  private static final String ORDER_ID = "orderId";
 
  // 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 deleting
  private static final String EXAMPLE_ORDER_ID = "0ad24370-96de-4922-9a53-954530fcbb64";
 
 
  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 delete the Order
    Response orderResponse = client.target(BRONTO_HOST)
        .path(DELETE_ORDER_PATH)
        .resolveTemplate(ORDER_ID, EXAMPLE_ORDER_ID)
        .request(MediaType.APPLICATION_JSON)
        .header("Authorization", "Bearer " + accessToken.toString())
        .delete();
 
    if (orderResponse.getStatus() != Response.Status.NO_CONTENT.getStatusCode()) {
      String reason = orderResponse.getHeaderString(REASON_HEADER);
      throw new RuntimeException("Unable to delete Order. Reason=" + reason);
    }
  }
}

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_ORDER_ID with a real order ID.
curl -X DELETE -H "Content-type: application/json" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Cache-Control: no-cache" https://rest.bronto.com/orders/YOUR_ORDER_ID