Order methods supported on the Merchant API

The following methods operate on the Order data model.

GET http://api.cratejoy.com/v1/orders/
GET http://api.cratejoy.com/v1/orders/{order_id}
PUT http://api.cratejoy.com/v1/orders/{order_id}/
POST http://api.cratejoy.com/v1/orders/

List orders

GET http://api.cratejoy.com/v1/orders/
$.ajax({     
  url: 'https://api.cratejoy.com/v1/orders/',
  method: 'GET'
});
$.ajax({     
  url: 'https://api.cratejoy.com/v1/orders/?placed_at__gt=2017-03-15T20:00:24Z',
  method: 'GET'
})
{
  "count": 1, 
  "next": null, 
  "prev": null, 
  "results": [
    {
      "card_refunded_amount": 0,
      "credit_applied": 0,
      "customer": [{/*...*/}], // Customer relation property
      "customer_id": 586402305,
      "financial_status": "paid",
      "fulfillment_status": "fulfilled",
      "gift_card_discount": 0,
      "gift_message": "",
      "gift_renewal_notif": false,
      "gross_shipping": 0,
      "id": 730837920,
      "is_gift": true,
      "order_gift_info": {
				"gift_message": "I bought you a nice new sweater!",
        "gift_recipient_name": "Mr. Rogers",
        "gift_recipient_email": "[email protected]"
      },
      "is_renewal": false,
      "is_test": true,
      "note": null,
      "placed_at": "2017-03-20T22:59:40Z",
      "products": [{/*...*/}], /// Products relation property
      "prorated_charge": null,
      "refund_applied": null,
      "refunded_amount": 0,
      "status": "closed",
      "store_id": 644263166,
      "sub_total": 3500,
      "total": 3500,
      "total_app_fees": null,
      "total_label_cost": null,
      "total_pending_fees": null,
      "total_price": 3500,
      "total_shipping": 0,
      "total_tax": 0,
      "transaction_fee": 0,
      "transaction_fee_status": null,
      "type": "order",
      "url": "/v1/orders/730837920/"
    }

Get an order

GET http://api.cratejoy.com/v1/orders/{order_id}
$.ajax({     
  url: 'https://api.cratejoy.com/v1/orders/75572230/',
  method: 'GET'
});

Update an order

PUT http://api.cratejoy.com/v1/orders/{order_id}/
$.ajax({
    url: 'https://api.cratejoy.com/v1/orders/75572230/',
   	method: 'PUT', 
    data: {
      note: "Drop package off at the front office"
    }
});
$.ajax({
    url: 'https://api.cratejoy.com/v1/orders/75572230/',
   	method: 'PUT', 
    data: {
      order_gift_info: { gift_message: "Hi, I got you this gift." }
    }
});

For a complete list of editable properties see the Order data model .

Create an order

POST http://api.cratejoy.com/v1/orders/

Create an order

Customer requirements

  • Customer must already exist
    • Use JSON filters to identify the customer
    • In most cases, this will be the id but could using full filter syntax
    • Filters MUST unambiguously identify ONE customer
  • Customer must have a payment method already established.

Product Requirements

  • Include the subscription's product_instance ID
  • Include the subscription's term id or name/num_cycles. name indicates how often the customer is shipped a shipment, and num_cycles indicates the number of cycles the customer has prepaid. The term and number of cycles must be valid if the product is a subscription product. Term should not be provided for one-time products.

To prevent accidental duplicate charges, you cannot create an order for a customer who already has one from the past minute.

If you include an order_gift_info section, the order will automatically be set as a gift.

$.ajax({
    url: 'https://api.cratejoy.com/v1/orders/',
    method: 'POST',
    data: {
      customer: {
        // Customer ID or Customer email address
        id: 586402305
      },
      ship_address_id: 8675309, // Optional
      cust_pay_id: 1234, // Optional
      coupons: ['CODE1', 'CODE2'], // Optional
      products: [{
       product_instance: {
          // The product instance ID
          id: 645769439
        },
        term: { // Only for subscription products
					num_cycles: 1 // Prepayment term. (e.g. 3 for a 3 month prepay)
        },
        quantity: 1 // Optional; default is 1
      }],
      // Optional:
      order_gift_info: {
				gift_message: 'I bought you a nice new sweater!',
        gift_recipient_name: 'Mr. Rogers',
        gift_recipient_email: '[email protected]'
        }
    }
});