# Create Order

### Create Order Endpoint <a href="#order-createorderendpoint" id="order-createorderendpoint"></a>

#### Overview <a href="#order-overview" id="order-overview"></a>

The `/order/create` endpoint is designed for creating a new order with a list of products, specifying the wallet to be used for payment, and a reference for the order. This endpoint returns details about the order created, including an invoice with the payment status and exchange rates if applicable.

#### HTTP Request <a href="#order-httprequest" id="order-httprequest"></a>

`POST /order/create`

#### Content-Type <a href="#order-content-type" id="order-content-type"></a>

`application/json`

#### Request Body <a href="#order-requestbody" id="order-requestbody"></a>

<table data-header-hidden><thead><tr><th width="264"></th><th></th><th></th></tr></thead><tbody><tr><td>Field</td><td>Type</td><td>Description</td></tr><tr><td><code>productList</code></td><td>Array</td><td>A list of products to be included in the order. Each product object includes <code>sku</code>, <code>productType</code>, <code>quote</code>, and <code>quantity</code>.</td></tr><tr><td><code>wallet</code></td><td>String</td><td>The wallet type to be used for the payment.</td></tr><tr><td><code>reference</code></td><td>String</td><td>A reference string for the order.</td></tr><tr><td><code>webhookUrl</code></td><td>URL String | Optional</td><td><a href="https://app.gitbook.com/o/rAHTXDKVzIOr4Jqk2SBF/s/bgpTyn5ehDgNS21U6ST7/~/changes/36/webhooks/order-webhook">Read here</a></td></tr></tbody></table>

**Sample Request Body**

<pre class="language-javascript"><code class="lang-javascript"><strong>{
</strong>    "productList": [
        {
            "sku": "038-00-range",
            "productType": "range",
            "quote": 5,
            "quantity": 1
        }
    ],
    "wallet": "EUR",
    "reference": "Test Reference",
    "webhookUrl" : "YOUR WEBHOOK URL"
}
</code></pre>

#### Response <a href="#order-response" id="order-response"></a>

The response includes a message, data about the order including an `id`, exchange rates if applicable, and two invoices for wallet and retail

{% hint style="info" %}
Read [Order Invoice](https://app.gitbook.com/o/rAHTXDKVzIOr4Jqk2SBF/s/bgpTyn5ehDgNS21U6ST7/~/changes/33/orders/order-invoice) for information about the invoices and their structure.
{% endhint %}

**Response**

```javascript
{
    "message": "No Message",
    "data": {
        "id": "xQg4IeRUNIcIfJSWx6Nl",
        "exchangeRates": [
            {
                "targetCurrency": "EUR",
                "rate": 0.00001263583522870862,
                "modifiedDate": {
                    "_seconds": 1711227854,
                    "_nanoseconds": 883000000
                },
                "baseCurrency": "IRT"
            }
        ],
        "invoice": "walletInvoice",
        "retailInvoice": "retailInvoice",
        "expiresAt": 1712096042072
    }
}
```

#### Order Valid size <a href="#order-ordervalidsize" id="order-ordervalidsize"></a>

Currently we have limitation on how many items you can include in your order which is:

* Maximum **quantity per SKU** : 5
* Maximum **number of unique SKUs** in one order: 5
* Maximum **total** quantity : 25

#### Status Codes <a href="#order-statuscodes" id="order-statuscodes"></a>

| Status Code | Description                                                           |
| ----------- | --------------------------------------------------------------------- |
| 200         | `OK` - The order was successfully created.                            |
| 403         | `Unauthorized` - Authentication credentials are missing or invalid.   |
| 500         | `Internal Server Error` - An unexpected error occurred on the server. |

**Error 400 troubleshooting:**

Error 400 happens because of one of the below reasons, it is also returned in the response

| **Code** | **Message**                                                       | **Fix**                                        |
| -------- | ----------------------------------------------------------------- | ---------------------------------------------- |
| 400      | `Requested product list is bigger than allowed`                   | Reduce the size of the order.                  |
| 400      | `Your product list is not formatted well`                         | The product list items should have unique SKUs |
| 400      | `The entered quote doesn\'t match the SKU.`                       |                                                |
| 400      | `The entered quote is not in range`                               |                                                |
| 400      | `You have insufficient funds in your wallet to create this order` |                                                |
| 404      | `One or more product in the sent list are not found.`             |                                                |
| 500      | `Your requested exchange is not supported`                        |                                                |
| 500      | `Requested item is out of stock`                                  |                                                |

#### Notes <a href="#order-notes" id="order-notes"></a>

* Ensure that the product list includes all necessary details as per your product catalog specifications.
* The `expiresAt` field represents the UNIX timestamp (in milliseconds) indicating when the order or quote expires. (Normally 10 minutes)
* Exchange rates and currency conversion details are provided based on the current rates and are frozen for this order until order expiration.

***
