# Invoicing

### Guidelines

Below are some of the points you must be aware of while calling Swipez APIs:

* All API requests and responses are in JSON format.
* POST requests should include `ContentType: application/json`&#x20;
* All API response have **status, message,** and **data**.
* Swipez uses API keys to allow access to the API. Once you have signed up at our merchant site, you will be able to see your [AccessKey and SecretKey](https://www.swipez.in/merchant/profile/accesskey).

### Rate limiting

The API is rate limited per user. You will receive a 429 HTTP status code if you exceed the rate limit. The rate limit is 30 requests per minute per user and is subject to change.

### Quick Reference

| URL                                                                                                                                           | HTTP Verb | Functionality               |
| --------------------------------------------------------------------------------------------------------------------------------------------- | --------- | --------------------------- |
| [/api/v3/merchant/invoice/save](https://docs.swipez.in/invoicing-1#save-invoice)                                                              | POST      | To create invoice.          |
| [/api/v3/merchant/invoice/update](https://docs.swipez.in/invoicing-1#update-invoice)                                                          | POST      | To update created invoice.  |
| [/api/v2/merchant/invoice/settle](https://docs.swipez.in/invoicing-1#settle-invoice)                                                          | POST      | To settle invoice.          |
| [/api/v1/merchant/invoice/detail](https://docs.swipez.in/invoicing-1#get-invoice-details)                                                     | POST      | To get invoice details.     |
| [/api/v1/merchant/invoice/getlist](https://docs.swipez.in/invoicing-1#invoice-list)                                                           | POST      | To get invoice list.        |
| [/api/v1/merchant/subscription/save](https://app.gitbook.com/@swipez/s/swipez-docs/~/drafts/-MUmqisdIkG-CEp_IN8M/invoicing#save-subscription) | POST      | To save recurring invoice.  |
| [<mark style="color:blue;">/api/v3/merchant/invoice/deleteInvoice</mark>](/invoicing.md#delete-invoice)                                       | POST      | To delete or cancel invoice |

## Save invoice

<mark style="color:green;">`POST`</mark> `/api/v3/merchant/invoice/save`

This endpoint allows you to save and send invoices to customers.\
\
**Download invoice format JSON with below steps.**\
1\. Go to invoice format list <https://www.swipez.in/merchant/template/viewlist\\>
2\. Click on action button.\
3\. Choose "Upload Invoice v3 JSON" option.<br>

#### Request Body

| Name                     | Type    | Description                                                                                                                      |
| ------------------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------- |
| access\_key\_id          | string  | Your access key.                                                                                                                 |
| secret\_access\_key      | string  | Your secret access key.                                                                                                          |
| template\_id             | string  | Invoice format encrypted key.                                                                                                    |
| invoice                  | array   | Array of multiple invoices.                                                                                                      |
| customer\_code           | string  | Customer unique number.                                                                                                          |
| bill\_cycle\_name        | string  | Billing cycle name eg. Feb21                                                                                                     |
| franchise\_id            | integer | If you enable "Franchise" plugin in your invoice format you can set franchise id which you will get from franchise list.         |
| vendor\_id               | integer | If you enable "Vendor" plugin in your invoice format you can set vendor id which you will get from vendor list.                  |
| bill\_date               | string  | Bill date (in the format of YYYY-mm-dd)                                                                                          |
| due\_date                | string  | Due date (in the format of YYYY-mm-dd)                                                                                           |
| notify\_patron           | number  | Notification send to customer value 1 for yes 0 for no.                                                                          |
| custom\_header\_fields   | string  | If you added custom field in invoice format you can set value for that column.                                                   |
| particular\_rows         | string  | Set values for particular rows as per invoice format like Item, Description, Cost etc.                                           |
| advance\_received        | integer | If you enable "Prepaid invoice" plugin in invoice format you can set received amount.                                            |
| enable\_partial\_payment | integer | If you enable "Partial payment" plugin in invoice format you can set 1 for enable 0 for disable partial payment for this invoice |
| partial\_min\_amount     | string  | Partial minimum amount.                                                                                                          |
| cc\_email                | array   | If you enable "CC email" plugin in your invoice format you can set emails for cc in this invoice.                                |
| coupon                   | array   | If you enable "Coupon" plugin in your invoice format you can set coupon id or coupon details in this array.                      |
| deduct\_rows             | array   | If you enable "Deductible" plugin in your invoice format you can set deduct tax details like tax name, percent, applicable.      |
| tax\_rows                | array   | Add taxes to invoice eg. Tax name, percentage, applicable on                                                                     |
| new\_customer            | array   | If customer does not exist in Swipez then you can add customer details                                                           |
| settlement               | array   | If you want to settle invoice immediately after creating invoice                                                                 |

{% tabs %}
{% tab title="200 Invoice saved successfully." %}

```
{
    "reqtime": "2021-03-01 18:59:41",
    "resptime": "2021-03-01 18:59:41",
    "srvrsp": [
        {
            "invoice_id": "R000029148",
            "code": "12121",
            "bill_date": "2021-03-01",
            "patron_name": "Rohit Sharma",
            "email_id": "user@swipez.in",
            "mobile": "9999999999",
            "amount": "590.00",
            "short_url": "https://go.swipez.in/9vb786"
        }
    ],
    "errcode": 0,
    "errmsg": "",
    "errlist": null
}
```

{% endtab %}
{% endtabs %}

#### Sample code

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

```javascript
curl --location --request POST '<BASE URL>/api/v3/merchant/invoice/save' \
--header 'Content-Type: application/json' \
--data-raw '{
	"access_key_id": "<GET ACCESS KEY ID FROM YOUR ACCOUNT>",
	"secret_access_key": "<GET SECRET ACCESS KEY FROM YOUR ACCOUNT>",
	"template_id": "<GET TEMPLATE ID FROM YOUR ACCOUNT>",
	"invoice": [
		{
			"customer_code": "Cust-1",
			"bill_cycle_name": "Feb 21",
			"bill_date": "2021-02-01",
			"due_date": "2021-02-05",
			"invoice_properties": {
				"notify_patron": "1"
			},
			"custom_header_fields": [
				{
					"id": "1853191",
					"name": "Invoice no",
					"type": "text",
					"value": "INV-5"
				}
			],
			"particular_rows": [
				{
					"item": "Product name",
					"sac_code": "9899",
					"description": "Product description",
					"gst": "18",
					"total_amount": "1500.00"
				}
			],
			"tax_rows": [
				{
					"name": "IGST@18%",
					"percentage": "18.00",
					"applicable_on": "1500.00"
				}
			],
			"new_customer": {
				"customer_code": "",
				"customer_name": "",
				"email": "",
				"mobile": "",
				"address": "",
				"city": "",
				"state": "",
				"zipcode": "",
				"custom_fields": [
					{
						"id": "845",
						"name": "GST",
						"type": "gst",
						"value": ""
					}
				]
			},
			"settlement": {
			        "access_key_id": "<GET ACCESS KEY ID FROM YOUR ACCOUNT>",
				"secret_access_key": "<GET SECRET ACCESS KEY FROM YOUR ACCOUNT>",
			        "invoice_id": "",
			        "paid_date": "2022-02-23",
			        "amount": "18.00",
			        "mode": "Online",
			        "bank_name": "",
			        "bank_ref_no": "1234567",
			        "cheque_no": "",
			        "cash_paid_to": "",
			        "notify": "1",
			        "attach_invoice_pdf": "1"
			}
		}
	]
}'

```

{% endtab %}

{% tab title="PHP" %}

```

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => '<BASE URL>/api/v3/merchant/invoice/save',
  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 =>'{
	"access_key_id": "<GET ACCESS KEY ID FROM YOUR ACCOUNT>",
	"secret_access_key": "<GET SECRET ACCESS KEY FROM YOUR ACCOUNT>",
	"template_id": "<GET TEMPLATE ID FROM YOUR ACCOUNT>",
	"invoice": [
		{
			"customer_code": "Cust-1",
			"bill_cycle_name": "Feb 21",
			"bill_date": "2021-02-01",
			"due_date": "2021-02-05",
			"invoice_properties": {
				"notify_patron": "1"
			},
			"custom_header_fields": [
				{
					"id": "1853191",
					"name": "Invoice no",
					"type": "text",
					"value": "INV-5"
				}
			],
			"particular_rows": [
				{
					"item": "Product name",
					"sac_code": "9899",
					"description": "Product description",
					"gst": "18",
					"total_amount": "1500.00"
				}
			],
			"tax_rows": [
				{
					"name": "IGST@18%",
					"percentage": "18.00",
					"applicable_on": "1500.00"
				}
			],
			"new_customer": {
				"customer_code": "",
				"customer_name": "",
				"email": "",
				"mobile": "",
				"address": "",
				"city": "",
				"state": "",
				"zipcode": "",
				"custom_fields": [
					{
						"id": "845",
						"name": "GST",
						"type": "gst",
						"value": ""
					},
					{
						"id": "846",
						"name": "Company Name",
						"type": "company_name",
						"value": ""
					}
				]
			},
			"settlement": {
			        "access_key_id": "<GET ACCESS KEY ID FROM YOUR ACCOUNT>",
				"secret_access_key": "<GET SECRET ACCESS KEY FROM YOUR ACCOUNT>",
			        "invoice_id": "",
			        "paid_date": "2022-02-23",
			        "amount": "18.00",
			        "mode": "Online",
			        "bank_name": "",
			        "bank_ref_no": "1234567",
			        "cheque_no": "",
			        "cash_paid_to": "",
			        "notify": "1",
			        "attach_invoice_pdf": "1"
			}
		}
	]
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

{% endtab %}
{% endtabs %}

## Update invoice

<mark style="color:green;">`POST`</mark> `/api/v3/merchant/invoice/update`

\
This endpoint allows you to update created invoice.\
\
Download invoice format JSON with below steps. \
1\. Go to invoice format list <https://www.swipez.in/merchant/template/viewlist> \
2\. Click on action button. \
3\. Choose "Update Invoice v3 JSON" option.

#### Request Body

| Name                     | Type    | Description                                                                                                                      |
| ------------------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------- |
| invoice\_id              | string  | Swipez system generated invoice id.                                                                                              |
| access\_key\_id          | string  | Your access key.                                                                                                                 |
| secret\_access\_key      | string  | Your secret access key.                                                                                                          |
| template\_id             | string  | Invoice format encrypted key.                                                                                                    |
| invoice                  | array   | Array of invoice detail.                                                                                                         |
| customer\_code           | string  | Customer unique number.                                                                                                          |
| bill\_cycle\_name        | string  | Billing cycle name eg. Feb21                                                                                                     |
| franchise\_id            | integer | If you enable "Franchise" plugin in your invoice format you can set franchise id which you will get from franchise list.         |
| vendor\_id               | integer | If you enable "Vendor" plugin in your invoice format you can set vendor id which you will get from vendor list.                  |
| bill\_date               | string  | Bill date (in the format of YYYY-mm-dd)                                                                                          |
| due\_date                | string  | Due date (in the format of YYYY-mm-dd)                                                                                           |
| notify\_patron           | number  | Notification send to customer value 1 for yes 0 for no.                                                                          |
| custom\_header\_fields   | string  | If you added custom field in invoice format you can set value for that column.                                                   |
| particular\_rows         | string  | Set values for particular rows as per invoice format like Item, Description, Cost etc.                                           |
| advance\_received        | integer | If you enable "Prepaid invoice" plugin in invoice format you can set received amount.                                            |
| enable\_partial\_payment | integer | If you enable "Partial payment" plugin in invoice format you can set 1 for enable 0 for disable partial payment for this invoice |
| partial\_min\_amount     | string  | Partial minimum amount.                                                                                                          |
| cc\_email                | array   | If you enable "CC email" plugin in your invoice format you can set emails for cc in this invoice.                                |
| coupon                   | array   | If you enable "Coupon" plugin in your invoice format you can set coupon id or coupon details in this array.                      |
| deduct\_rows             | array   | If you enable "Deductible" plugin in your invoice format you can set deduct tax details like tax name, percent, applicable.      |
| tax\_rows                | array   | Add taxes to invoice eg. Tax name, percentage, applicable on                                                                     |
| new\_customer            | array   | If customer does not exist in Swipez then you can add customer details                                                           |

{% tabs %}
{% tab title="200 Invoice saved successfully." %}

```
{
    "reqtime": "2021-03-01 18:59:41",
    "resptime": "2021-03-01 18:59:41",
    "srvrsp": [
        {
            "invoice_id": "R000029148",
            "code": "12121",
            "bill_date": "2021-03-01",
            "patron_name": "Rohit Sharma",
            "email_id": "user@swipez.in",
            "mobile": "9999999999",
            "amount": "590.00",
            "short_url": "https://go.swipez.in/9vb786"
        }
    ],
    "errcode": 0,
    "errmsg": "",
    "errlist": null
}
```

{% endtab %}
{% endtabs %}

#### Sample code

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

```javascript
curl --location --request POST '<BASE URL>/api/v3/merchant/invoice/update' \
--header 'Content-Type: application/json' \
--data-raw '{
	"access_key_id": "<GET ACCESS KEY ID FROM YOUR ACCOUNT>",
	"secret_access_key": "<GET SECRET ACCESS KEY FROM YOUR ACCOUNT>",
	"invoice_id": "<SYSTEM GENERATED INVOICE ID>",
	"invoice": 
		{
			"customer_code": "Cust-1",
			"bill_cycle_name": "Feb 21",
			"bill_date": "2021-02-01",
			"due_date": "2021-02-05",
			"invoice_properties": {
				"notify_patron": "1"
			},
			"custom_header_fields": [
				{
					"id": "1853191",
					"name": "Invoice no",
					"type": "text",
					"value": "INV-5"
				}
			],
			"particular_rows": [
				{
					"item": "Product name",
					"sac_code": "9899",
					"description": "Product description",
					"gst": "18",
					"total_amount": "1500.00"
				}
			],
			"tax_rows": [
				{
					"name": "IGST@18%",
					"percentage": "18.00",
					"applicable_on": "1500.00"
				}
			],
			"new_customer": {
				"customer_code": "",
				"customer_name": "",
				"email": "",
				"mobile": "",
				"address": "",
				"city": "",
				"state": "",
				"zipcode": "",
				"custom_fields": [
					{
						"id": "845",
						"name": "GST",
						"type": "gst",
						"value": ""
					},
					{
						"id": "846",
						"name": "Company Name",
						"type": "company_name",
						"value": ""
					}
				]
			}
		}
}'

```

{% endtab %}

{% tab title="PHP" %}

```

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => '<BASE URL>/api/v3/merchant/invoice/save',
  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 =>'{
	"access_key_id": "<GET ACCESS KEY ID FROM YOUR ACCOUNT>",
	"secret_access_key": "<GET SECRET ACCESS KEY FROM YOUR ACCOUNT>",
	"invoice_id": "<SYSTEM GENERATED INVOICE ID>",
	"invoice": 
		{
			"customer_code": "Cust-1",
			"bill_cycle_name": "Feb 21",
			"bill_date": "2021-02-01",
			"due_date": "2021-02-05",
			"invoice_properties": {
				"notify_patron": "1"
			},
			"custom_header_fields": [
				{
					"id": "1853191",
					"name": "Invoice no",
					"type": "text",
					"value": "INV-5"
				}
			],
			"particular_rows": [
				{
					"item": "Product name",
					"sac_code": "9899",
					"description": "Product description",
					"gst": "18",
					"total_amount": "1500.00"
				}
			],
			"tax_rows": [
				{
					"name": "IGST@18%",
					"percentage": "18.00",
					"applicable_on": "1500.00"
				}
			],
			"new_customer": {
				"customer_code": "",
				"customer_name": "",
				"email": "",
				"mobile": "",
				"address": "",
				"city": "",
				"state": "",
				"zipcode": "",
				"custom_fields": [
					{
						"id": "845",
						"name": "GST",
						"type": "gst",
						"value": ""
					}
				]
			}
		}
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

{% endtab %}
{% endtabs %}

## Settle invoice

<mark style="color:green;">`POST`</mark> `/api/v2/merchant/invoice/settle`

This endpoint allows you to settle invoice with transaction details

#### Request Body

| Name                 | Type    | Description                                  |
| -------------------- | ------- | -------------------------------------------- |
| access\_key\_id      | string  | Your access key.                             |
| secret\_access\_key  | string  | Your secret key.                             |
| invoice\_id          | string  | System generated invoice id.                 |
| paid\_date           | string  | Payment date (in the format YYYY-mm-dd)      |
| amount               | number  | Settlement amount.                           |
| mode                 | string  | Payment mode (NEFT,Cheque,Cash,Online)       |
| bank\_name           | string  | Bank name of transaction.                    |
| bank\_ref\_no        | string  | Bank reference number                        |
| cheque\_no           | string  | Cheque number if mode is Cheque              |
| cash\_paid\_to       | string  | Cash receiver name.                          |
| notify               | integer | Want to send receipt to customer (1 or 0)    |
| attach\_invoice\_pdf | integer | Want to attach invoice pdf in email (1 or 0) |

{% tabs %}
{% tab title="200 Invoice settled successfully. " %}

```
{
    "reqtime": "2021-03-01 20:21:09",
    "resptime": "2021-03-01 20:21:09",
    "srvrsp": {
        "invoice_id": "R000029148",
        "code": "12121",
        "transaction_id": "H000001297",
        "paid_date": "2021-03-01",
        "patron_name": "Rohit Sharma",
        "email_id": "user@swipez.in",
        "amount": "500.00"
    },
    "errcode": 0,
    "errmsg": "",
    "errlist": null
}
```

{% endtab %}
{% endtabs %}

#### Sample code

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

```
curl --location --request POST '<BASE URL>/api/v2/merchant/invoice/settle' \
--header 'Content-Type: application/json' \
--data-raw '{
	"access_key_id": "<GET ACCESS KEY ID FROM YOUR ACCOUNT>",
	"secret_access_key": "<GET SECRET ACCESS KEY FROM YOUR ACCOUNT>",
	"invoice_id": "<SYSTEM GENERATED INVOICE ID>",
	"paid_date": "2021-03-01",
	"amount": "500.00",
	"mode": "Online",
	"bank_name": "",
	"bank_ref_no": "8749540",
	"cheque_no": "",
	"cash_paid_to": "",
	"notify": "1"
}'
```

{% endtab %}

{% tab title="PHP" %}

```

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => '<BASE URL>/api/v2/merchant/invoice/settle',
  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 =>'{
	"access_key_id": "<GET ACCESS KEY ID FROM YOUR ACCOUNT>",
	"secret_access_key": "<GET SECRET ACCESS KEY FROM YOUR ACCOUNT>",
	"invoice_id": "<SYSTEM GENERATED INVOICE ID>",
	"paid_date": "2021-03-01",
	"amount": "500.00",
	"mode": "Online",
	"bank_name": "",
	"bank_ref_no": "8749540",
	"cheque_no": "",
	"cash_paid_to": "",
	"notify": "0"
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
	),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

{% endtab %}
{% endtabs %}

## Get invoice details

<mark style="color:green;">`POST`</mark> `/api/v1/merchant/invoice/detail`

This endpoint allows you to get invoice details.

#### Request Body

| Name                | Type   | Description                  |
| ------------------- | ------ | ---------------------------- |
| access\_key\_id     | string | Your access key.             |
| secret\_access\_key | string | Your secret key.             |
| invoice\_id         | string | System generated invoice id. |

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

```
{
    "reqtime": "2021-03-02 09:40:48",
    "resptime": "2021-03-02 09:40:49",
    "srvrsp": {
        "invoice_id": "R000029148",
        "invoice_number": "INV-5",
        "bill_date": "01 Mar 2021",
        "due_date": "01 Mar 2021",
        "cycle_name": "Test",
        "customer_code": "12121",
        "customer_name": "Rohit Sharma",
        "email": "user@swipez.in",
        "mobile": "9999999999",
        "address": "26/2, Herms paras, near Joggers park,Kalyani nagar",
        "city": "Delhi",
        "zipcode": "490014",
        "state": "Delhi",
        "narrative": "",
        "absolute_cost": "590.00",
        "paid_amount": "0.00",
        "advance": "0.00",
        "previous_due": "0.00",
        "late_fee": "0.00",
        "franchise_id": "0",
        "short_url": "https://shr.swipez.in/9vb987",
        "invoice_status": "Paid offline",
        "custom_column": [
            {
                "column_name": "Custom column 1",
                "value": "Custom value"
            }
        ],
        "particular": [
            {
                "item": "Maintenance Charges",
                "sac_code": "99998",
                "description": "Test",
                "total_amount": "500.00"
            }
        ],
        "tax": [
            {
                "tax_name": "CGST@9%",
                "percentage": "9.00",
                "applicable_on": "500.00",
                "amount": "45.00",
                "narrative": ""
            },
            {
                "tax_name": "SGST@9%",
                "percentage": "9.00",
                "applicable_on": "500.00",
                "amount": "45.00",
                "narrative": ""
            }
        ]
    },
    "errcode": null,
    "errmsg": "",
    "errlist": null
}
```

{% endtab %}
{% endtabs %}

#### Sample code

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

```
curl --location --request POST '<BASE URL>/api/v1/merchant/invoice/detail' \
--header 'Content-Type: application/json' \
--data-raw '{
	"access_key_id": "<GET ACCESS KEY ID FROM YOUR ACCOUNT>",
	"secret_access_key": "<GET SECRET ACCESS KEY FROM YOUR ACCOUNT>",
	"invoice_id": "<SYSTEM GENERATED INVOICE ID>"
}'
```

{% endtab %}

{% tab title="PHP" %}

```
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => '<BASE URL>/api/v1/merchant/invoice/detail',
  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 =>'{
	"access_key_id": "<GET ACCESS KEY ID FROM YOUR ACCOUNT>",
	"secret_access_key": "<GET SECRET ACCESS KEY FROM YOUR ACCOUNT>",
	"invoice_id": "<SYSTEM GENERATED INVOICE ID>"
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

{% endtab %}
{% endtabs %}

## Invoice list

<mark style="color:green;">`POST`</mark> `/api/v1/merchant/invoice/getlist`

This endpoint allows you to get list of invoices.

#### Request Body

| Name                | Type   | Description                                                          |
| ------------------- | ------ | -------------------------------------------------------------------- |
| access\_key\_id     | string | Your access key.                                                     |
| secret\_access\_key | string | Your secret key.                                                     |
| from\_date          | string | From date (in the format YYYY-mm-dd) from which you want the data.   |
| to\_date            | string | To Date till you want the data                                       |
| filter\_by          | string | Filter by date type (bill\_date,due\_date,sent\_date)                |
| invoice\_status     | string | Filter by invoice status (Submitted,Failed,Paid online,Paid offline) |
| customer\_code      | string | Filter by customer code.                                             |
| group               | string | Filter by customer group.                                            |
| franchise\_id       | string | Filter by franchise.                                                 |

{% tabs %}
{% tab title="200 Invoices successfully retrieved." %}

```
{
    "reqtime": "2021-03-02 10:09:15",
    "resptime": "2021-03-02 10:09:15",
    "total_records": 2,
    "srvrsp": [
        {
            "invoice_id": "R000029148",
            "invoice_number": null,
            "bill_date": "2021-03-01",
            "due_date": "2021-03-01",
            "sent_date": "2021-03-01 18:59:41",
            "customer_code": "12121",
            "customer_name": "Rohit Sharma ",
            "customer_group": "All,Cricket",
            "email": "rohit@swipez.in",
            "mobile": "9999999999",
            "address": "26/2, Herms paras, near Joggers park,Kalyani nagar",
            "city": "Mumbai",
            "state": "Maharashtra",
            "zipcode": "400214",
            "amount": "590.00",
            "paid_amount": "0.00",
            "status": "Paid offline",
            "cycle_name": "Test",
            "franchise_id": "0",
            "franchise_name": null,
            "created_by": "Test company"
        },
        {
            "invoice_id": "R000029147",
            "invoice_number": "INV655",
            "bill_date": "2021-02-15",
            "due_date": "2021-02-15",
            "sent_date": "2021-02-15 16:36:01",
            "customer_code": "C000359",
            "customer_name": "Virat Kohli",
            "customer_group": "All",
            "email": "virat@swipez.in",
            "mobile": "9999999998",
            "address": "",
            "city": "Delhi",
            "state": "Delhi",
            "zipcode": "400014",
            "amount": "826.00",
            "paid_amount": "0.00",
            "status": "Paid offline",
            "cycle_name": "Test Fee",
            "franchise_id": "0",
            "franchise_name": null,
            "created_by": "Test company"
        }
        
    ],
    "errcode": null,
    "errmsg": "",
    "errlist": null
}
```

{% endtab %}
{% endtabs %}

#### Sample code

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

```
curl --location --request POST '<BASE URL>/api/v1/merchant/invoice/getlist' \
--header 'Content-Type: application/json' \
--data-raw '{
	"access_key_id": "<GET ACCESS KEY ID FROM YOUR ACCOUNT>",
	"secret_access_key": "<GET SECRET ACCESS KEY FROM YOUR ACCOUNT>",
	"from_date": "2021-02-04",
	"to_date": "2021-03-03",
	"filter_by": "bill_date",
	"invoice_status": "",
	"customer_code": "",
	"group": "",
	"franchise_id": ""
}'
```

{% endtab %}

{% tab title="PHP" %}

```

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => '<BASE URL>/api/v1/merchant/invoice/getlist',
  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 =>'{
	"access_key_id": "<GET ACCESS KEY ID FROM YOUR ACCOUNT>",
	"secret_access_key": "<GET SECRET ACCESS KEY FROM YOUR ACCOUNT>",
	"from_date": "2021-02-04",
	"to_date": "2021-03-03",
	"filter_by": "bill_date",
	"invoice_status": "",
	"customer_code": "",
	"group": "",
	"franchise_id": ""
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

{% endtab %}
{% endtabs %}

## Save subscription

<mark style="color:green;">`POST`</mark> `/api/v1/merchant/subscription/save`

This endpoint allows you to save recurring invoicing.&#x20;

#### Request Body

| Name                   | Type   | Description                                                                                                                                                     |
| ---------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| access\_key\_id        | string | Your access key                                                                                                                                                 |
| secret\_access\_key    | string | Your secret key.                                                                                                                                                |
| template\_id           | string | Invoice format encrypted key.                                                                                                                                   |
| mode                   | string | Recurring mode (Monthly, Daily, Weekly, Yearly)                                                                                                                 |
| repeat\_every          | number | Repeat every recurring mode eg. 3 Months                                                                                                                        |
| start\_date            | string | Start date of invoice creation                                                                                                                                  |
| due\_date              | string | Due date of first invoice.                                                                                                                                      |
| end\_mode              | string | <p>Recurring stop mode <br>Never: It will be infinite<br>Occurences: After occurrence subscription will end<br>End date: Set end date to stop subscription </p> |
| occurences             | number | Set occurrence value if end mode is Occurrences                                                                                                                 |
| end\_date              | string | Set end date if end mode is "End date"                                                                                                                          |
| carry\_forword\_dues   | string | If you want to carry forward due of unpaid invoices                                                                                                             |
| invoice                | string | Invoice data.                                                                                                                                                   |
| customer\_code         | string | Customer identifier.                                                                                                                                            |
| bill\_cycle\_name      | string | Billing cycle name eg. Feb 21                                                                                                                                   |
| bill\_date             | string | Bill date (in the format of YYYY-mm-dd)                                                                                                                         |
| notify\_patron         | number | Invoice notification to customer, 1 for enable                                                                                                                  |
| custom\_header\_fields | string | If you added custom fields in your invoice format you can set value for that column.                                                                            |
| particular\_rows       | string | Set values for particular rows as per your invoice format like Item name, Description, Cost                                                                     |
| tax\_rows              | string | Add taxes to invoice.                                                                                                                                           |
| new\_customer          | string | If customer does not exist in Swipez then you can add customer details.                                                                                         |

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

```
```

{% endtab %}
{% endtabs %}

#### Sample code

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

```
curl --location --request POST '<BASE URL>/api/v1/merchant/subscription/save' \
--header 'Content-Type: application/json' \
--data-raw '{
	"access_key_id": "<GET ACCESS KEY ID FROM YOUR ACCOUNT>",
	"secret_access_key": "<GET SECRET ACCESS KEY FROM YOUR ACCOUNT>",
	"template_id": "<GET TEMPLATE ID FROM YOUR ACCOUNT>",
	"mode": "Monthly",
	"repeat_every": "3",
	"start_date": "2021-03-01",
	"due_date": "2021-03-07",
	"end_mode": "Never",
	"occurences": "",
	"end_date": "",
	"carry_forword_dues": "0",
	"invoice": 
		{
			"customer_code": "Cust-1",
			"bill_cycle_name": "Feb 21",
			"bill_date": "2021-02-01",
			"due_date": "2021-02-05",
			"invoice_properties": {
				"notify_patron": "1"
			},
			"custom_header_fields": [
				{
					"id": "1853191",
					"name": "Invoice no",
					"type": "text",
					"value": "INV-5"
				}
			],
			"particular_rows": [
				{
					"item": "Product name",
					"sac_code": "9899",
					"description": "Product description",
					"gst": "18",
					"total_amount": "1500.00"
				}
			],
			"tax_rows": [
				{
					"name": "IGST@18%",
					"percentage": "18.00",
					"applicable_on": "1500.00"
				}
			],
			"new_customer": {
				"customer_code": "",
				"customer_name": "",
				"email": "",
				"mobile": "",
				"address": "",
				"city": "",
				"state": "",
				"zipcode": "",
				"custom_fields": [
					{
						"id": "845",
						"name": "GST",
						"type": "gst",
						"value": ""
					}
				]
			}
		}
	
}'
```

{% endtab %}

{% tab title="PHP" %}

```

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => '<BASE URL>/api/v1/merchant/subscription/save',
  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 =>'{
	"access_key_id": "<GET ACCESS KEY ID FROM YOUR ACCOUNT>",
	"secret_access_key": "<GET SECRET ACCESS KEY FROM YOUR ACCOUNT>",
	"template_id": "<GET TEMPLATE ID FROM YOUR ACCOUNT>",
	"mode": "Monthly",
	"repeat_every": "3",
	"start_date": "2021-03-01",
	"due_date": "2021-03-07",
	"end_mode": "Never",
	"occurences": "",
	"end_date": "",
	"carry_forword_dues": "0",
	"invoice": 
		{
			"customer_code": "Cust-1",
			"bill_cycle_name": "Feb 21",
			"bill_date": "2021-02-01",
			"due_date": "2021-02-05",
			"invoice_properties": {
				"notify_patron": "1"
			},
			"custom_header_fields": [
				{
					"id": "1853191",
					"name": "Invoice no",
					"type": "text",
					"value": "INV-5"
				}
			],
			"particular_rows": [
				{
					"item": "Product name",
					"sac_code": "9899",
					"description": "Product description",
					"gst": "18",
					"total_amount": "1500.00"
				}
			],
			"tax_rows": [
				{
					"name": "IGST@18%",
					"percentage": "18.00",
					"applicable_on": "1500.00"
				}
			],
			"new_customer": {
				"customer_code": "",
				"customer_name": "",
				"email": "",
				"mobile": "",
				"address": "",
				"city": "",
				"state": "",
				"zipcode": "",
				"custom_fields": [
					{
						"id": "845",
						"name": "GST",
						"type": "gst",
						"value": ""
					}
				]
			}
		}
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

{% endtab %}
{% endtabs %}

## Delete invoice&#x20;

<mark style="color:green;">`POST`</mark> `/api/v3/merchant/invoice/deleteInvoice`

This endpoint allows you to delete or cancel the invoice.

#### Request Body

| Name                                                  | Type   | Description                                                      |
| ----------------------------------------------------- | ------ | ---------------------------------------------------------------- |
| access\_key\_id<mark style="color:red;">\*</mark>     | String | Your access key                                                  |
| secret\_access\_key<mark style="color:red;">\*</mark> | String | Your secret key.                                                 |
| invoice\_id<mark style="color:red;">\*</mark>         | String | System generated invoice id.                                     |
| status<mark style="color:red;">\*</mark>              | String | <p>Filter by invoice status</p><p>(12-cancelled, 13-deleted)</p> |

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

```javascript
{
    "reqtime": "2022-02-25 18:59:19",
    "resptime": "2022-02-25 18:59:19",
    "srvrsp": {
        "invoice_id": "R000030213"
    },
    "errcode": 0,
    "errmsg": "",
    "errlist": null
}
```

{% endtab %}
{% endtabs %}

**Sample Code**

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

```
curl --location --request POST '<BASE URL>/api/v3/merchant/invoice/deleteInvoice' \
--header 'Content-Type: application/json' \
--data-raw '{
	"access_key_id": "<GET ACCESS KEY ID FROM YOUR ACCOUNT>",
	"secret_access_key": "<GET SECRET ACCESS KEY FROM YOUR ACCOUNT>",
	"invoice_id": "<SYSTEM GENERATED INVOICE ID>",
	"status": "12"    //12 cancelled, 13 deleteted
}'
```

{% endtab %}

{% tab title="PHP" %}

```

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => '<BASE URL>/api/v3/merchant/invoice/deleteInvoice',
  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 =>'{
	"access_key_id": "<GET ACCESS KEY ID FROM YOUR ACCOUNT>",
	"secret_access_key": "<GET SECRET ACCESS KEY FROM YOUR ACCOUNT>",
	"invoice_id": "<SYSTEM GENERATED INVOICE ID>",
	"status": "12"    //12 cancelled, 13 deleteted
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: 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:

```
GET https://docs.swipez.in/invoicing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
