> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oneclickdz.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Place Order

> Purchase gift cards or digital products

## Overview

Create orders for gift cards and digital products. Cards are delivered digitally via the `/checkOrder` endpoint.

<Note>
  **Before ordering:** Verify stock via `/checkProduct` and check account
  balance.
</Note>

## Request Body

<ParamField body="productId" type="string" required>
  Product ID from `/catalog`
</ParamField>

<ParamField body="typeId" type="string" required>
  Type ID from `/checkProduct`
</ParamField>

<ParamField body="quantity" type="integer" required>
  Number of cards to order (minimum: 1)
</ParamField>

## Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.oneclickdz.com/v3/gift-cards/placeOrder \
    -X POST \
    -H "Content-Type: application/json" \
    -H "X-Access-Token: YOUR_API_KEY" \
    -d '{
      "productId": "507f1f77bcf86cd799439011",
      "typeId": "type_001",
      "quantity": 2
    }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch(
    "https://api.oneclickdz.com/v3/gift-cards/placeOrder",
    {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "X-Access-Token": "YOUR_API_KEY",
      },
      body: JSON.stringify({
        productId: "507f1f77bcf86cd799439011",
        typeId: "type_001",
        quantity: 2,
      }),
    }
  );
  const { data } = await response.json();
  console.log("Order ID:", data.orderId);
  ```

  ```python Python theme={null}
  response = requests.post(
      'https://api.oneclickdz.com/v3/gift-cards/placeOrder',
      headers={
          'Content-Type': 'application/json',
          'X-Access-Token': 'YOUR_API_KEY'
      },
      json={
          'productId': '507f1f77bcf86cd799439011',
          'typeId': 'type_001',
          'quantity': 2
      }
  )
  order_id = response.json()['data']['orderId']
  ```

  ```php PHP theme={null}
  <?php
  $data = [
      'productId' => '507f1f77bcf86cd799439011',
      'typeId' => 'type_001',
      'quantity' => 2
  ];

  $ch = curl_init('https://api.oneclickdz.com/v3/gift-cards/placeOrder');
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      'Content-Type: application/json',
      'X-Access-Token: YOUR_API_KEY'
  ]);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  $response = json_decode(curl_exec($ch), true);
  $orderId = $response['data']['orderId'];
  ?>
  ```
</CodeGroup>

### Success Response

```json theme={null}
{
  "success": true,
  "data": {
    "orderId": "6901616fe9e88196b4eb64b3"
  },
  "meta": {
    "timestamp": "2025-10-29T01:00:00.000Z"
  },
  "requestId": "req_1730163600_abc123"
}
```

## Pre-Order Checklist

<Steps>
  <Step title="Verify Stock">
    ```javascript theme={null}
    const product = await checkProduct(productId);
    const type = product.types.find(t => t.id === typeId);
    if (!type || type.quantity < quantity) {
      throw new Error('Insufficient stock');
    }
    ```
  </Step>

  <Step title="Check Balance">
    ```javascript theme={null}
    const balance = await getBalance();
    const totalCost = type.price * quantity;
    if (balance < totalCost) {
      throw new Error('Insufficient balance');
    }
    ```
  </Step>

  <Step title="Place Order">
    ```javascript theme={null}
    const order = await placeOrder({ productId, typeId, quantity });
    ```
  </Step>

  <Step title="Poll for Cards">
    ```javascript theme={null}
    const result = await pollOrder(order.orderId);
    ```
  </Step>
</Steps>

## Error Responses

<AccordionGroup>
  <Accordion title="ERR_VALIDATION">Invalid request parameters</Accordion>
  <Accordion title="ERR_STOCK">Product out of stock</Accordion>
  <Accordion title="INSUFFICIENT_BALANCE">Not enough balance</Accordion>
</AccordionGroup>

## Processing

<Warning>Orders are **final once placed**. Save `orderId` immediately.</Warning>

Most orders process within seconds. Poll `/checkOrder/:orderId` every 5-10 seconds until status is `FULFILLED` or `REFUNDED`.

## Related

<CardGroup cols={2}>
  <Card title="Check Order" icon="magnifying-glass" href="/en/api-reference/gift-cards/check-order">
    Get cards when fulfilled
  </Card>

  <Card title="Check Product" icon="box" href="/en/api-reference/gift-cards/check-product">
    Verify stock first
  </Card>
</CardGroup>
