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
- Your server generates a unique
clientSessionIdbefore the product page is displayed. - The product page is returned to the browser with the
clientSessionIdembedded. - The browser initializes the Body2Fit widget using that
clientSessionIdand the product SKU. - The shopper uses the widget to get a size recommendation and places an order.
- 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/v2Endpoint
POST /CreatePurchaseHeaders
| Header | Value |
|---|---|
Content-Type | application/json |
Request Parameters
Top-level body
| Property | Type | Required | Description | Example |
|---|---|---|---|---|
clientKey | string | Yes | Your domain-scoped client key, provided by Bodygram during account setup. The same key used to initialize the widget. | abc123def456 |
clientSessionId | string | Yes | The session ID generated on your server before the product page was shown. Must match the value passed to the widget. | session_12345 |
orderId | string | Yes | Unique order ID generated by your shop. | order_9876 |
items | array | Yes | Array of item objects (see below). | [{...}] |
createdAt | number | Yes | Order timestamp in milliseconds since Unix epoch (UTC). Note: this is milliseconds, not seconds — use Date.now() in JavaScript. | 1726642845768 |
currency | string | Yes | ISO 4217 three-letter currency code. | USD |
countryCode | string | Yes | ISO 3166-1 Alpha-2 country code. | JP |
languageCode | string | Yes | ISO 639-1 language code. | en |
Item object
Each object in the items array must contain:
| Property | Type | Required | Description | Example |
|---|---|---|---|---|
sku | string | Yes | Product Stock Keeping Unit (SKU). | E123000 |
brand | string | Yes | Brand name of the product. | BRAND123 |
size | string | Yes | Size selected by the customer. | M |
price | number | Yes | Unit price in the specified currency. | 19.99 |
quantity | number | Yes | Number 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
}