Discounts #
The sections below demonstrate how to solve common book keeping problems revolving around the Discount resource.
Gross Discounts #
Problem #
You want to create a discount that applies to the gross (tax inclusive) amount on the Line Item.
Solution #
Gross Discount flag #
You can create a gross Discount by calling the create Discount Resource endpoint with the `gross_discount' attribute set to true.
Request #
curl --location --request POST 'api.microbooks.io/books/v1/discounts' \
--data-raw '{
"name": "Season Discount",
"code": "HLDYS",
"rate" : 10,
"account_id" : 1,
"gross_discount" : true
}'
import requests
url = "https://api.microbooks.io/books/v1/discounts"
body = {
"name": "Season Discount",
"code": "HLDYS",
"rate" : 10,
"account_id" : 1,
"gross_discount" : true
}
headers = {"Authorization": "Bearer <bearer_token>"}
response = requests.request("POST", url, headers=headers, json=body)
print(response.text)
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://api.microbooks.io/books/v1/discounts',
'headers': {'Authorization': 'Bearer <bearer_token>'},
'body': '{
"name": "Season Discount",
"code": "HLDYS",
"rate" : 10,
"account_id" : 1,
"gross_discount" : true
}'
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
$client = new Client();
$body = '{
"name": "Season Discount",
"code": "HLDYS",
"rate" : 10,
"account_id" : 1,
"gross_discount" : true
}';
$request = new Request('POST', 'https://api.microbooks.io/books/v1/discounts',
[headers' => ['Authorization' => 'Bearer <bearer_token>']],
$body
);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
var client = new RestClient("https://api.microbooks.io/books/v1/discounts");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
var body = "{
\"name\": \"Season Discount\",
\"code\": \"HLDYS\",
\"rate\" : 10,
\"account_id\" : 1,
\"gross_discount\" : true
}";
request.AddParameter("text/plain", body, ParameterType.RequestBody);
request.AddHeader("Authorization", "Bearer " + <bearer_token>);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
Operations Discounts #
Problem #
You want to create a discount that applies to the Entity’s core business (operations).
Solution #
Operational Account #
You can create an operations Discount by specifying an account for the Discount of either OPERATING_EXPENSE
or OPERATING_REVENUE
Account type.
Mixed Discounts
Operations and Non - Operations Discounts cannot be attached to the same Line Item.
Request #
curl --location --request POST 'api.microbooks.io/books/v1/discounts' \
--data-raw '{
"name": "Clearance Discount",
"code": "SALE",
"rate" : 10,
"account_id" : 1 # Account type should be `OPERATING_EXPENSE` or `OPERATING_REVENUE`
}'
import requests
url = "https://api.microbooks.io/books/v1/discounts"
body = {
"name": "Clearance Discount",
"code": "SALE",
"rate" : 5,
"account_id" : 1 # Account type should be `OPERATING_EXPENSE` or `OPERATING_REVENUE`
}
headers = {"Authorization": "Bearer <bearer_token>"}
response = requests.request("POST", url, headers=headers, json=body)
print(response.text)
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://api.microbooks.io/books/v1/discounts',
'headers': {'Authorization': 'Bearer <bearer_token>'},
'body': '{
"name": "Clearance Discount",
"code": "SALE",
"rate" : 5,
"account_id" : 1 // Account type should be `OPERATING_EXPENSE` or `OPERATING_REVENUE`
}'
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
$client = new Client();
$body = '{
"name": "Clearance Discount",
"code": "SALE",
"rate" : 5,
"account_id" : 1 // Account type should be `OPERATING_EXPENSE` or `OPERATING_REVENUE`
}';
$request = new Request('POST', 'https://api.microbooks.io/books/v1/discounts',
[headers' => ['Authorization' => 'Bearer <bearer_token>']],
$body
);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
var client = new RestClient("https://api.microbooks.io/books/v1/discounts");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
var body = "{
\"name\": \"Season Discount\",
\"code\": \"SALE\",
\"rate\" : 5,
\"account_id\" : 1 // Account type should be `OPERATING_EXPENSE` or `OPERATING_REVENUE`
}";
request.AddParameter("text/plain", body, ParameterType.RequestBody);
request.AddHeader("Authorization", "Bearer " + <bearer_token>);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);