Button Developers

Reporting Orders

In this section, we'll walk through the steps needed to report orders to Button.

Report a New Order

Brands should report all successful orders to the Button Order API before reporting back to the end user, and after fulfilling that order in your own inventory system. Order reporting at this time guarantees both that the order was successfully acknowledged, and that any promotions from other applications involved in this purchase are carried out.

Here is a sample request using the cURL terminal command. For more information on this API’s specifications, visit the Order API.

curl https://api.usebutton.com/v1/order \
  -X POST \
  -u YOUR_API_KEY: \
  -H "Content-Type: application/json" \
  -d '{
    "total": 7000,
    "currency": "USD",
    "order_id": "1994",
    "purchase_date": "2017-07-25T08:23:52Z",
    "finalization_date": "2017-08-02T19:26:08Z",
    "btn_ref": "srctok-XXX",
    "customer": {
      "id": "mycustomer-1234",
      "email_sha256": "'`echo -n "[email protected]" | openssl dgst -sha256`'",
      "device_id": "XXXX-XXXXXX-XXX-XXXXXX",
      "is_new": true
    },
    "customer_order_id": "abcdef-123456"
    "line_items": [
            {
                "identifier": "sku-1234",
                "total": 4000,
                "amount": 2000,
                "quantity":2,
                "sku": "sku-1234",
                "upc": "400000000001",
                "category": ["Clothes"],
                "description": "T-shirts",
                "attributes":{
                    "size": "M"
                }
            },{
                "identifier": "sku-4567",
                "total": 3000,
                "amount": 3000,
                "quantity":1,
                "sku": "sku-4567",
                "upc": "400000000002",
                "category": ["Clothes"],
                "description": "Pants",
                "attributes":{
                    "size": "L"
                }
            }
    ],
  }'

🚧

Note

You'll need to authenticate your API requests; see our authentication reference for more details.

Order Object

All fields below are required when reporting orders to Button:

Request Parameter

Description

total

Total value of the order. Includes any discounts, if applicable. Must exclude VAT, all other taxes, surcharges and any additional costs such as delivery. This value represents the commissionable total. Must be an integer >= 0. Example: 1234 for $12.34.

currency

Three-letter ISO currency code as specified in ISO 4217.

order_id

The Order ID unique to this order. Treated as an ASCII string. 255 character maximum.

purchase_date

ISO-8601 string representing the time the purchase was made by the user.

btn_ref

The Button Attribution Token. A URL safe string up to 255 characters. This field is optional to create an order, but is required for attribution. When testing your integration, you should send dummy Attribution Tokens to Button, in the following format: ^fakesrctok-[a-f0-9]{16}$ (e.g. fakesrctok-abcdef0123456789). Note: even though this is marked as *optional*, you must provide a valid Button Attribution Token when reporting orders driven by a Button Publisher.

customer

Information regarding the Customer Object.

customer_order_id

The customer-facing order ID. Treated as a UTF-8 string. 255 character maximum. Note: Use this field to report the order identifier as communicated to the customer.

line_items

An array of the line item details that comprise the order.

status

A read-only field giving the order's current status.

partner_order_channel

The channel in which the user transacted. Accepted values for this field are app and webview.

Customer Object

All fields below are required when reporting orders to Button:

Key

Description

id

The ID for the transacting customer in your system.

email_sha256

The SHA-256 hash of the transacting customer's lowercase email, as a 64-character hex string. Note: The value of the e-mail address must be converted to lowercase before computing the hash. The hash itself may use uppercase or lowercase hex characters.

device_id

The customer's device ID (iOS: IDFA, Android: AAID)

is_new

A Boolean value indicating whether or not the customer has previously made a purchase. Pass true if this is their first purchase, otherwise pass false.

Line Items Object

All fields below are required when reporting orders to Button:

Key

Description

identifier

The unique identifier for this line item, within the scope of this order. This must be unique across all line-items within the order. We suggest using the SKU or UPC of the product.

sku

The Stock Keeping Unit of the line item. A Brand-specific identifier for the line item. String with a maximum length of 255.

upc

The Universal Product Code of the line item. Also referred to as UPC-A and GTIN-12. UPC-E (8-digit) codes should be converted to 12-digit codes. String with 12 numeric digits. For industries not regularly utilizing upc this can be your industry’s unique product identifier.

quantity

The number of unique units represented by this line item. Must be an integer > 0. Defaults to 1.

total

The total cost of all items in this line item expressed as an integer in pennies (e.g. if 3 bananas were purchased for $3.00 each, total would be 900). Must be net of any discounts or taxes and represent the value a Brand expects to commission on.

category

The category of the line item. An ordered list of strings, starting with the topmost (or most general) category. The total number of subcategories is capped at 7. Example: ["Electronics", "Computers", "Laptops", "Accessories", "Bags"].

description

Text describing the line item.

attributes

A key/value store for strings to specify additional information about a line item. Examples of attributes are: top level / meta category identifier with a category; secondary category identifier with a subcategory; primary manufacturer of the product with a brand

Update an Order

Accurate billing relies on accurate order reporting. In cases where initial orders are modified, it is vital to update them via the Button Orders API.

Because of this, Brands must also report all successful order updates to the Button Orders API whenever the order’s value, content, or status changes in your e-commerce backend. Similar to reporting a new order, updating orders is done via POST request containing the order’s updated information.

When you report an order adjustment to Button, the body should contain the most recent / current version of the order. To illustrate this, if an order was initially posted with two line items, and then one line item was returned, the order adjustment posted to Button should only contain one line item.

Important: Partial returns are considered “updates” and should be reported using this update method.

Here is a sample request using the cURL terminal command – if you compare this to the sample order reported above, you'll see one line item was removed and the total now reflects the updated order total.

curl https://api.usebutton.com/v1/order/ord-xxx \
  -X POST \
  -u my-api-key: \
  -H "Content-Type: application/json" \
  -d '{
    "total": 4000,
    "line_items": [
            {
                "identifier": "sku-1234",
                "total": 4000,
                "amount": 2000,
                "quantity":2,
                "sku": "sku-1234",
                "upc": "400000000001",
                "category": ["Clothes"],
                "description": "T-shirts",
                "attributes":{
                    "size": "M"
                }
            }
    ],
  }'

For more information on this API’s specifications, visit the Orders API.

Cancel an Order

Lastly, for all orders that are cancelled within your Brand’s Order Management System, you must report this to the Button Order API to avoid improper billing or commissioning to your Brand or other parties involved in the transaction. Cancellations are reported via http DELETE request, and are only valid for entire order cancellations. Partial order cancellations are considered an order update. Once a cancellation is made, it cannot be reversed.

Here is a sample request using the cURL terminal command. For more information on this API’s specifications, visit the Orders API.

curl https://api.usebutton.com/v1/order/<brand-order-id> \
       -X DELETE \
       -u YOUR_API_KEY:

Receiving a Response

A successful response body from the Offers API will return a meta.status of ok for all transmissions, differing only under the object field to reflect either the new order being registered, updated, or cancelled.

// Sample response:
{
  "meta": {
    "status": "ok"
  },
    "object": {
      "id": "f00b4r",
        "active": true
    }
}

Updated 7 months ago



Reporting Orders


In this section, we'll walk through the steps needed to report orders to Button.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.