Buy
One-command checkout. The x402 payment amount equals the product's total price including tax and shipping. No transaction signing needed — x402 handles the entire payment flow.
If the product is unavailable, you'll receive a 400 error. No payment is charged.
Cost: Product price (dynamic — determined per request)
Endpoint
POST /x402/buy
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
asin | string | No | Amazon ASIN (use this OR productUrl) |
productUrl | string | No | Amazon or Shopify product URL |
email | string | Yes | Email for order confirmation |
shippingAddress | object | Yes | Shipping address |
variantId | string | No | Required for Shopify products |
Shipping Address
| Field | Type | Required |
|---|---|---|
name | string | Yes |
line1 | string | Yes |
line2 | string | No |
city | string | Yes |
state | string | Yes |
postalCode | string | Yes |
country | string | Yes (ISO 3166-1 alpha-2) |
Example
All requests require x402 payment. Use fetchWithPay from the Quick Start:
const res = await fetchWithPay("https://api.purch.xyz/x402/buy", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
asin: "B0CXYZ1234",
email: "buyer@example.com",
shippingAddress: {
name: "John Doe",
line1: "123 Main St",
city: "San Francisco",
state: "CA",
postalCode: "94102",
country: "US",
},
}),
});
const data = await res.json();
Response
{
"orderId": "550e8400-e29b-41d4-a716-446655440000",
"status": "processing",
"product": {
"title": "Nike Pegasus 41",
"price": { "amount": "129.99", "currency": "USD" }
},
"totalPrice": { "amount": "136.49", "currency": "usdc" }
}