> For the complete documentation index, see [llms.txt](https://docs.xtrakit.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.xtrakit.com/overview/sales/add-sale.md).

# Add Sale

## Endpoint

<mark style="color:yellow;">**`POST`**</mark> `https://api.xtrakit.com/api/v1/sales/add`

## Headers

`Authorization: Bearer API_KEY`

## **Body Parameters**

<table><thead><tr><th width="336">Parameters</th><th width="100">Type</th><th>Description</th></tr></thead><tbody><tr><td><p>invoice_code </p><p><em><strong>string</strong></em></p></td><td>Required</td><td>An invoice code is a unique 6-digit code to generate. </td></tr><tr><td><p>invoice_number </p><p><em><strong>string</strong></em></p></td><td>Required</td><td>An invoice number is a unique 6-digit code to generate.  Prefix depends on the one you set on the system which would be appended automatically. <code>Example: INV-000001</code></td></tr><tr><td><p>customer_id </p><p><em><strong>int</strong></em></p></td><td>Required</td><td>You can retrieve customer IDs from customers created and pull their primary ID here.</td></tr><tr><td><p>sub_total_amount </p><p><em><strong>decimal (10,2)</strong></em></p></td><td>Required</td><td>Subtotal amount of your sales in this format: <code>10.00</code></td></tr><tr><td><p>total_amount </p><p><em><strong>decimal (10,2)</strong></em></p></td><td>Required</td><td>The total amount of your sales after adding everything including tax, discount, etc. In this format: <code>10.00</code></td></tr><tr><td><p>amount_paid </p><p><em><strong>decimal (10,2)</strong></em></p></td><td>Required</td><td>The amount received from the customer when creating this sale. If the amount is zero (0) and the payment method is none, it means the invoice status is <code>DRAFT</code></td></tr><tr><td><p>discount </p><p><em><strong>decimal (10,2)</strong></em></p></td><td>Optional</td><td>Discounts given to the customer on sale can be <code>null.</code> Discount is in value not percentage. <code>Example: 10.00</code></td></tr><tr><td><p>invoice_type </p><p><em><strong>string</strong></em></p></td><td>Required</td><td>We have 3 types of invoices in our system, with 3 Statuses: <code>main</code>, <code>pos</code>, and <code>order</code>. So, the main is the XtraKit dashboard, pos is the XtraPOS, and order is the Storefront.</td></tr><tr><td><p>invoice_colour </p><p><em><strong>string</strong></em></p></td><td>Optional</td><td>To set your custom invoice colour, you need to put colour by using a colour code like this: <code>#FFFFFF</code></td></tr><tr><td><p>invoice_note </p><p><em><strong>string</strong></em></p></td><td>Optional</td><td>If you want to add a message to your invoice.</td></tr><tr><td><p>invoice_terms</p><p><em><strong>string</strong></em></p></td><td>Optional</td><td>What terms and conditions do you want to add to the invoice? Maybe half payment should be made before work.</td></tr><tr><td><p>payment_type</p><p><em><strong>string</strong></em></p></td><td>Required</td><td>Payment method or type can be of these options: <code>None</code>, <code>Mobile Money</code>, <code>Cash</code>, <code>Bank Transfer / Deposit</code>, <code>Cheque</code>, <code>Card Payment, Digital Payment</code> and <code>Other Payment</code></td></tr><tr><td><p>payment_internal_note</p><p><em><strong>string</strong></em></p></td><td>Optional</td><td>You want to add any payment message for internal use only. The customer won't see this message.</td></tr><tr><td><p>issued_by</p><p><em><strong>string</strong></em></p></td><td>Optional</td><td>Name of the person who issued the invoice. Example: <code>Jones Nathal</code></td></tr><tr><td><p>due_date</p><p><em><strong>string</strong></em></p></td><td>Required</td><td>The latest date for when you must pay your invoice. Date format: <code>2024-08-30</code></td></tr><tr><td><p>reminder_date</p><p><em><strong>string</strong></em></p></td><td>Optional</td><td>The date you want us to send a reminder to the client on invoice payment. Date format: <code>2024-08-30</code></td></tr><tr><td><p>reminder_message</p><p><em><strong>string</strong></em></p></td><td>Optional</td><td>The reminder message you want us to send to the customer on the reminder date.</td></tr></tbody></table>

## Sample Requests <a href="#sample-requests" id="sample-requests"></a>

{% tabs %}
{% tab title="PHP" %}
{% code fullWidth="true" %}

```php
<?php

$curl = curl_init();

$data = [
    "invoice_number" => "INV-000001",
    "customer_id" => "42",
    "sub_total_amount" => "100.00",
    "total_amount" => "200.00",
    "amount_paid" => "200.00",
    "discount" => "0.00",
    "invoice_type" => "pos",
    "invoice_colour" => "#FFFFFF",
    "invoice_note" => "Thanks for doing business",
    "invoice_terms" => "60% payment before work commerce",
    "payment_date" => "2024-08-04",
    "payment_type" => "None",
    "payment_status" => "paid",
    "issued_by" => "Jones Nathal",
    "due_date" => "2024-08-30",
    "reminder_date" => "2024-08-25",
    "reminder_message" => ""
];
$url = 'https://api.xtrakit.com/api/v1/sales/add';

curl_setopt_array($curl, array(
  CURLOPT_URL => $url,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => $data,
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer API_KEY', // Replace 'API_KEY' with your actual API key
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

?>
```

{% endcode %}
{% endtab %}

{% tab title="NodeJS" %}

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

const data = {
    "invoice_number": "INV-000001",
    "customer_id": "42",
    "sub_total_amount": "100.00",
    "total_amount": "200.00",
    "amount_paid": "200.00",
    "discount": "0.00",
    "invoice_type": "pos",
    "invoice_colour": "#FFFFFF",
    "invoice_note": "Thanks for doing business",
    "invoice_terms": "60% payment before work commerce",
    "payment_date" : "2024-08-04",
    "payment_type": "None",
    "payment_status": "paid",
    "issued_by": "Jones Nathal",
    "due_date": "2024-08-30",
    "reminder_date": "2024-08-25",
    "reminder_message": ""
};

const config = {
    method: 'post',
    url: `https://api.xtrakit.com/api/v1/sales/add`,
    headers: {
        'Authorization': 'Bearer API_KEY' // Replace 'API_KEY' with your actual API key
    },
    data: data 
};

axios(config).then(function(response) {
    console.log(JSON.stringify(response.data));
}).catch(function(error) {
    console.error(error);
});
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

data = {
    "invoice_number": "INV-000001",
    "customer_id": "42",
    "sub_total_amount": "100.00",
    "total_amount": "200.00",
    "amount_paid": "200.00",
    "discount": "0.00",
    "invoice_type": "pos",
    "invoice_colour": "#FFFFFF",
    "invoice_note": "Thanks for doing business",
    "invoice_terms": "60% payment before work commerce",
    "payment_date" : "2024-08-04",
    "payment_type": "None",
    "payment_status": "paid",
    "issued_by": "Jones Nathal",
    "due_date": "2024-08-30",
    "reminder_date": "2024-08-25",
    "reminder_message": ""
}

url = f'https://api.xtrakit.com/api/v1/sales/add'
headers = {
    "Authorization": "Bearer API_KEY" # Replace 'API_KEY' with your actual API key
}

try:
    response = requests.post(url, headers=headers, json=data)
    print(response.json())
except requests.exceptions.RequestException as e:
    print(e)
```

{% endtab %}
{% endtabs %}

## Sample Response

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

```json
{
    "status": 200,
    "message": "Sale added successfully",
    "data": {
        "sales": {
            "id": 32,
            "invoice_code": 324232,
            "invoice_number": "INV-000001",
            "customer_id": "42",
            "sub_total_amount": "100.00",
            "total_amount": "200.00",
            "amount_paid": "200.00",
            "discount": "0.00",
            "invoice_type": "pos",
            "invoice_colour": "#FFFFFF",
            "invoice_note": "Thanks for doing business",
            "invoice_terms": null,
            "payment_internal_note": null,
            "payment_date": "2024-08-04",
            "payment_type": "None",
            "payment_status": "paid",
            "issued_by": "Jones Nathal",
            "due_date": "2024-08-30",
            "reminder_date": "2024-08-25",
            "reminder_message": null,
            "created_at": "2024-08-04 08:23:45",
            "updated_at": "2024-08-04 02:00:43"
        },
        "sales-item": [
            {
                "id": 45,
                "invoice_code": "324232",
                "invoice_number": "INV-000001",
                "item_name": "Web Design",
                "description": "Including hosting",
                "unit_price": "100.00",
                "quantity": "2",
                "tax": "0.00",
                "created_at": "2024-08-04 08:23:45",
                "updated_at": "2024-08-04 02:00:43"
            },
            ...
        ],
        "sales-payment": [
            {
                "invoice_code": "324232",
                "customer_name": "Peter Amos",
                "amount_paid": "200.00",
                "payment_method": "Cash",
                "internal_payment_note": null,
                "issued_by": "Jones Nathal",
                "payment_at": "2024-08-04 08:23:45",
                "created_at": "2024-08-04 08:23:45",
                "updated_at": "2024-08-04 02:00:43"
            },
            ...
        ]
    }
}
```

{% endtab %}

{% tab title="Error" %}

```json
{
    "status": 401,
    "error": "Unauthorized: Missing Bearer Token"
},

{
    "status": 401,
    "error": "Unauthorized: Invalid API Key"
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.xtrakit.com/overview/sales/add-sale.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
