Overview
This article details how to place, update, retrieve, and delete data from the orders collection using REST API calls. The orders collection contains all order data related to a purchase event. It's a separate collection designed specifically to accommodate data associated with orders. The most common order-related attributes are provided by default as part of the schema.
API set name: orders
Authentication
Cordial's core APIs use HTTPS Basic Authentication (BA). From within the Cordial platform, you can generate an encoded API key for your account and use it for authorization.
Related collections
The following collections are associated with the orders collection.
| Collection | Association |
|---|---|
| products | A product record will be created or updated in the products collection each time an order is placed. |
Methods, parameters, and examples
POST/v2/orders
| Method | URL Path |
|---|---|
| POST | /v2/orders |
|
Creates a new order in the Cordial database using the appropriate JSON body. An order can include one or more items. Posting more than one time for the same |
|
-
* Required
Base level parameters
Parameter Type Description Example * orderIDstring Unique identifier assigned for the order. 33451* cIDstring Unique primary or secondary contact identifier (key/value pair) to look up and reference the contact. cID: "1234abcd"oremail: "mikesmith@example.com"* purchaseDatestring A date value signifying the purchase data and time. Date format is ISO 8601. 2025-01-09T22:47:12+0000linkIDstring Cordial ID that represents the message and link. * Required to track revenue attribution to a specific link. 45:55....aef:1mcIDstring Cordial ID that represents the account, contact, and the message. * Required to track revenue attribution to an email. 45:55....aef:1msIDstring Cordial ID that represents the message. 45:55....aef:1customerIDstring An ID value assigned by the eCommerce or CRM system. abc123propertiesobject Key value pairs describing the properties of the order. Learn how to add custom order and item values using the properties object here.
"currency": "USD"totalAmountfloat Auto-calculated as the sum of each item.amount235.99taxfloat The amount of the tax 22.50shippingAndHandlingfloat The amount charged for shipping and handling. 0.0shippingAdressandbillingAddressobject parametersnamestring The name of the person or company making the order and/or who the order will be shipped to Mark Smithaddressstring Defines the street address 13130 Silverlake Roadcitystring Defines the city Los Angelesstatestring Defines the state CApostalCodeinteger Defines the postal code 90028countrystring Defines the country USAitemsobject parametersThe
itemsobject is optional—but, if included,productID,sku,category, andnameparameters are required.* productIDstring A unique identifier for the product. 1234abcd* skustring The stock keeping unit value for a particular item RF-WP33286-21* categorystring The category given to the particular item Major Appliance* namestring The name of the product S22-Refrigeratorqtyinteger The number of items purchased. Defaults to 1if not passed.2itemPricefloat The item price 29.95amountfloat Auto-calculated as qty x itemPrice. If a value not equal toqty x itemPriceis passed, it will be overwritten.59.90descriptionstring Description of the product Great product!urlstring Link to the product https://myproduct.comimagesarray A comma separated array of image file locations. Use an empty array []as default if no values exist."https://example.com/pic.jpg"attrobject Key value pairs describing attributes of the product. Values added cannot be searched using the Audience Builder or within Smarty for personalization. "size":"large","color":"red"propertiesobject Can be used in place of the attrkey. Values added can be searched using the Audience Builder and within Smarty for personalization, if searching of nested order properties is enabled in the account."brands":["Cool Brand","Other Cool Brand"], "return_date": "2025-07-01 00:00:00"tagsarray A comma separated array of values to describe the product. Only accepts alphanumeric characters or dashes. "office","office-supplies"discountApplicationobject parametersIf
discountApplicationis included,typeandamountare required.discountApplicationobject Calculates a specified discount to arrive at a final sales price.
Calculate the final amount as:
totalAmount = totalAmount - discountApplication.amountWhen
discountApplication.amountis zero or not present: CalculatetotalAmountwithout any changes.For a $10 discount: "discountApplication": { "type": "fixed", "amount": 10.00 }typestring Type of discount. This API accepts discounts of fixed amounts.
fixedamountinteger amount of discount
10.00 -
Basic example (minimum requirements)
{ "orderID": "33451", "purchaseDate": "2025-01-09T22:47:12+0000",
"email": "marksmith@example.com" }All optional fields included
{ "orderID": "33451", "email": "marksmith@example.com", "purchaseDate": "2025-01-09T22:47:12+0000", "linkID": "55373eed6c87669bw", "mcID": "45:55373eed6c87669bwewewee7:ot:55375ba27ec3343a77ce07ec:1422343949", "customerID": "5432225", "properties": { "color": "red", "size": "large", "currency": "USD" }, "shippingAddress": { "name": "Mark Smith", "address": "13130 Silverlake Road", "city": "Los Angeles", "state": "CA", "postalCode": 92332, "country": "USA" }, "billingAddress": { "name": " Mark Smith ", "address": "13130 Silverlake Road", "city": "Los Angeles", "state": "CA", "postalCode": 92332, "country": "USA" }, "items": [ { "productID": "1234abcd", "sku": "ssd-2344-15", "description": "This shirt is amazing!", "category": "Shirts", "name": "Awesome Flannel", "qty": 1, "url": "https://awesomeflannels.com/1234abcd", "itemPrice": 129.95, "images": [ "https://awesomeflannels.com/image_1.jpg", "https://awesomeflannels.com/image_2.jpg" ], "tags": [ "flannels", "winter" ], "properties": { "brands": [ "Cool Brand", "Other Cool Brand" ], "return_date": "2025-07-09T22:47:12+0000" }, "attr": { "color": "red", "size": "large" } } ], "discountApplication": { "type": "fixed", "amount": 10.00 }, "tax": 7, "shippingAndHandling": 0 } -
The following URL in conjunction with the JSON will perform the POST.
https://<path>/v2/orders
Custom order and item values
The properties parameter can be used to insert additional custom order and item values. Values added using the properties attribute will become available for segmenting audiences using the Audience Builder.
Use the properties parameter in place of the attr parameter if you want it to be searchable.
-
Example of adding custom order properties
{ "orderID": "33451", "properties": { "color": "red", "size": "large", "currency": "USD" }, "items": [ { "productID": "1234abcd", "name": "Red Flannel", "category": "shirts", "sku": "ssd-2344-15", "tags": [ "flannels", "winter" ] }] }Example of adding custom items properties
{ "orderID": "33451", "items": [ { "productID": "1234abcd", "name": "Red Flannel", "category": "shirts", "sku": "ssd-2344-15", "tags": [ "flannels", "winter" ], "properties": { "brands": [ "Marmot", "Quicksilver" ] } }] }
Work with multiple shipping addresses
The shippingAddress and billingAddress parameters are part of the default kitchen sink order object. However, your order data may contain a secondary ship-to address as well as a separate ship-to address for each order item. Using the order and order item properties parameter, you can pass additional address fields as custom order and item values.
-
Add a custom secondary shipping address using order properties:
{ "orderID": "33451", "email": "marksmith@example.com", "purchaseDate": "2025-01-09T22:47:12+0000", "properties": { "shippingAddress2": { "name": "Mark Smith", "address": "5555 Park Avenue", "city": "Los Angeles", "state": "CA", "postalCode": 90038, "country": "USA" } }, "shippingAddress": { "name": "Mark Smith", "address": "13130 Silverlake Road", "city": "Los Angeles", "state": "CA", "postalCode": 92332, "country": "USA" }, "billingAddress": { "name": " Mark Smith ", "address": "13130 Silverlake Road", "city": "Los Angeles", "state": "CA", "postalCode": 92332, "country": "USA" } }Add a custom order item shipping address using items properties:
{ "orderID": "33451", "email": "marksmith@example.com", "purchaseDate": "2025-01-09T22:47:12+0000", "properties": { "color": "red", "size": "large", "currency": "USD" }, "items": [ { "productID": "1234abcd", "name": "Red Flannel", "category": "shirts", "sku": "ssd-2344-15", "tags": [ "flannels", "winter" ], "properties": { "itemShipAddress": { "name": "Mark Smith", "address": "5555 Park Avenue", "city3": "Los Angeles", "state": "CA", "postalCode": 90038, "country": "USA" } } } ] }1.) The
orderIDfield must be a unique value. 2.) The contact identifier primary or secondary key field is required. This is the unique identifier for the contact. Cordial does not accept anonymous order records. 3.)mcIDorlinkIDare required if you need to attribute the order to a specific message or link within a message. These can be passed in the link aslinkID={$linkID}&mcID={$mcID}and stored in a session variable for use in the API. 4.) One or more items can be included in an order.
GET/v2/orders
| Method | URL Path |
|---|---|
| GET | /v2/orders |
|
|
The GET/orders endpoint can retrieve up to 10,000 records at a time. To page through more than 10,000 records, multiple queries must be made with manually adjusted parameters for each.
-
Parameter Type Description Example fieldsstring Sets which data fields will be returned. ?fields=shippingAddresscIDstring Unique contact ID to identify and reference the contact. ?cID=5ada55ed132f37e60e63c04demailstring Unique email address to identify and reference the contact. ?email=msmith@example.compurchaseDatestring Filters the data by date using gteandlte.?purchaseDate[gte]=2017-01-10pagenumber Page number of results. ?page=3per_pagenumber Number of results per page. ?per_page=10sort_bystring Column to sort by. Note: Works in conjunction with sort_dir. ?sort_by=purchaseDatesort_dirstring Direction to sort by. Note: Works in conjunction with sort_by. ?sort_by=purchaseDate&sort_dir=desc -
The following URL will retrieve all orders and include all fields.
https://<path>/v2/orders
The following URL will retrieve all orders, but only include the fields data for
shippingAddresshttps://<path>/v2/orders?fields=shippingAddress
The following URL will retrieve all orders, and include the fields data for both
totalAmountandtaxhttps://<path>/v2/orders?fields=totalAmount,tax
The following URL will retrieve all orders with a
purchaseDategreater than2024-11-10https://api.cordial.io/v2/orders?purchaseDate[gt]=2024-11-10
The following URL will retrieve all orders where the
purchaseDateis between2017-01-10and2017-01-11https://api.cordial.io/v2/orders?purchaseDate[gte]=2017-01-10&purchaseDate[lte]=2017-01-11
The following URL will retrieve all orders starting from the third page grouping contacts by 10. For example, page 1 would have included the first 10, page 2 the second group of 10 and so on.
https://<path>/v2/orders?page=3&per_page=10
The following URL will retrieve all orders associated with the specified batch message ID (msID).
https://api.cordial.io/v2/orders?msID=45:58d99989486e542f5291c5b8:ot
The following URL will retrieve all orders associated with the specified automation template ID (mdtID).
https://api.cordial.io/v2/orders?mdtID=5b83b2e161c95f012b8255d6
GET/v2/orders/{id}
| Method | URL Path |
|---|---|
| GET | v2/orders/{id} |
|
|
-
Parameter Type Description Example fieldsstring Sets which data fields will be returned. ?fields=shippingAddress -
Return records filtered by ID
The following URL will retrieve an order where the
idvalue is128.https://<path>/v2/orders/128
Return records filtered by ID field
The following URL will retrieve an order where the
idvalue is128, but only include the field data forshippingAddresshttps://<path>/v2/orders/128?fields=shippingAddress
Return records filtered by ID multiple fields
The following URL will retrieve an order where the
idvalue is128, and include thefielddata for bothtotalAmountandtaxhttps://<path>/v2/orders/128?fields=totalAmount,tax
PUT/v2/orders{id}
| Method | URL path |
|---|---|
| PUT | /v2/orders |
| Updates an order in the Cordial database using the appropriate JSON body. | |
-
Same requirements and schema as the POST method above.
-
The following will update the purchase date of order
33451.{ "email": "marksmith@example.com", "orderID": "33451", "purchaseDate": "2025-01-10T22:47:12+0000" } -
The following URL in conjunction with the JSON will perform the PUT.
https://<path>/v2/orders
DELETE/v2/orders/{id}
| Method | URL Path |
|---|---|
| DELETE | /v2/orders/{id} |
|
Deletes an order from the Cordial database. The order id defined by the order's unique For example, v2/orders/22345 would delete the attribute with the |
|
-
The following URL will delete an order where the
idvalue is 128.https://<path>/v2/orders/128
Test in Swagger
You can access and test Cordial's APIs in Swagger.
Error responses
The Cordial API will return an error object with an errorKey and message if there is a problem with an API call. Below is a list of errors specific to the Orders API endpoint, along with suggested modifications to resolve each error. If you receive an error from this API endpoint that is not listed in this table, it is likely recorded within the Global API error responses page.
errorKey |
Message | Modifications |
|---|---|---|
ORDERS_ID_UNIQUE |
ID must be unique | The orderID must be unique. |
ORDERS_CID_MCID_NOT_MATCH |
cID and mcID do not match |
The Cordial database contact ID and message contact ID do not match. |
ORDERS_PRIMARY_FILTER |
Use only one from existing filters ':primaryKey' OR 'cID' | Please use either the primaryKey or cID filter, but not both. |
ORDERS_NOT_FOUND |
Order not found | The identifier entered didn't return any results. |
ORDERS_INCORRECT_FILTER |
Time value is incorrect | Time input should be in ISO 08601 format, e.g. YYY-MM-DDThh:mm:ss
|
ORDERS_CONTACT_NOT_FOUND |
Must include customPK or secondaryKey, customPK, email, cID, firebase, push | Ensure the contact information has been input correctly. |
Comments
0 comments
Please sign in to leave a comment.