> ## 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.

# Placing Orders

> Place gift card orders after checking stock and balance

## Overview

Place orders for gift cards after verifying product availability. Orders process instantly and return an `orderId` for tracking.

<Warning>Orders are final once placed. Check stock and balance first.</Warning>

## API Reference

<Card title="POST /v3/gift-cards/placeOrder" icon="cart-shopping" href="/en/api-reference/gift-cards/place-order">
  Complete endpoint documentation
</Card>

## Place an Order

<CodeGroup>
  ```python Python theme={null}
  import requests
  import os

  def place_order(product_id, type_id, quantity):
      response = requests.post(
          'https://api.oneclickdz.com/v3/gift-cards/placeOrder',
          headers={
              'Content-Type': 'application/json',
              'X-Access-Token': os.getenv('API_KEY')
          },
          json={
              'productId': product_id,
              'typeId': type_id,
              'quantity': quantity
          }
      )

      result = response.json()

      if not response.ok:
          raise Exception(result.get('message', 'Order failed'))

      return result['data']['orderId']

  # Usage
  order_id = place_order('507f1f77bcf86cd799439011', 'type_001', 2)
  print(f"Order placed: {order_id}")
  ```

  ```php PHP theme={null}
  <?php
  function placeOrder($productId, $typeId, $quantity, $apiKey) {
      $data = [
          'productId' => $productId,
          'typeId' => $typeId,
          'quantity' => $quantity
      ];

      $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: ' . $apiKey
      ]);
      curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

      $response = curl_exec($ch);
      $result = json_decode($response, true);
      curl_close($ch);

      if (!$result['success']) {
          throw new Exception($result['message'] ?? 'Order failed');
      }

      return $result['data']['orderId'];
  }

  // Usage
  $orderId = placeOrder('507f1f77bcf86cd799439011', 'type_001', 2, getenv('API_KEY'));
  echo "Order placed: $orderId\n";
  ?>
  ```

  ```javascript Node.js theme={null}
  const axios = require("axios");

  async function placeOrder(productId, typeId, quantity) {
    try {
      const response = await axios.post(
        "https://api.oneclickdz.com/v3/gift-cards/placeOrder",
        {
          productId: productId,
          typeId: typeId,
          quantity: quantity,
        },
        {
          headers: {
            "Content-Type": "application/json",
            "X-Access-Token": process.env.API_KEY,
          },
        }
      );

      if (!response.data.success) {
        throw new Error(response.data.message || "Order failed");
      }

      return response.data.data.orderId;
    } catch (error) {
      if (error.response) {
        throw new Error(error.response.data.message || "Order failed");
      }
      throw error;
    }
  }

  // Usage
  (async () => {
    try {
      const orderId = await placeOrder("507f1f77bcf86cd799439011", "type_001", 2);
      console.log(`Order placed: ${orderId}`);
    } catch (error) {
      console.error("Error placing order:", error.message);
    }
  })();
  ```

  ```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
    }'
  ```
</CodeGroup>

## Response

```json theme={null}
{
  "success": true,
  "data": {
    "orderId": "6901616fe9e88196b4eb64b3"
  }
}
```

## Error Handling

<CodeGroup>
  ```python Python theme={null}
  try:
      order_id = place_order(product_id, type_id, quantity)
      print(f"Success: {order_id}")
  except Exception as error:
      if 'stock' in str(error):
          print("Out of stock")
      elif 'balance' in str(error):
          print("Insufficient balance")
      else:
          print(f"Order failed: {error}")
  ```

  ```php PHP theme={null}
  <?php
  try {
      $orderId = placeOrder($productId, $typeId, $quantity, $apiKey);
      echo "Success: {$orderId}\n";
  } catch (Exception $error) {
      $errorMsg = strtolower($error->getMessage());

      if (strpos($errorMsg, 'stock') !== false) {
          echo "Out of stock\n";
      } elseif (strpos($errorMsg, 'balance') !== false) {
          echo "Insufficient balance\n";
      } else {
          echo "Order failed: " . $error->getMessage() . "\n";
      }
  }
  ?>
  ```

  ```javascript Node.js theme={null}
  try {
    const orderId = await placeOrder(productId, typeId, quantity);
    console.log(`Success: ${orderId}`);
  } catch (error) {
    const errorMsg = error.message.toLowerCase();

    if (errorMsg.includes("stock")) {
      console.log("Out of stock");
    } else if (errorMsg.includes("balance")) {
      console.log("Insufficient balance");
    } else {
      console.log(`Order failed: ${error.message}`);
    }
  }
  ```
</CodeGroup>

## Next Steps

After placing an order:

1. **Save the orderId** - You'll need it to check status
2. **Track the order** - Check status until fulfilled
3. **Deliver cards** - Send codes to your customer

<CardGroup cols={2}>
  <Card title="Track Order Status" icon="chart-line" href="/en/gift-card-guides/4-status-tracking">
    Monitor order until completed
  </Card>

  <Card title="Check Products" icon="search" href="/en/gift-card-guides/2-checking-products">
    Verify stock before ordering
  </Card>
</CardGroup>
