Bodygram

Order Confirmation

Send order data to Bodygram after checkout to improve recommendation accuracy over time.

Overview

Order Confirmation is an API call you make after a shopper completes a purchase. It closes the feedback loop by telling Bodygram which items and sizes were actually purchased, allowing recommendations to improve over time.

Sending order data is optional — Bodygram works without it, but the system becomes more accurate as more order signals are received.

Order Confirmation should be called from your server after payment is confirmed — for example, inside an order webhook or payment confirmation handler. Calling it server-side ensures the request is sent reliably regardless of what the user's browser does after checkout.


Before You Start

This page assumes you are already generating a clientSessionId on your server and passing it to the Body2Fit widget on the product page. If you haven't set that up yet, see Configuration for the session.clientSessionId option and Integration Guide for the full widget setup.

The same clientSessionId you pass to the widget must be sent in the Order Confirmation request to link the order back to the session.


Integration Flow

  1. Your server generates a unique clientSessionId before the product page is displayed.
  2. The product page is returned to the browser with the clientSessionId embedded.
  3. The browser initializes the Body2Fit widget using that clientSessionId and the product SKU.
  4. The shopper uses the widget to get a size recommendation and places an order.
  5. Your server receives the confirmed order and sends an Order Confirmation request to Bodygram, including the same clientSessionId.
Browser                     Your Server              Bodygram API
  │                           │── generate sessionId   │
  │◀── product page ──────────│   (includes sessionId) │
  │── init widget ─────────────────────────────────────▶│
  │── place order ────────────▶│                        │
  │                            │── POST /CreatePurchase ──▶│
  │                            │◀── 200 OK ───────────────│

API Reference

Base URL

https://fitfinder.body2fit.bodygram.com/v2

Endpoint

POST /CreatePurchase

Headers

HeaderValue
Content-Typeapplication/json

Request Parameters

Top-level body

PropertyTypeRequiredDescriptionExample
clientKeystringYesYour domain-scoped client key, provided by Bodygram during account setup. The same key used to initialize the widget.abc123def456
clientSessionIdstringYesThe session ID generated on your server before the product page was shown. Must match the value passed to the widget.session_12345
orderIdstringYesUnique order ID generated by your shop.order_9876
itemsarrayYesArray of item objects (see below).[{...}]
createdAtnumberYesOrder timestamp in milliseconds since Unix epoch (UTC). Note: this is milliseconds, not seconds — use Date.now() in JavaScript.1726642845768
currencystringYesISO 4217 three-letter currency code.USD
countryCodestringYesISO 3166-1 Alpha-2 country code.JP
languageCodestringYesISO 639-1 language code.en

Item object

Each object in the items array must contain:

PropertyTypeRequiredDescriptionExample
skustringYesProduct Stock Keeping Unit (SKU).E123000
brandstringYesBrand name of the product.BRAND123
sizestringYesSize selected by the customer.M
pricenumberYesUnit price in the specified currency.19.99
quantitynumberYesNumber of units purchased.2

Response

Success — 200 OK

{
  "status": "success"
}

Error — 4xx / 5xx

{
  "status": "error",
  "error": {
    "message": "A brief description of the error"
  }
}

Error Handling

Error responses are for debugging only. Since Order Confirmation is optional and non-critical to checkout, never block purchase completion or alter the user experience based on API errors. Log errors internally and continue normal operation.

If you see persistent errors, review your integration or contact support@bodygram.com.


Implementation Example

// Call this inside your order confirmation webhook or payment handler.
// Pass the confirmed order object from your system.
//
// Expected order object structure:
// {
//   sessionId: string,   // clientSessionId from the product page
//   id: string,          // your internal order ID
//   currency: string,    // e.g. "USD"
//   countryCode: string, // e.g. "JP"
//   languageCode: string,// e.g. "en"
//   items: Array<{
//     sku: string,
//     brand: string,
//     size: string,       // the size the customer ordered
//     price: number,
//     quantity: number,
//   }>
// }
async function sendOrderConfirmation(order) {
  try {
    const response = await fetch(
      'https://fitfinder.body2fit.bodygram.com/v2/CreatePurchase',
      {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
          clientKey: 'YOUR_CLIENT_KEY',
          clientSessionId: order.sessionId,
          orderId: order.id,
          items: order.items.map((item) => ({
            sku: item.sku,
            brand: item.brand,
            size: item.size,
            price: item.price,
            quantity: item.quantity,
          })),
          createdAt: Date.now(), // milliseconds
          currency: order.currency,
          countryCode: order.countryCode,
          languageCode: order.languageCode,
        }),
      }
    );

    if (!response.ok) {
      const error = await response.json();
      console.warn('Order confirmation failed:', error.error?.message);
    }
  } catch (err) {
    console.warn('Order confirmation request failed:', err);
  }

  // Always continue — a failed confirmation does not affect the order
}

On this page