How to use Orders API

Track, list, and cancel orders using Transak's Whitelabel APIs
View as Markdown

Once a user places an order, your app still needs to know what happened to it. Is there an order already in progress? What’s in the user’s order history? What’s the status of one specific order? Can the user back out before paying? The Order APIs answer all four questions.

What We’ll Build

A “My Orders” experience: an active-order check before checkout, a full order history list, a single order details/status view, and a cancel action.

APIPurpose
GET /api/whitelabel/orders/get-active-ordersCheck whether the user already has an order in progress before starting a new one
GET /api/whitelabel/orders/get-ordersFetch the user’s complete order history
GET /api/whitelabel/orders/get-order-by-idFetch (or poll) the details and status of one specific order
DELETE /api/whitelabel/orders/cancel-orderCancel an order before its payment is completed

Authentication Headers

These APIs support both onboarding paths from Authentication APIs. The headers you pass depend on which path your integration uses.

Pass these headers on every order API call when your platform owns the user’s authentication:

HeaderDescription
x-user-identifierThe authenticated user’s email address
x-access-tokenYour Partner Access Token

Step 1 — Get Active Orders

Call this before letting a user start checkout. An active order is one that hasn’t reached a final state (COMPLETED, CANCELLED, FAILED, REFUNDED, or EXPIRED) — see the full list on How to Track Order Status. If one exists, resume it or offer to cancel it instead of creating a duplicate order.

1

Fetch active orders

$curl "https://api-gateway-stg.transak.com/api/v2/active-orders" \
> -H "x-api-key: YOUR_API_KEY" \
> -H "x-user-ip: USER_IP_ADDRESS" \
> -H "Authorization: USER_ACCESS_TOKEN"
2

Branch on the result

data is an array. An empty array means the user has no order in progress and can start a new one.

1const { data: activeOrders } = json;
2if (activeOrders.length > 0) {
3 // Resume or offer to cancel activeOrders[0] instead of starting checkout
4}
getActiveOrders.ts
1const BASE = "https://api-gateway-stg.transak.com";
2
3interface Order {
4 orderId: string;
5 status: string;
6 isBuyOrSell: string;
7 fiatCurrency: string;
8 cryptoCurrency: string;
9 paymentMethod: string;
10 network: string;
11 walletAddress: string;
12 quoteId: string;
13 fiatAmount: number;
14 cryptoAmount: number;
15 totalFeeInFiat: number;
16 txHash: string;
17}
18
19async function getActiveOrders(params: {
20 apiKey: string;
21 userIp: string;
22 accessToken: string;
23}): Promise<Order[]> {
24 const res = await fetch(`${BASE}/api/v2/active-orders`, {
25 headers: {
26 "x-api-key": params.apiKey,
27 "x-user-ip": params.userIp,
28 Authorization: params.accessToken,
29 },
30 });
31 const json = await res.json();
32 if (!res.ok) throw new Error(json.error?.message ?? `HTTP ${res.status}`);
33 return json.data as Order[];
34}

Step 2 — Get Orders

Fetch the user’s complete order history — every order they’ve ever placed, regardless of status. Use this to render an order list or transaction history screen.

1

Fetch order history

$curl "https://api-gateway-stg.transak.com/api/v2/orders" \
> -H "x-api-key: YOUR_API_KEY" \
> -H "x-user-ip: USER_IP_ADDRESS" \
> -H "Authorization: USER_ACCESS_TOKEN"
2

Render the list

Each item includes orderId, status, amounts, and paymentDetails. Sort or filter client-side by status (e.g. show COMPLETED and CANCELLED separately).

1const { data: orders } = json;
2orders.map(o => `${o.orderId}${o.status}${o.fiatAmount} ${o.fiatCurrency}`);
getOrders.ts
1const BASE = "https://api-gateway-stg.transak.com";
2
3interface Order {
4 orderId: string;
5 status: string;
6 isBuyOrSell: string;
7 fiatCurrency: string;
8 cryptoCurrency: string;
9 paymentMethod: string;
10 fiatAmount: number;
11 cryptoAmount: number;
12 totalFeeInFiat: number;
13 txHash: string;
14 transactionLink: string;
15}
16
17async function getOrders(params: {
18 apiKey: string;
19 userIp: string;
20 accessToken: string;
21}): Promise<Order[]> {
22 const res = await fetch(`${BASE}/api/v2/orders`, {
23 headers: {
24 "x-api-key": params.apiKey,
25 "x-user-ip": params.userIp,
26 Authorization: params.accessToken,
27 },
28 });
29 const json = await res.json();
30 if (!res.ok) throw new Error(json.error?.message ?? `HTTP ${res.status}`);
31 return json.data as Order[];
32}

Step 3 — Get Order By ID

Fetch a single order using the orderId returned from checkout, from Get Orders, or from Get Active Orders. Use this for an order details screen, or poll it on an interval to track a specific order’s status until it reaches a final state.

1

Fetch the order

$curl "https://api-gateway-stg.transak.com/api/v2/orders/ORDER_ID" \
> -H "x-api-key: YOUR_API_KEY" \
> -H "x-user-ip: USER_IP_ADDRESS" \
> -H "Authorization: USER_ACCESS_TOKEN"
2

Read the status

See the full status list on How to Track Order Status.

1const { status, txHash, transactionLink } = json.data;
2// status: "AWAITING_PAYMENT_FROM_USER" | "PROCESSING" | "COMPLETED" | "CANCELLED" | "FAILED" | ...
getOrderById.ts
1const BASE = "https://api-gateway-stg.transak.com";
2
3interface Order {
4 orderId: string;
5 status: string;
6 fiatAmount: number;
7 cryptoAmount: number;
8 txHash: string;
9 transactionLink: string;
10}
11
12async function getOrderById(params: {
13 orderId: string;
14 apiKey: string;
15 userIp: string;
16 accessToken: string;
17}): Promise<Order> {
18 const res = await fetch(`${BASE}/api/v2/orders/${params.orderId}`, {
19 headers: {
20 "x-api-key": params.apiKey,
21 "x-user-ip": params.userIp,
22 Authorization: params.accessToken,
23 },
24 });
25 const json = await res.json();
26 if (!res.ok) throw new Error(json.error?.message ?? `HTTP ${res.status}`);
27 return json.data as Order;
28}
29
30const FINAL_STATUSES = ["COMPLETED", "CANCELLED", "FAILED", "REFUNDED", "EXPIRED"];
31
32async function pollOrderStatus(
33 params: Parameters<typeof getOrderById>[0] & { intervalMs?: number; timeoutMs?: number }
34): Promise<Order> {
35 const { intervalMs = 5000, timeoutMs = 300_000 } = params;
36 const deadline = Date.now() + timeoutMs;
37
38 while (Date.now() < deadline) {
39 const order = await getOrderById(params);
40 if (FINAL_STATUSES.includes(order.status)) return order;
41 await new Promise(resolve => setTimeout(resolve, intervalMs));
42 }
43 throw new Error("Timed out waiting for order to reach a final status");
44}

Step 4 — Cancel Order

Cancels an order that hasn’t finished payment yet — useful when the user changes their mind, enters incorrect details, or hits a payment issue.

A cancelled order cannot be reversed. Once cancelled, the user must place a new order.

1

Cancel the order

Pass cancelReason as a query parameter and the orderId in the path.

$curl -X DELETE "https://api-gateway-stg.transak.com/api/v2/orders/ORDER_ID\
>?cancelReason=User%20changed%20their%20mind" \
> -H "x-api-key: YOUR_API_KEY" \
> -H "x-user-ip: USER_IP_ADDRESS" \
> -H "Authorization: USER_ACCESS_TOKEN"
2

Confirm the cancellation

1const { orderId, status } = json.data;
2// status: "CANCELLED"
cancelOrder.ts
1const BASE = "https://api-gateway-stg.transak.com";
2
3async function cancelOrder(params: {
4 orderId: string;
5 cancelReason: string;
6 apiKey: string;
7 userIp: string;
8 accessToken: string;
9}): Promise<{ orderId: string; status: string }> {
10 const qs = new URLSearchParams({ cancelReason: params.cancelReason });
11 const res = await fetch(`${BASE}/api/v2/orders/${params.orderId}?${qs}`, {
12 method: "DELETE",
13 headers: {
14 "x-api-key": params.apiKey,
15 "x-user-ip": params.userIp,
16 Authorization: params.accessToken,
17 },
18 });
19 const json = await res.json();
20 if (!res.ok) throw new Error(json.error?.message ?? `HTTP ${res.status}`);
21 return json.data;
22}

Full Flow (Putting It Together)

hooks/useOrderManagement.ts
1import { useState } from "react";
2
3const BASE = "https://api-gateway-stg.transak.com";
4const FINAL_STATUSES = ["COMPLETED", "CANCELLED", "FAILED", "REFUNDED", "EXPIRED"];
5
6interface Order {
7 orderId: string;
8 status: string;
9 fiatAmount: number;
10 cryptoAmount: number;
11 fiatCurrency: string;
12 cryptoCurrency: string;
13 txHash: string;
14 transactionLink: string;
15}
16
17export function useOrderManagement(apiKey: string, userIp: string, accessToken: string) {
18 const [activeOrders, setActiveOrders] = useState<Order[]>([]);
19 const [orders, setOrders] = useState<Order[]>([]);
20 const [selectedOrder, setSelectedOrder] = useState<Order | null>(null);
21 const [error, setError] = useState<string | null>(null);
22
23 const headers = () => ({
24 "x-api-key": apiKey,
25 "x-user-ip": userIp,
26 Authorization: accessToken,
27 });
28
29 async function fetchActiveOrders() {
30 setError(null);
31 const res = await fetch(`${BASE}/api/v2/active-orders`, { headers: headers() });
32 const json = await res.json();
33 if (!res.ok) throw new Error(json.error?.message ?? `HTTP ${res.status}`);
34 setActiveOrders(json.data);
35 return json.data as Order[];
36 }
37
38 async function fetchOrders() {
39 setError(null);
40 const res = await fetch(`${BASE}/api/v2/orders`, { headers: headers() });
41 const json = await res.json();
42 if (!res.ok) throw new Error(json.error?.message ?? `HTTP ${res.status}`);
43 setOrders(json.data);
44 return json.data as Order[];
45 }
46
47 async function fetchOrderById(orderId: string) {
48 setError(null);
49 const res = await fetch(`${BASE}/api/v2/orders/${orderId}`, { headers: headers() });
50 const json = await res.json();
51 if (!res.ok) throw new Error(json.error?.message ?? `HTTP ${res.status}`);
52 setSelectedOrder(json.data);
53 return json.data as Order;
54 }
55
56 async function pollOrderById(orderId: string, intervalMs = 5000, timeoutMs = 300_000) {
57 const deadline = Date.now() + timeoutMs;
58 while (Date.now() < deadline) {
59 const order = await fetchOrderById(orderId);
60 if (FINAL_STATUSES.includes(order.status)) return order;
61 await new Promise(r => setTimeout(r, intervalMs));
62 }
63 throw new Error("Timed out waiting for order to reach a final status");
64 }
65
66 async function cancelOrder(orderId: string, cancelReason: string) {
67 setError(null);
68 const qs = new URLSearchParams({ cancelReason });
69 const res = await fetch(`${BASE}/api/v2/orders/${orderId}?${qs}`, {
70 method: "DELETE",
71 headers: headers(),
72 });
73 const json = await res.json();
74 if (!res.ok) throw new Error(json.error?.message ?? `HTTP ${res.status}`);
75 setSelectedOrder(json.data);
76 return json.data as { orderId: string; status: string };
77 }
78
79 return {
80 activeOrders,
81 orders,
82 selectedOrder,
83 error,
84 fetchActiveOrders,
85 fetchOrders,
86 fetchOrderById,
87 pollOrderById,
88 cancelOrder,
89 };
90}

Order APIs