HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityLog In

Orders

This topic describes how to update and create orders in Optimizely Data Platform (ODP).

Overview

Orders in ODP are created and updated via Events.

πŸ“˜

Note

Each Order generates an order purchase event per order line item.

For example, an order with three line items would generate three order events.

Top-level information about the order (for example, billing address, coupon, tax) are stored in the Orders object and linked to order events on Order ID (order_id).

Fields

Order Line Items (Events)

🚧

Important

All ODP events (and, as a result, order line items) are immutable, meaning they cannot be changed once uploaded to ODP. If you need to process returns, refunds or cancellations please refer to the relevant documentation.

Display Name

Field Name

Data Type

Description

Order ID

order_id

Text

The unique identifier related to this order.

Product ID

product_id

Text

The unique identifier for the order line item.

Order Item: Price

price

Number

The price for an order line item.

Order Item: Quantity

quantity

Number

The number of items purchased.

Order Item: Discount

discount

Number

The discount (if any) for the given line item.

Order Item: Subtotal

subtotal

Number

The calculated subtotal for the given product and quantity, typically calculated after any discounts.

Order Summary (Orders Object)

πŸ“˜

Note

While order events cannot be updated, the Order Summary can be updated at any point using the Objects endpoint. Updates made via the Objects endpoint will not generate events.

Display Name

Field Name

Data Type

Description

Order ID

order_id

Text

Required. The unique identifier related to this order.

Status

status

Text

Required. The status of the order is taken from the event action.

Tax

tax

Number

Discount

discount

Number

Typically the total value of discounts for the order, including line item and order level discounts.

Shipping

shipping

Number

Subtotal

subtotal

Number

Subtotal may be taken either before or after discounting, but generally should be before shipping or tax. See below for more information.

Total

total

Number

Total should include the final amount charged to the customer after all goods, discounts, tax, and shipping are calculated. See below for more information.

Billing Address*

bill_address

Text

The billing address for the order, lines delimited by commas. Lines should include: Street 1, Street 2, City, State/Region/Province, ZIP/Postal Code, Country. To leave a field blank, be sure to include the comma delimiter (for example, Street 1,,City)

Shipping Address

ship_address

Text

The shipping address for the order, lines delimited by commas. Lines should include: Street 1, Street 2, City, State/Region/Province, ZIP/Postal Code, Country. To leave a field blank, be sure to include the comma delimiter (for example, Street 1,,City)

Phone*

phone

Text

The phone number for the order in E.164 format

Coupon Code

coupon_code

Text

First Name*

first_name

Text

Should match the billed customer.

Last Name*

last_name

Text

Should match the billed customer.

Name*

name

Text

Should match the billed customer.

Email*

email

Text

Other identifiers (such as an ecomm platform id) can be added to the order record. A minimum of one identifier is required to process an order.

This data plus any other identifiers will be used to create a customer record (if one does not already exist) or to fill in missing info on an existing record. Info will not be overwritten if it already exists. In the case of identifiers such as email, phone, etc., multiple values can be stored/added to a single customer record; these identifiers are also used to match the order to an existing customer.

A Note on Subtotal and Total Relationships

ODP does not automatically calculate totals and subtotals at the order level based on item level subtotals or tax, shipping, and discounts. Instead, you will send these values as you would like them represented. Different eCommerce platforms handle the definition of subtotal differently, with some of them including discounts before the subtotal and others including discounts after the subtotal (but before the total). Still others handle line item discounts differently than order-level discounts.

The most important thing is to be consistent between historic imports and real-time orders to ensure that subtotal and total are always calculated the same way across your customers and orders. To help you make this decision, please be aware that LTV and Average Order Value in ODP (along with similarly derived fields) are based on the order subtotal.

Importing Historical Orders

The recommended method of sending historical Order data is to send the data via API or CSV. CSV files can be uploaded in the UI or via (AWS) Amazon S3. The fields utilized in either method adhere to the schema outlined above.

Returns, Refunds, & Cancellations

To process returns, refunds, and cancellations, send an event with an event type of order and one of the following event actions:

πŸ“˜

Note

The following event actions treat -30 and 30 as a subtotal identically. They both create new events that subtract from the original order total.

  1. return - a customer has returned some or all of the items in an order and has been refunded.
  2. refund - a customer has been issued a refund for a given order. Semantically, refunds are treated the same as returns in ODP (for example, negative impact on revenue); you can use either. Use both if you want to distinguish between inventory being returned to you (a return) and just money being issued to the original purchaser (a refund). If the inventory is returned and money is issued back to the purchaser, ODP recommends using the 'return' order action.
  3. cancel - a customer has canceled their order. The order purchase and cancel events remain in ODP (for example, on the customer profile page and for segmentation), and revenue is negatively impacted, but the order no longer figures into determining the customer's lifecycle. This is in contrast to returns and refunds, where the order still counts in determining the order count, and thus lifecycle, for a customer.

Note that order returns, refunds, and cancels can be partial. ODP determines if they are partial by tracking whether the running tally of the order's subtotal field across all events is greater than zero (partial) or not.

🚧

Caution

ODP allows the subtotal and total fields for an order to go negative (for example, to support purchase and refund events received out of order or to support cases where the refund amount legitimately exceeds the purchase amount). Be cautious not to issue duplicate refund, return, and cancel events.

Custom Order Actions

The actions purchase, refund, return, and cancel behave as above. However, you can customize the action on the order to your business. These custom statuses are treated as below:

  1. If the order exists, the order details are not updated (for example, the order total would not be incremented). You can send the order information as a pass-through to an event-triggered marketing campaign without concern about changing order details.

  2. If the order does not exist, the order is created according to the details on the request.


Did this page help you?