πŸ›’Orders

πŸ’‘ Bulk upsert orders with items for a tenant


πŸš€ TL;DR - Quick Reference

Endpoint: POST /orders/{tenantId}

Use When:

  • Customer completes a purchase

  • Importing historical order data

  • Order refund/cancellation

  • Syncing e-commerce transactions

Required: OrderId, Currency Auth: x-replenit-auth-key header Returns: Count of upserted orders

Quickest Example:

POST /orders/{YOUR_TENANT_ID}
[{
  "OrderId": "O-789",
  "Currency": "USD",
  "TotalRevenue": 99.99,
  "OrderItems": []
}]

Jump to Full API Reference ↓


πŸ”— Endpoint

πŸ“‹ Parameters

Parameter
Type
Required
Description

tenantId

GUID

βœ… Yes

The tenant identifier (must exist)

πŸ“¨ Request

  • Body: JSON array of UpsertOrderDto objects

  • Content-Type: application/json

βœ… Success Response

  • Status: 200 OK

  • Body: Response envelope with data.count

❌ Error Responses

Status
Description

400 Bad Request

Invalid or missing tenant identifier

404 Not Found

Tenant does not exist in our system

500 Internal Server Error

Unexpected server errors


🎯 Identifier Behavior

Customer Identification

Priority Setting
Identifier Used

customerid

Customer ID from order

email (default)

Email address from order

Product Identification

πŸ“ Note: Order items currently use ProductId for identification


πŸ“„ Request Schema

UpsertOrderDto Fields

Field
Type
Max Length
Default
Required
Description

OrderId

string

100

-

βœ…

Unique order identifier

Email

string

-

-

❌

Customer email (optional if CustomerId is sent)

CustomerId

string

-

-

❌

Customer ID (used if priority is "CustomerId")

TotalQuantity

int

-

1

❌

Total items in order

TotalRevenue

double

-

1

❌

Total order value

OrderDate

string

-

UTC now

❌

ISO-8601 datetime; defaults to server UTC time if omitted

Currency

string

3

USD

βœ…

Currency code (ISO 4217)

UniqueQuantity

int

-

1

❌

Number of unique items

IsOrderCancelled

bool

-

false

❌

Cancellation status

OrderItems

CreateOrderItemDto[]

-

[]

❌

Order line items

CreateOrderItemDto Fields

Field
Type
Max Length
Required
Description

ProductId

string

100

βœ…

Product identifier

Sku

string

50

βœ…

Product SKU

Quantity

int

-

βœ…

Item quantity

Price

double

-

βœ…

Item price

Size

string

50

❌

Size (e.g., "1l")

Color

string

50

❌

Color variant

Brand

string

-

❌

Brand name

IsGift

bool

-

❌

Gift item flag

OriginalPrice

double

-

❌

Pre-discount price

πŸ’‘ Note: Size is automatically parsed into SizeNumeric and SizeMetric on the server


πŸ—‘οΈ DELETE Endpoint

πŸ”— Delete Order

πŸ“‹ Parameters

Parameter
Type
Required
Description

tenantId

GUID

βœ… Yes

The tenant identifier

orderId

string

βœ… Yes

The order ID to delete

βœ… Success Response

  • Status: 200 OK

  • Body: Response envelope with deleted order ID

❌ Error Responses

|| Status | Scenario | Example Response | || ------ | -------- | ---------------- | || 400 | Missing order ID | {"success": false, "message": "Order ID is required.", "data": {}} | || 404 | Tenant not found | {"success": false, "message": "Tenant not found.", "data": {}} | || 404 | Order not found | {"success": false, "message": "Order not found.", "data": {}} | || 500 | Storage failure | {"success": false, "message": "Failed to delete order.", "data": {}} |

Note: The tenant validation is performed automatically by middleware before reaching the endpoint. If tenant doesn't exist, you'll receive a 404 error immediately.

πŸš€ DELETE Examples

cURL

Python

Node.js


πŸ’‘ Real-World Use Cases

Use Case 1: E-commerce Purchase

Scenario: Customer just purchased 2 items from your online store

What to send:

What happens:

  1. βœ… Order synced to customer profile

  2. 🎯 Triggers "post-purchase" automation

  3. πŸ“§ Thank you email sent

  4. πŸ“Š Revenue attributed to customer


Use Case 2: Order Refund

Scenario: Customer returned an order, mark it as cancelled

What to send:

What happens:

  1. βœ… Order marked as cancelled

  2. πŸ“Š Revenue metrics updated (subtracted)

  3. 🎯 Customer removed from post-purchase flow


Use Case 3: Subscription Order

Scenario: Recurring monthly subscription payment

What to send:

Best practice: Use consistent OrderId pattern for subscriptions (e.g., SUB-{YYYY-MM}-{ID})


Use Case 4: Gift Order

Scenario: Customer bought items as gifts

What to send:

What happens:

  1. βœ… Order tracked as gift purchase

  2. 🎁 Analytics show gift behavior

  3. 🎯 Can trigger gift-specific campaigns


πŸ“ Complete Example Request (All Fields)

πŸ“ Minimal Example Request (Required Fields Only)

πŸ“ Cancelled Order Example

πŸš€ cURL Example

🐍 Python Example

🟒 Node.js Example


πŸ“Š Response Examples

βœ… Success Response (200)

❌ Validation Error (400) - Missing Required Fields

πŸ“– What this means:

  • Your first order (index [0]) is missing required fields

  • OrderId and Currency are required for all orders

  • Each order item needs ProductId and Sku

βœ… How to fix:

πŸ’‘ Required fields:

  • Order level: OrderId, Currency

  • Order item level: ProductId, Sku, Quantity, Price

❌ Validation Error (400) - String Length Exceeded

πŸ“– What this means:

  • Field values exceed maximum allowed length

  • OrderId: maximum 100 characters (shorten your order IDs)

  • Currency: maximum 3 characters (use standard 3-letter codes)

βœ… How to fix:

πŸ’‘ Field length limits:

Field
Max Length

OrderId, ProductId

100

Sku, Size, Color

50

Currency

3

❌ Not Found (404)

❌ Internal Server Error (500)


πŸ’‘ Best Practices

  1. Order IDs: Use unique, sequential order identifiers

  2. Timestamps: Always use UTC timezone for OrderDate in ISO-8601 format

  3. Currency Format: Use ISO 4217 currency codes:

  4. Calculations: Ensure TotalRevenue matches sum of item prices Γ— quantities

  5. Customer Data: Include either Email or CustomerId based on your identifier priority

  6. Order Items: Always include the parent OrderId in each item

  7. ProductIdentifiers: Please ensure that product identifiers (ProductId, SKU) are matched with your Product Catalog, so each event can be accurately linked to the correct product details (e.g., name, image, price)

  8. Batch Size: Recommended batch size is 50-200 orders per request

  9. Error Handling: Implement retry logic with exponential backoff for 500 errors


πŸ“ˆ Common Use Cases

πŸ’³ Processing a Simple Order

🎁 Order with Gift Items


Last updated