Transactions

Transactions #

The sections below demonstrate how to solve common book keeping problems revolving around the Transaction resource.

Draft Transactions #

Problem #

You want to create Transactions in a pending state during which time it can be changed, line items added or removed from it.

Solution #

Deferred Posting #

Calling the Create Transaction endpoint by default results in a pending Transaction. Only calling the Post Transaction endpoint commits the Transaction to the ledger making it immutable.

Request #

curl --location --request POST 'api.microbooks.io/books/v1/transaction' \
--data-raw '{
	"account_id": 1,
	"transaction_type": "JN",
	"narration": "Test Transaction",
	"transaction_date": "2022-07-25",
    
}'
import requests

url = "https://api.microbooks.io/books/v1/transaction"
body = {
    "account_id": 1,
	"transaction_type": "JN",
	"narration": "Test Transaction",
	"transaction_date": "2022-07-25",
}
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/transaction',
    'headers': {'Authorization': 'Bearer <bearer_token>'},
    'body': '{
        "account_id": 1,
        "transaction_type": "JN",
        "narration": "Test Transaction",
        "transaction_date": "2022-07-25",
    }'
};
request(options, function (error, response) {
    if (error) throw new Error(error);
    console.log(response.body);
});
$client = new Client();
$body = '{
    "account_id": 1,
	"transaction_type": "JN",
	"narration": "Test Transaction",
	"transaction_date": "2022-07-25",
}';
$request = new Request('POST', 'https://api.microbooks.io/books/v1/transaction', 
    [headers' => ['Authorization' => 'Bearer <bearer_token>']], 
    $body
);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
var client = new RestClient("https://api.microbooks.io/books/v1/transaction");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
var body = "{
    \"account_id\": 1,
	\"transaction_type\": \"JN\",
	\"narration\": \"Test Transaction\",
	\"transaction_date\": \"2022-07-25\",
}";
request.AddParameter("text/plain", body,  ParameterType.RequestBody);
request.AddHeader("Authorization", "Bearer " + <bearer_token>);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

Commited Transactions #

Problem #

You want to commit a draft Transactions to the ledger.

Solution #

Post Transaction #

You can commit a Transaction by calling the Post Transaction endpoint.

Request #

curl --location --request POST 'api.microbooks.io/books/v1/transaction/post/1'
import requests

url = "https://api.microbooks.io/books/v1/transaction/post/1"
body = {}
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/transaction/post/1',
    'headers': {'Authorization': 'Bearer <bearer_token>'},
    'body': '{}'
};
request(options, function (error, response) {
    if (error) throw new Error(error);
    console.log(response.body);
});
$client = new Client();
$body = '{}';
$request = new Request('POST', 'https://api.microbooks.io/books/v1/transaction/post/1', 
    [headers' => ['Authorization' => 'Bearer <bearer_token>']], 
    $body
);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
var client = new RestClient("https://api.microbooks.io/books/v1/transaction/post/1");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
var body = null;
request.AddParameter("text/plain", body,  ParameterType.RequestBody);
request.AddHeader("Authorization", "Bearer " + <bearer_token>);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

Transaction Line Itens #

Problem #

You want to view the Line Items attached to a Transaction.

Solution #

Get Line Items #

You can view the Line Items recorded for a Transaction by calling the get Line Items endpoint.

Request #

curl --location --request GET 'api.microbooks.io/books/v1/transaction/1/line-items'
import requests

url = "https://api.microbooks.io/books/v1/transaction/1/line-items"
body = {}
headers = {"Authorization": "Bearer <bearer_token>"}

response = requests.request("GET", url, headers=headers, json=body)

print(response.text)
var request = require('request');
var options = {
    'method': 'GET',
    'url': 'https://api.microbooks.io/books/v1/transaction/1/line-items',
    'headers': {'Authorization': 'Bearer <bearer_token>'},
    'body': '{}'
};
request(options, function (error, response) {
    if (error) throw new Error(error);
    console.log(response.body);
});
$client = new Client();
$body = '{}';
$request = new Request('GET', 'https://api.microbooks.io/books/v1/transaction/1/line-items', 
    [headers' => ['Authorization' => 'Bearer <bearer_token>']], 
    $body
);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
var client = new RestClient("https://api.microbooks.io/books/v1/transaction/1/line-items");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
var body = null;
request.AddParameter("text/plain", body,  ParameterType.RequestBody);
request.AddHeader("Authorization", "Bearer " + <bearer_token>);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

Transaction Assignments #

Problem #

You want to view the Transactions that have been cleared by (assigned to) to a Transaction.

Solution #

Get Assignments #

You can view the Assignments recorded for a Transaction by calling the get Assignments endpoint.

Request #

curl --location --request GET 'api.microbooks.io/books/v1/transaction/1/assignments'
import requests

url = "https://api.microbooks.io/books/v1/transaction/1/assignments"
body = {}
headers = {"Authorization": "Bearer <bearer_token>"}

response = requests.request("GET", url, headers=headers, json=body)

print(response.text)
var request = require('request');
var options = {
    'method': 'GET',
    'url': 'https://api.microbooks.io/books/v1/transaction/1/assignments',
    'headers': {'Authorization': 'Bearer <bearer_token>'},
    'body': '{}'
};
request(options, function (error, response) {
    if (error) throw new Error(error);
    console.log(response.body);
});
$client = new Client();
$body = '{}';
$request = new Request('GET', 'https://api.microbooks.io/books/v1/transaction/1/assignments', 
    [headers' => ['Authorization' => 'Bearer <bearer_token>']], 
    $body
);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
var client = new RestClient("https://api.microbooks.io/books/v1/transaction/1/assignments");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
var body = null;
request.AddParameter("text/plain", body,  ParameterType.RequestBody);
request.AddHeader("Authorization", "Bearer " + <bearer_token>);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

Transaction Clearances #

Problem #

You want to view the Transactions that have been used to clear a Transaction.

Solution #

Get Clearances #

You can view the Clearances recorded for a Transaction by calling the get Clearances endpoint.

Request #

curl --location --request GET 'api.microbooks.io/books/v1/transaction/1/clearances'
import requests

url = "https://api.microbooks.io/books/v1/transaction/1/clearances"
body = {}
headers = {"Authorization": "Bearer <bearer_token>"}

response = requests.request("GET", url, headers=headers, json=body)

print(response.text)
var request = require('request');
var options = {
    'method': 'GET',
    'url': 'https://api.microbooks.io/books/v1/transaction/1/clearances',
    'headers': {'Authorization': 'Bearer <bearer_token>'},
    'body': '{}'
};
request(options, function (error, response) {
    if (error) throw new Error(error);
    console.log(response.body);
});
$client = new Client();
$body = '{}';
$request = new Request('GET', 'https://api.microbooks.io/books/v1/transaction/1/clearances', 
    [headers' => ['Authorization' => 'Bearer <bearer_token>']], 
    $body
);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
var client = new RestClient("https://api.microbooks.io/books/v1/transaction/1/clearances");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
var body = null;
request.AddParameter("text/plain", body,  ParameterType.RequestBody);
request.AddHeader("Authorization", "Bearer " + <bearer_token>);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

Manage Line Items #

Problem #

You want to add or remove Line Items from a Transaction.

Solution #

Add/Remove Line Items #

You can add or remove Line Items from a Transaction by calling the Add or Remove Line Items endpoint respectively.

Request #

curl --location --request POST 'api.microbooks.io/books/v1/transaction/add-items/1' \ # or remove-items/1 
--data-raw '
    "line_items": [1],
    "transaction_type": "JN"
import requests

url = "https://api.microbooks.io/books/v1/transaction/add-items/1" # or remove-items/1
body = {
    "line_items": [1],
    "transaction_type": "JN"
}
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/transaction/add-items/1', // or remove-items/1
    'headers': {'Authorization': 'Bearer <bearer_token>'},
    'body': '{
        "line_items": [1],
        "transaction_type": "JN"
    }'
};
request(options, function (error, response) {
    if (error) throw new Error(error);
    console.log(response.body);
});
$client = new Client();
$body = '{
    "line_items": [1],
    "transaction_type": "JN"
}';
$request = new Request('POST', 'https://api.microbooks.io/books/v1/transaction/add-items/1', // or remove-items/1
    [headers' => ['Authorization' => 'Bearer <bearer_token>']], 
    $body
);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
var client = new RestClient("https://api.microbooks.io/books/v1/transaction/add-items/1"); // or remove-items/1
client.Timeout = -1;
var request = new RestRequest(Method.POST);
var body = "{
    \"line_items\": [1],
    \"transaction_type\": \"JN\"
}";
request.AddParameter("text/plain", body,  ParameterType.RequestBody);
request.AddHeader("Authorization", "Bearer " + <bearer_token>);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);