Recycle Bin

Recycle Bin #

The Recycle Bin is a utility that manages the removal and restoration of Resources from an Entity. A Resource is recycled when it is deleted. While in the Recycle Bin, the Resource is hidden from the other Resources making it unavailable for use. All Resource types in the microbooks system can be recycled and once in the Recycle Bin, they can either be restored or destroyed. Destroyed Resources are lost completely and cannot be restored.

Properties #

Direct Properties #

Being a derived Resource, the Recycle Bin does not have any Direct Properties as it is only indirectly created by the deletion of another Resource.

Indirect Properties #

PropertyTypeDefinition
UserDictionaryThe user who deleted/restored/destroyed the resource
ResourceDictionaryThe Resource that was deleted/restored/destroyed

Basics #

As mentioned above, this Resource is created when another is deleted.

Variations #

The Recycled Bin Resource has no Variations.

Operations #

Restore #

When a Resource has been deleted, it is unavailable for use by the rest of the system but still it exists in a dormant state. This endpoint reactivates the deleted Resource putting it back into circulation.

A restore can be refused, for example for a Category whose name has since been taken, or a Balance whose Reporting Period has since closed. The endpoint then returns the error of the Resource being restored, and the Resource stays in the Recycle Bin.

Request #

curl --location --request POST 'https://api.microbooks.io/books/v1/recycled-resource/1/restore' \
--header "Authorization: Bearer <bearer_token>"
import requests

url = "https://api.microbooks.io/books/v1/recycled-resource/1/restore"
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/recycled-resource/1/restore',
    '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 = null;
$request = new Request('POST', 'https://api.microbooks.io/books/v1/recycled-resource/1/restore', 
    [headers' => ['Authorization' => 'Bearer <bearer_token>']], 
    $body
);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
var client = new RestClient("https://api.microbooks.io/books/v1/recycled-resource/1/restore");
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);

Response #

{
    "status": "success",
    "message": "Non Current Asset: Ms. Elisabeth Murphy Sr. restored successfully",
    "resource": {
        "uuid": "d66fc8fc-c073-41c9-bb36-2ae70f0130da",
        "id": 1,
        "entity_id": 1,
        "category_id": 1,
        "currency_id": 1,
        "code": 9,
        "name": "Ms. Elisabeth Murphy Sr.",
        "description": null,
        "type": "Non Current Asset",
        "is_closed": false,
        "category": {
            "uuid": "6460d9b7-dbdc-4ce3-a9fe-f51c2fd94cd8",
            "id": 1,
            "entity_id": 1,
            "name": "voluptatum",
            "type": "Non Current Asset"
        }
    }
}

Destroy #

Calling the destroy endpoint permanently removes a recycled Resource from the system.

Request #

curl --location --request POST 'https://api.microbooks.io/books/v1/recycled-resource/1/destroy' \
--header "Authorization: Bearer <bearer_token>"
import requests

url = "https://api.microbooks.io/books/v1/recycled-resource/1/destroy"
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/recycled-resource/1/destroy',
    '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 = null;
$request = new Request('POST', 'https://api.microbooks.io/books/v1/recycled-resource/1/destroy', 
    [headers' => ['Authorization' => 'Bearer <bearer_token>']], 
    $body
);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
var client = new RestClient("https://api.microbooks.io/books/v1/recycled-resource/1/destroy");
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);

Response #

{
    "status": "success",
    "message": "Receivable: Verona Treutel destroyed successfully",
    "resource": {
        "uuid": "b40d6438-55f9-4f9d-839e-033da881a253",
        "id": 2,
        "entity_id": 1,
        "category_id": 2,
        "currency_id": 1,
        "code": 9,
        "name": "Verona Treutel",
        "description": null,
        "type": "Receivable",
        "is_closed": false,
        "category": {
            "uuid": "f2016651-d640-4a68-9af7-5f6bf1a37988",
            "id": 2,
            "entity_id": 1,
            "name": "et",
            "type": "Receivable"
        }
    }
}

Errors #

Below are the Errors that are returned by the Recycle Bin Resource.

Detail CodeHTTP StatusNameDefinition
101400Missing EntityThe Recycle Bin Resource manages the recycling, restoration and destruction of other Resources in use on the platform and therefore requires an Existing Entity Resource to scope the above actions
102400Duplicate CategoryThe Category Resource cannot be restored because the Entity now has another Category with that name
108400Closed Reporting PeriodThe Balance Resource cannot be restored because its Reporting Period is closed
422422ValidationA field is missing, malformed or not recognised. The field is the key under errors

Errors use the standard error envelope, which also lists the request-level codes (401, 403, 404, 429 and others) that any endpoint can return.