> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.tiankii.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.tiankii.com/_mcp/server.

# Create invoice

POST https://api.md.tiankii.com/v1/invoice
Content-Type: application/json

## Create invoice

Creates a new invoice for the given store and returns a POS-ready payload (`InvoicePosDto`) containing the invoice id, hosted invoice URL, resolved payment method, crypto amount / destination and exchange rates.

### Auth
Send the merchant API key in the `x-api-key` header (alias `x-account-api-key`). The key must carry **`Merchant.invoice.create`**. Also accepts JWT user, POS JWT and Google-signed tokens. Optionally scope the key to a specific account/store with the `x-application-account-id` header (alias `x-account-id`) or the `application_account_id` query param.

### Query params
- `paymentMethod` (optional): id of the default payment method to pre-select for this invoice.

### Body
`CreateInvoiceDto` (JSON). Required: `amount`, `currency`, `storeId`.

> ⚠️ **About `storeId`**: when you authenticate with an API key the store is taken from the key, and the handler overwrites whatever you send (`data.storeId = user.store_id`). The field is nonetheless declared `@IsNotEmpty()`, so the validation pipe rejects the request if you omit it. Send it empty — the value has no effect.
 Optional: `appId`, nested `metadata` (orderId, tip, posData JSON string, description), nested `buyer` (customer contact / billing fields), `couponCode`, and `webhook` (URL notified on payment). The fields `prQuantity`, `paymentRequestId` and `lnurlpRequestId` are internal linking fields.

### Side effects
Persists a new `Invoices` record in status `new`, resolves the exchange rate and payment destination, and — if a `webhook` is supplied — registers it for payment callbacks. Unknown body properties are stripped by the global validation pipe.

---
**Notas:** storeId is required by validation but ignored for API-key callers (overwritten in createdInvoiceByUser when the principal is not POS/limited). Response type is InvoicePosDto. The DTO exposes deprecated aliases (rate, satsDue, cryptoCode, btcAddress, nationalRate, invoiceWallet, btcDue) kept for backward compatibility — prefer exchangeRate, cryptoAmount, paymentType, paymentDestination, usdExchangeRate.

Reference: https://docs.tiankii.com/api-reference/tiankii-api-api-key/invoice/create

## Authentication

- `x-api-key` header (required)

## Request

### Query parameters

- `paymentMethod` (string, optional) — Payment method to pre-select on the new charge (a `PaymentMethodsLike` value). Omit it to let the store's default resolve.

### Headers

- `x-application-account-id` (string, optional) — Scope the request to a specific store / account instead of the one resolved from the API key. Aliases: the `x-account-id` header, or the `application_account_id` / `account_id` query parameter.

### Body (application/json)

- `amount` (double, required)
- `currency` (string, required)
- `storeId` (string, required) — Leave it empty: when authenticating with an API key the store is resolved from the key and the handler overwrites whatever you send (`data.storeId = user.store_id`), so the value has no effect.

## Examples

**Request**

```json
{
  "amount": 1.5,
  "currency": "USD",
  "storeId": ""
}
```

**SDK Code**

```python
import requests

url = "https://api.md.tiankii.com/v1/invoice"

querystring = {"paymentMethod":"BTC_StrikeLike"}

payload = {
    "amount": 1.5,
    "currency": "USD",
    "storeId": ""
}
headers = {
    "x-application-account-id": "acct_3f9a21c7",
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, params=querystring)

print(response.json())
```

```javascript
const url = 'https://api.md.tiankii.com/v1/invoice?paymentMethod=BTC_StrikeLike';
const options = {
  method: 'POST',
  headers: {
    'x-application-account-id': 'acct_3f9a21c7',
    'x-api-key': '<apiKey>',
    'Content-Type': 'application/json'
  },
  body: '{"amount":1.5,"currency":"USD","storeId":""}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.md.tiankii.com/v1/invoice?paymentMethod=BTC_StrikeLike"

	payload := strings.NewReader("{\n  \"amount\": 1.5,\n  \"currency\": \"USD\",\n  \"storeId\": \"\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-application-account-id", "acct_3f9a21c7")
	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.md.tiankii.com/v1/invoice?paymentMethod=BTC_StrikeLike")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-application-account-id"] = 'acct_3f9a21c7'
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"amount\": 1.5,\n  \"currency\": \"USD\",\n  \"storeId\": \"\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.md.tiankii.com/v1/invoice?paymentMethod=BTC_StrikeLike")
  .header("x-application-account-id", "acct_3f9a21c7")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"amount\": 1.5,\n  \"currency\": \"USD\",\n  \"storeId\": \"\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.md.tiankii.com/v1/invoice?paymentMethod=BTC_StrikeLike', [
  'body' => '{
  "amount": 1.5,
  "currency": "USD",
  "storeId": ""
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
    'x-application-account-id' => 'acct_3f9a21c7',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.md.tiankii.com/v1/invoice?paymentMethod=BTC_StrikeLike");
var request = new RestRequest(Method.POST);
request.AddHeader("x-application-account-id", "acct_3f9a21c7");
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"amount\": 1.5,\n  \"currency\": \"USD\",\n  \"storeId\": \"\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "x-application-account-id": "acct_3f9a21c7",
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "amount": 1.5,
  "currency": "USD",
  "storeId": ""
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.md.tiankii.com/v1/invoice?paymentMethod=BTC_StrikeLike")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```