Skip to main content

Sort Results

Some of our APIs (e.g. the LIST methods) return a set of resources instead of a single one. This means that a certain order is established between them and that your application could take advantage of a certain order.

Sorting lets you choose the rule that must be used to order the returned resources, delegating this task to our APIs.

Check the fields!

Our APIs let you apply an ordering rule only on a certain set of fields. Please check the table below for the available fields for each method.

To order the returned resources, all you have to do is to add the sort parameter to the query string, containing a comma-separated set of the fields that define the sorting rule. The default order for each field is the ascending order, which doesn't require any prefix, while the descending order can be selected by adding the prefix "-" to the field name.

For example, this request will sort all the expenses first by the "date" field in descending order and then by the "amount_net" field in ascending order.

curl --request GET \
--url 'https://api-v2.fattureincloud.it/c/company_id/received_documents?sort=-date,amount_net&type=expense' \
--header 'Accept: application/json'
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN'

The corresponding code examples:

// this code uses RestSharp Client: https://restsharp.dev
// you can install it with the following command:
// dotnet add package RestSharp

using System;
using RestSharp;

namespace restclient
{
class Program
{
static void Main(string[] args)
{
// for this example we define the token as a string, but you should have obtained it in the previous steps
// the token is valid for the "received_documents:r" scope needed to perform this operation
var token = "YOUR_ACCESS_TOKEN";

// these parameters are usually retrieved through our APIs or stored in a DB
var companyId = 17;

var query = System.Web.HttpUtility.ParseQueryString(string.Empty);
query.Add("sort", "-date,amount_net");
query.Add("type", "expense");

var url = "https://api-v2.fattureincloud.it/c/" + companyId + "/received_documents" + "?" + query;

var client = new RestClient(url);
var request = new RestRequest(Method.GET);

request.AddHeader("authorization", "Bearer " + token);
IRestResponse response = client.Execute(request);
Console.Write(response.Content.ToString());
}
}
}

Here you can find an example response, please note that sorting is strictly related to the Pagination functionality:

{
"data": [
{
"id": 251,
"type": "expense",
"description": "Catene auto",
"amount_net": 68.03,
"amount_vat": 14.97,
"is_marked": false,
"entity": {
"id": 109,
"name": "Catene e catenacci S.r.l."
},
"date": "2021-12-23",
"next_due_date": "2013-12-23",
"amount_gross": 83
},
{
"id": 104328,
"type": "expense",
"description": "Ricarica Telefonica",
"amount_net": 20,
"amount_vat": 0,
"is_marked": false,
"entity": {
"id": 35,
"name": "Maracaibo Mobile S.p.a."
},
"date": "2021-08-01",
"next_due_date": "1970-01-01",
"amount_gross": 20
},
{
"id": 134828,
"type": "expense",
"description": "Soggiorno di lavoro",
"amount_net": 592,
"amount_vat": 0,
"is_marked": false,
"entity": {
"id": -1,
"name": "Hotel Paradiso"
},
"date": "2014-10-29",
"next_due_date": "2020-10-29",
"amount_gross": 592
},
{
"id": 134830,
"type": "expense",
"description": "SmartPhone Y",
"amount_net": 130,
"amount_vat": 0,
"is_marked": false,
"entity": {
"id": 14542,
"name": "Pear Inc."
},
"date": "2014-04-16",
"next_due_date": "2020-09-01",
"amount_gross": 130
},
{
"id": 134832,
"type": "expense",
"description": "BestBook Pro 2020",
"amount_net": 430,
"amount_vat": 0,
"is_marked": false,
"entity": {
"id": 14542,
"name": "Pear Inc."
},
"date": "2014-04-16",
"next_due_date": "2020-05-29",
"amount_gross": 430
}
],
"current_page": 2,
"last_page": 67,
"per_page": "5",
"from": 6,
"to": 10,
"total": 335,
"path": "https://api-v2.fattureincloud.it/received_documents",
"first_page_url": "https://api-v2.fattureincloud.it/received_documents?per_page=5&type=expense&fieldset=basic&page=1",
"last_page_url": "https://api-v2.fattureincloud.it/received_documents?per_page=5&type=expense&fieldset=basic&page=67",
"next_page_url": "https://api-v2.fattureincloud.it/received_documents?per_page=5&type=expense&fieldset=basic&page=3",
"prev_page_url": "https://api-v2.fattureincloud.it/received_documents?per_page=5&type=expense&fieldset=basic&page=1",
}

📔  Sortable fields

Here you can find the list of fields that can be used to order the result for each List method; for every field, it is possible to use the ascending or descending order.

MethodFields
listClientscode, name, type, vat_number, tax_code, address_street, address_postal_code, address_city, address_province, country, email, certified_email, phone, fax, notes, e_invoice, ei_code, created_at, updated_at
listSupplierscode, name, type, vat_number, tax_code, address_street, address_postal_code, address_city, address_province, country, email, certified_email, phone, fax, notes, e_invoice, ei_code, created_at, updated_at
listProductsname, code, net_price, gross_price, net_cost, description, category, notes, in_stock, created_at, updated_at
listIssuedDocumentsentity.id, entity.name, entity.vat_number, entity.tax_code, entity.city, entity.province, entity.country, date, number, numeration, amount_net, amount_vat, amount_gross, next_due_date, created_at, updated_at
listReceivedDocumentsid, category, entity.id, entity.name, date, next_due_date, amount_gross, amount_net, amount_vat, created_at, updated_at
listReceiptsdate, rc_center, created_at, updated_at
listF24due_date, status, amount, description
listArchiveDocumentsdate, category, description

📚  Additional Resources