List All Purchases

get https://api.vendloop.com/purchases

Returns a paginated list of purchases sorted by date in descending order.

Header

Authorization
String
Set value to Bearer SECRET_KEY
supplier_id
integer
Specify an ID for the supplier whose purchases you want to retrieve
product_id
integer
Specify an ID to retrieve purchases for the selected product only
variant_id
integer
Specify an ID to retrieve purchases for the selected product variant only
user_id
integer
Specify an ID to retrieve purchases made by the selected employee only
start_date
datetime
A timestamp from which to start listing purchases. see date & time formats section
end_date
datetime
A timestamp from which to stop listing purchases. see date & time formats section
limit
integer
Specify how many records you want to retrieve per page. If not specified we use a default value of 50.
curl -L 'https://api.vendloop.com/purchases/' \
-H 'Authorization: Bearer SECRET_KEY'
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.vendloop.com/purchases',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer SECRET_KEY'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer SECRET_KEY");

var requestOptions = {
  method: 'GET',
  headers: myHeaders,
  redirect: 'follow'
};

fetch("https://api.vendloop.com/purchases", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
val client = OkHttpClient()
val request = Request.Builder()
  .url("https://api.vendloop.com/purchases")
  .addHeader("Authorization", "Bearer SECRET_KEY")
  .build()
val response = client.newCall(request).execute()

Sample Response

{
  "status":true,
  "message":"Purchase records found",
  "data":[
    {
      "id":"16",
      "date":"2023-05-23 08:17:00",
      "due_date":"2023-05-23",
      "business_id":"1",
      "store_id":"1",
      "supplier_id":"3",
      "user_id":"2",
      "reference_no":"PUR/178018695962",
      "note":"",
      "order_tax":"0.0000",
      "paid":"0.0000",
      "payment_status":"pending",
      "purchase_status":"received",
      "shipping":"0.0000",
      "total":"600.0000",
      "total_discount":"0.0000",
      "total_tax":"0.0000",
      "updated_at":null,
      "updated_by":null,
      "items":[
        {
          "cost":"50.0000",
          "discount":"0.0000",
          "id":"26",
          "name":"Apple",
          "product_id":"3",
          "quantity":"12.0000",
          "sku":"16132561",
          "tax":"0.0000",
          "tax_id":null,
          "tax_method":"subtraction",
          "type":"standard",
          "unit_code":"ball",
          "unit_id":"1"
        }
      ],
      "payments":false,
      "tax":null
    }
  ],
  "metadata":{
    "limit":50,
    "start":1,
    "total":12
  }
}
{
    "status": false,
    "message": "Purchase records not found"
}

Fetch a Single Purchase

get https://api.vendloop.com/purchases/{id}

Returns details of a purchase with the given ID.

Header

Authorization
String
Set value to Bearer SECRET_KEY
id required
integer
Auto-generated unique ID
reference
string
Specify the reference number for this purchase. this is ignored if the id parameter is used
supplier_id
integer
Specify an ID for the supplier whose purchase you want to retrieve
product_id
integer
Specify an ID to retrieve purchases for the selected product only
variant_id
integer
Specify an ID to retrieve purchases for the selected product variant only
user_id
integer
Specify an ID to retrieve purchases made by the selected employee only
start_date
datetime
A timestamp from which to start listing purchases. see date & time formats section
end_date
datetime
A timestamp from which to stop listing purchases. see date & time formats section
curl -L 'https://api.vendloop.com/purchases/{id}' \
-H 'Authorization: Bearer SECRET_KEY'
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.vendloop.com/purchases/{id}',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer SECRET_KEY'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer SECRET_KEY");

var requestOptions = {
  method: 'GET',
  headers: myHeaders,
  redirect: 'follow'
};

fetch("https://api.vendloop.com/purchases/{id}", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
val client = OkHttpClient()
val request = Request.Builder()
  .url("https://api.vendloop.com/purchases/{id}")
  .addHeader("Authorization", "Bearer SECRET_KEY")
  .build()
val response = client.newCall(request).execute()

Sample Response

{
  "status":true,
  "message":"Purchase record found",
  "data":{
    "id":"16",
    "date":"2023-05-23 08:17:00",
    "due_date":"2023-05-23",
    "business_id":"1",
    "store_id":"1",
    "supplier_id":"3",
    "user_id":"2",
    "reference_no":"PUR/178018695962",
    "note":"",
    "order_tax":"0.0000",
    "paid":"0.0000",
    "payment_status":"pending",
    "status":"received",
    "shipping":"0.0000",
    "total":"600.0000",
    "total_discount":"0.0000",
    "total_tax":"0.0000",
    "updated_at":null,
    "updated_by":null,
    "items":[
      {
          "cost":"50.0000",
          "discount":"0.0000",
          "id":"26",
          "name":"Apple",
          "product_id":"3",
          "quantity":"12.0000",
          "sku":"16132561",
          "tax":"0.0000",
          "tax_id":null,
          "tax_method":"subtraction",
          "type":"standard",
          "unit_code":"ball",
          "unit_id":"1"
      }
    ],
    "payments":false,
    "tax":null
  }
}
{
    "status": false,
    "message": "Purchase record not found"
}

Create a Purchase

post https://api.vendloop.com/purchases

Create a purchase. Returns the newly created purchase.

Header

Authorization
String
Set value to Bearer SECRET_KEY
user_id required
integer
The ID of the user associated with this purchase. User IDs can be retrieved from the users endpoint.
supplier_id required
integer
The ID of the Supplier associated with this purchase. Supplier IDs can be retrieved from the suppliers endpoint.
status required
string
Status of the purchase.

completed pending

items required
string
JSON encoded string of line items for this purchase.
payments
string
JSON encoded string of payments for this purchase.
reference
string
The invoice number for the purchase. If none is provided it will be populated by Vendloop POS.
date
datetime
The date of the purchase. If not provided will be added as the time the purchase reached the server. see date & time formats section
discount
double
The discount value of the purchase.
discount_type
string
The discount type of the purchase.

percent fixed

tax_id
integer
The ID of the tax associated with this purchase. Tax IDs can be retrieved from the taxes endpoint.
note
string
A note on the purchase entered by the cashier.
curl -L 'http://api.vendloop.com/purchases' \
-H 'Authorization: Bearer SECRET_KEY' \
-d '{
	"user_id": "1",
	"supplier_id": "1",
	"status": "completed",
	"reference": "170652348409",
	"date": "2024-07-18 04:37:29",
	"discount": 5,
	"discount_type": "percent",
	"tax_id": 2,
	"note": "",
	"items": [
		{
			"cost": 100,
			"discount": 5,
			"discount_type": "percent",
			"product_id": "1",
			"quantity": 5,
			"tax_id": 2,
			"variant_id": 5
		}
	],
	"payments": [
		{
			"user_id": "1",
			"reference": "170652348409",
			"amount": 100,
			"paid_by": "cash",
			"date": "2024-07-18 04:37:29",
			"note": ""
		}, {
			"user_id": "1",
			"reference": "170652348410",
			"amount": 100,
			"paid_by": "deposit",
			"date": "2024-07-18 04:37:29",
			"note": ""
		}
	]
}'
<?php
$fields = [
	"user_id" => "1",
	"supplier_id" => "1",
	"status" => "completed",
	"reference" => "170652348409",
	"date" => "2024-07-18 04:37:29",
	"discount" => 5,
	"discount_type" => "percent",
	"tax_id" => 2,
	"note" => "",
	"items" => json_encode([
		[
			"cost" => 100,
			"discount" => 5,
			"discount_type" => "percent",
			"product_id" => "1",
			"quantity" => 5,
			"tax_id" => 2,
			"variant_id" => 5
		]
	]),
	"payments" => json_encode([
		[
			"user_id" => "1",
			"reference" => "170652348409",
			"amount" => 100,
			"paid_by" => "cash",
			"date" => "2024-07-18 04:37:29",
			"note" => ""
		], [
			"user_id" => "1",
			"reference" => "170652348410",
			"amount" => 100,
			"paid_by" => "deposit",
			"date" => "2024-07-18 04:37:29",
			"note" => ""
		]
	])
];

$fields_string = http_build_query($fields);

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.vendloop.com/purchases',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => $fields_string,
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer SECRET_KEY'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer SECRET_KEY");

var formdata = new FormData();
formdata.append("user_id", "1");
formdata.append("supplier_id", "1");
formdata.append("status", "completed");
formdata.append("reference", "170652348409");
formdata.append("date", "2024-07-18 04:37:29");
formdata.append("discount", 5);
formdata.append("discount_type", "percent");
formdata.append("tax_id", 2);
formdata.append("note", "");
formdata.append("items", JSON.stringify([{"cost": 100, "discount": 5, "discount_type": "percent", "product_id": "1", "quantity": 5, "tax_id": 2, "variant_id": 5}]));
formdata.append("payments", JSON.stringify([{"user_id": "1", "reference": "170652348409", "amount": 100, "paid_by": "cash", "date": "2024-07-18 04:37:29", "note": ""}, {"user_id": "1", "reference": "170652348410", "amount": 100, "paid_by": "deposit", "date": "2024-07-18 04:37:29", "note": ""}]));

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: formdata,
  redirect: 'follow'
};

fetch("https://api.vendloop.com/purchases", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
val client = OkHttpClient()
val mediaType = "text/plain".toMediaType()
val body = MultipartBody.Builder().setType(MultipartBody.FORM)
  .addFormDataPart("user_id", "1")
  .addFormDataPart("supplier_id", "1")
  .addFormDataPart("status", "completed")
  .addFormDataPart("reference", "170652348409")
  .addFormDataPart("date", "2024-07-18 04:37:29")
  .addFormDataPart("discount", 5)
  .addFormDataPart("discount_type", "percent")
  .addFormDataPart("tax_id", 2)
  .addFormDataPart("note", "")
  .addFormDataPart("items",  Gson().toJson([{"cost": 100, "discount": 5, "discount_type": "percent", "product_id": "1", "quantity": 5, "tax_id": 2, "variant_id": 5}]))
  .addFormDataPart("payments",  Gson().toJson([{"user_id": "1", "reference": "170652348409", "amount": 100, "paid_by": "cash", "date": "2024-07-18 04:37:29", "note": ""}, {"user_id": "1", "reference": "170652348410", "amount": 100, "paid_by": "deposit", "date": "2024-07-18 04:37:29", "note": ""}]))
  .build()
val request = Request.Builder()
  .url("https://api.vendloop.com/purchases")
  .post(body)
  .addHeader("Authorization", "Bearer SECRET_KEY")
  .build()
val response = client.newCall(request).execute()

Sample Response

{
  "status": true,
  "message": "Purchase record added",
  "data": {
    "id": "187",
    "date": "2024-07-18 12:01:50",
    "due_date": null,
    "business_id": "1",
    "store_id": "1",
    "supplier_id": "2",
    "user_id": "2",
    "reference": "SALE/032558986109",
    "note": "",
    "order_tax": "0.0000",
    "paid": "206.6250",
    "payment_status": "paid",
    "purchase_status": "completed",
    "shipping": "0.0000",
    "staff_note": "",
    "sub_total": "217.5000",
    "grand_total": "206.6250",
    "total_discount": "10.8750",
    "total_tax": "0.0000",
    "updated_at": null,
    "updated_by": null,
    "device_id": null,
    "items": [
      {
        "cost": "142.5000",
        "discount": "0.0000",
        "id": "4",
        "name": "Bottle Water",
        "product_id": "3",
        "quantity": "1.0000",
        "sku": "16216661",
        "tax": "0.0000",
        "tax_id": null,
        "tax_method": "subtraction",
        "type": "standard",
        "unit_code": "bottle",
        "unit_id": "3"
      },
      {
        "cost": "75.0000",
        "discount": "0.0000",
        "id": "26",
        "name": "Apple",
        "product_id": "3",
        "quantity": "1.0000",
        "sku": "16132561",
        "tax": "0.0000",
        "tax_id": null,
        "tax_method": "subtraction",
        "type": "standard",
        "unit_code": "ball",
        "unit_id": "1"
      }
    ],
    "payments": [
      {
        "id": "202",
        "date": "2024-07-18 12:01:50",
        "user_id": "2",
        "reference_no": "049208965727",
        "paid_by": "cash",
        "amount": "103.3125"
      },
      {
        "id": "203",
        "date": "2024-07-18 12:01:50",
        "user_id": "2",
        "reference_no": "780383676091",
        "paid_by": "cash",
        "amount": "103.3125"
      }
    ],
    "tax": null
  }
}
{
    "status": false,
    "message": "Failed to add purchase"
}

Delete a Single Purchase

post https://api.vendloop.com/purchases/delete

Delete purchase with the given ID.

Header

Authorization
String
Set value to Bearer SECRET_KEY
id required
integer
The ID of the purchase to be deleted.
curl -L 'http://api.vendloop.com/purchases/delete' \
-H 'Authorization: Bearer SECRET_KEY' \
-F 'id="{id}"'
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.vendloop.com/purchases/delete',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => array('id' => '{id}'),
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer SECRET_KEY'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer SECRET_KEY");

var formdata = new FormData();
formdata.append("id", "{id}");

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: formdata,
  redirect: 'follow'
};

fetch("https://api.vendloop.com/purchases/delete", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
val client = OkHttpClient()
val mediaType = "text/plain".toMediaType()
val body = MultipartBody.Builder().setType(MultipartBody.FORM)
  .addFormDataPart("id","{id}")
  .build()
val request = Request.Builder()
  .url("https://api.vendloop.com/purchases/delete")
  .post(body)
  .addHeader("Authorization", "Bearer SECRET_KEY")
  .build()
val response = client.newCall(request).execute()

Sample Response

{
  "status":true,
  "message":"Purchase record deleted"
}
{
    "status": false,
    "message": "Purchase record not found"
}