# Create Invoice

<mark style="color:blue;">`POST`</mark> `/invoice/create`

Create a new invoice specifying currency, amount, expiration time, and other relevant parameters.

**Headers**

| Name         | Value              |
| ------------ | ------------------ |
| Content-Type | `application/json` |
| X-API-KEY    | `<token>`          |

**Body**

<table><thead><tr><th width="200">Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>currency</code><mark style="color:yellow;">*</mark></td><td>string</td><td><a href="../supported-currencies-and-networks">Currency</a></td></tr><tr><td><code>allowed_currencies</code><mark style="color:yellow;">*</mark></td><td>list[ string ]</td><td>List of <a href="../supported-currencies-and-networks">Currencies</a></td></tr><tr><td><code>amount</code><mark style="color:red;">*</mark></td><td>string</td><td>Amount of invoice like: <code>200 USD</code> <code>0.015 BNB</code></td></tr><tr><td><code>expires_time</code><mark style="color:red;">*</mark></td><td>number</td><td>Expiration time of invoice in minutes: <code>30-1440</code></td></tr><tr><td><code>label</code><mark style="color:red;">*</mark></td><td>string</td><td>Label of invoice</td></tr><tr><td><code>postback_url</code></td><td>string</td><td>Destination URL for sending post</td></tr><tr><td><code>success_url</code></td><td>string</td><td>URL for User after successful payment</td></tr><tr><td><code>fail_url</code></td><td>string</td><td>URL for User after failed payment</td></tr></tbody></table>

{% hint style="warning" %}
**Important**: currency and allowed\_currencies cannot be used together.

* If you want to lock the invoice to a single currency, set currency and leave allowed\_currencies = null.
* Otherwise, set currency = null and specify allowed\_currencies as a list of at least two currency codes.
  {% endhint %}

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
    "id": 0,
    "uuid": "string",
    "currency": "string",
    "tx_hash": "string",
    "address": "string",
    "amount": 0,
    "amount_usd": 0,
    "confirmations": 0,
    "created_at": "2019-08-24T14:15:22Z",
    "expires_at": "2019-08-24T14:15:22Z",
    "is_expired": true,
    "is_paid": true,
    "label": "string",
    "postback_url": "http://example.com",
    "success_url": "http://example.com",
    "fail_url": "http://example.com",
    "url": "http://example.com"
}
```

{% endtab %}

{% tab title="400" %}

```json
{
    "detail": "Currency does not exist"
}
```

```json
{
    "detail": "Invalid amount. Should be in range ({minimum_deposit of currency}-100,000,000)"
}
```

```json
{
    "detail": "Invalid expires_time. Should be in range (5-60) minutes"
}
```

```json
{
    "detail": "Max length of label is 255 characters"
}
```

```json
{
    "detail": "Max length of postback_url is 255 characters"
}
```

```json
{
    "detail": "Max length of success_url is 255 characters"
}
```

{% endtab %}

{% tab title="422" %}

```json
{
    "detail": [
        {
            "loc": [],
            "msg": "string",
            "type": "string"
        }
    ]
}
```

{% endtab %}
{% endtabs %}

**Example**

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST "https://api.nord-pay.com/invoice/create" \
     -H "Content-Type: application/json" \
     -H "X-API-KEY: YOUR_API_KEY" \
     -d '{
       "currency": "USDTBEP20",
       "amount": "200 USD",
       "expires_time": 1,
       "label": "Order #123",
       "postback_url": "https://example.com/postback",
       "success_url": "https://example.com/success",
       "fail_url": "http://example.com"
     }'
```

{% endtab %}

{% tab title="Python (requests)" %}

```python
import requests

def create_invoice(currency, label, amount, expires_time, postback_url=None, success_url=None):
    url = "https://api.nord-pay.com/invoice/create"
    headers = {
        "Content-Type": "application/json",
        "X-API-KEY": "YOUR_API_KEY"
    }
    payload = {
        "currency": currency,
        "label": label,
        "amount": amount,
        "expires_time": expires_time
    }
    if postback_url:
        payload["postback_url"] = postback_url
    if success_url:
        payload["success_url"] = success_url

    resp = requests.post(url, json=payload, headers=headers)
    resp.raise_for_status()
    return resp.json()

# usage:
invoice = create_invoice(
    currency="USDTBEP20",
    label="Order #123",
    amount="200 USD",
    expires_time=30,
    postback_url="https://example.com/postback",
    success_url="https://example.com/success"
)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
function createInvoice(
    string $currency,
    string $label,
    float $amount,
    int $expiresTime,
    string $postbackUrl = null,
    string $successUrl = null
): array {
    $url = "https://api.nord-pay.com/invoice/create";
    $payload = [
        "currency"     => $currency,
        "label"        => $label,
        "amount"       => $amount,
        "expires_time" => $expiresTime
    ];
    if ($postbackUrl) $payload["postback_url"] = $postbackUrl;
    if ($successUrl)  $payload["success_url"]  = $successUrl;

    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST           => true,
        CURLOPT_POSTFIELDS     => json_encode($payload),
        CURLOPT_HTTPHEADER     => [
            "Content-Type: application/json",
            "X-API-KEY: YOUR_API_KEY"
        ],
    ]);
    $response = curl_exec($ch);
    curl_close($ch);
    return json_decode($response, true);
}

// usage:
$invoice = createInvoice(
    "USDTBEP20",
    "Order #123",
    "200 USD",
    30,
    "https://example.com/postback",
    "https://example.com/success"
);
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
async function createInvoice({
  currency,
  label,
  amount,
  expires_time,
  postback_url,
  success_url
}) {
  const response = await fetch("https://api.nord-pay.com/invoice/create", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-API-KEY": "YOUR_API_KEY"
    },
    body: JSON.stringify({
      currency,
      label,
      amount,
      expires_time,
      ...(postback_url && { postback_url }),
      ...(success_url && { success_url })
    })
  });
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
  return response.json();
}

// usage:
createInvoice({
  currency: "USDTBEP20",
  label: "Order #123",
  amount: "200 USD",
  expires_time: 30,
  postback_url: "https://example.com/postback",
  success_url: "https://example.com/success"
}).then(invoice => {
  // work with invoice
});
```

{% endtab %}

{% tab title="Node.js (axios)" %}

```javascript
const axios = require('axios');

async function createInvoice({
  currency,
  label,
  amount,
  expires_time,
  postback_url,
  success_url
}) {
  const { data } = await axios.post(
    "https://api.nord-pay.com/invoice/create",
    {
      currency,
      label,
      amount,
      expires_time,
      ...(postback_url && { postback_url }),
      ...(success_url && { success_url })
    },
    {
      headers: {
        "Content-Type": "application/json",
        "X-API-KEY": "YOUR_API_KEY"
      }
    }
  );
  return data;
}

// usage:
createInvoice({
  currency: "USDTBEP20",
  label: "Order #123",
  amount: "200 USD",
  expires_time: 30,
  postback_url: "https://example.com/postback",
  success_url: "https://example.com/success"
}).then(invoice => {
  // work with invoice
});
```

{% endtab %}
{% endtabs %}
