Discounts

Discounts #

Discounts are reductions either in amounts charged or demanded for the Sale or Purchase of goods and services. Discounts can either be received from suppliers or given to clients.

Properties #

Direct Properties #

PropertyTypeDefinition
NameStringA label to identify the Discount
CodeStringA symbol/acronym to identify the Discount
RateFloatThe rate of the Discount as a percentage

Indirect Properties #

PropertyTypeDefinition
AccountDictionaryThe Income/Expense Account of the Discount

Basics #

The parameters required to create a Discount Resource are the Name, Code, Rate and the Id of the Discount’s Control Account.

Request #

curl --location --request POST 'api.microbooks.io/books/v1/discounts' \
--data-raw '{
	"name": "Trade Discount",
    "code": "SALE",
    "rate" : 10,
    "account_id" : 1
}'
import requests

url = "https://api.microbooks.io/books/v1/discounts"
body = {
    "name": "Trade Discount",
    "code": "SALE",
    "rate" : 10,
    "account_id" : 1
}
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": "Trade Discount",
        "code": "SALE",
        "rate" : 10,
        "account_id" : 1
    }'
};
request(options, function (error, response) {
    if (error) throw new Error(error);
    console.log(response.body);
});
$client = new Client();
$body = '{
    "name": "Trade Discount",
    "code": "SALE",
    "rate" : 10,
    "account_id" : 1
}';
$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\": \"Trade Discount\",
    \"code\": \"SALE\",
    \"rate\" : 10,
    \"account_id\" : 1
}";
request.AddParameter("text/plain", body,  ParameterType.RequestBody);
request.AddHeader("Authorization", "Bearer " + <bearer_token>);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

Response #

{
    "status": "success",
    "message": "Discount: Trade Discount (SALE) at 10.00% created successfully",
    "resource": {
        "name": "Trade Discount",
        "code": "SALE",
        "rate": 10,
        "account_id": 1,
        "operations_discount": false,
        "entity_id": 1,
        "id": 2,
        "account": {
            "uuid": "9bf98392-556e-4f68-8e92-3fcfef689f25",
            "id": 1,
            "entity_id": 1,
            "category_id": null,
            "currency_id": 1,
            "code": 2,
            "name": "Rick Schinner II",
            "description": null,
            "type": "Direct Expense",
            "is_closed": false
        }
    }
}

Errors #

Below are the Errors that are returned by the Discount Resource.

Detail CodeNameDefinition
100Orphaned ItemsCannot recycle the Discount Resource because it has dependent Resources
101Missing EntityThe Discount Resource requires an existing Entity because it is applied to Line Items used in Transactions, for the purpose of preparing Financial Statements which are scoped to an Entity
102Missing Applicable AccountThe Discount Resource requires an Account of type Account::CONTROL to which the amounts charged by the Discount will be posted
103Invalid Acount TypeThe Account type of the Account select for the Discount Resource must be Account::CONTROL
104Invalid Applicable RateA Discount with a rate of 0 is meaningless