Skip to main content

Filter Results

If you are using one of our SDKs to develop your integration you have multiple choices when you want to filter the responses of our Api, you can write your query manually or you can use our Filter Helper to build the filter.

Retrieve your Company ID!

In this example, we'll suppose you have to manage just one Company, so we simply inserted its ID directly in the code. If instead, you need to be able to manage multiple companies, you'll need to retrieve the ID of the current company in some way. Check the Company-scoped Methods page for more info.

๐Ÿ”งย  Building the filter manuallyโ€‹

If you have to filter an Api response and your query is not very complicated, the most straightforward approach you can use is the manual one, you simply have to set the request's q parameter to the desired filter query and you are ready to go.

using System;
using System.Diagnostics;
using It.FattureInCloud.Sdk.Api;
using It.FattureInCloud.Sdk.Client;
using It.FattureInCloud.Sdk.Model;

namespace Example
{
public class ListClientsExample
{
public static void Main()
{
Configuration config = new Configuration();
config.AccessToken = "YOUR_ACCESS_TOKEN";

var apiInstance = new ClientsApi(config);
var companyId = 12345;
var fieldset = "detailed";
var q = "vat_number = '03812340161'";

try
{
ListClientsResponse result = apiInstance.ListClients(companyId, null, fieldset, null, null, null, q);
Console.Write(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling ClientsApi.ListClients: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
}

๐Ÿ†˜ย  Using the Filter Helperโ€‹

If you have a long and articulated query or you are building your filter programmatically then your best option is to use our Filter Helper that you can find in each one of our official SDKs.

Conditionโ€‹

The Condition class is the underlying principle of our Helper, it's made up of 3 properties, the Field, the Operator and the Value

var condition = new Condition<string>("vat_number", Operator.EQ, "03812340161");
var query = condition.BuildQuery(); // "vat_number = '03812340161'"

Operatorโ€‹

There are many operators you can utilize in a Condition:

Operator NameSymbol
EQ'='
GT'>'
GTE'>='
LT'<'
LTE'<='
NEQ'<>', '!='
IS'='
IS_NOT'!='
LIKE'like'
CONTAINS'contains'
STARTS_WITH'starts with'
ENDS_WITH'ends with'

Conjunction & Disjunctionโ€‹

The Conjunction and Disjunction classes work like logical operators between two Conditions, the Conjunction works like the AND operator while the Disjunction works like the OR operator.

var condition1 = new Condition<string>("vat_number", Operator.EQ, "03812340161");
var condition2 = new Condition<string>("tax_code", Operator.EQ, "RSSMRG99A23206D");
var disjunction = new Disjunction(condition1, condition2);
var query = disjunction.BuildQuery(); // (vat_number = '03812340161' or tax_code = 'RSSMRG99A23206D')

DSLโ€‹

There is another way to use our Filter Helper, you can indeed use out Domain-Specific language as shown in the next steps.

Whereโ€‹

To initialize a Filter you must set a Where condition, you have 2 options:

Where(field, operator, value)โ€‹

In this method you have to pass the field, operator and value as shown in the following examples:

var filter = new Filter();
filter.Where("vat_number", Operator.EQ, "03812340161");

var query = filter.BuildQuery(); // vat_number = '03812340161'
WhereExpression(condition|conjunction|disjunction)โ€‹

In this method you can either pass a simple condition or a more complex conjunction or disjunction as shown below:

var condition1 = new Condition<string>("vat_number", Operator.EQ, "03812340161");
var condition2 = new Condition<string>("tax_code", Operator.EQ, "RSSMRG99A23206D");
var disjunction = new Disjunction(condition1, condition2);

var filter = new Filter();
filter.WhereExpression(disjunction);

var query = filter.BuildQuery(); // (vat_number = '03812340161' or tax_code = 'RSSMRG99A23206D')

And & Orโ€‹

If you need a more complex filter you can add an and or or condition to your Filter you have 3 options:

And(field, operator, value) & Or(field, operator, value)โ€‹

In this method you have to pass the field, operator and value as shown in the following examples:

var filter = new Filter();
filter.Where("vat_number", Operator.EQ, "03812340161");
filter.Or("tax_code", Operator.EQ, "RSSMRG99A23206D");
filter.Or("code", Operator.CONTAINS, "2022/");

var query = filter.BuildQuery(); // ((vat_number = '03812340161' or tax_code = 'RSSMRG99A23206D') or code contains '2022/')
AndExpression(condition|conjunction|disjunction) & OrExpression(condition|conjunction|disjunction)โ€‹

In this method you can either pass a simple condition or a more complex conjunction or disjunction as shown below:

var condition1 = new Condition<string>("tax_code", Operator.EQ, "RSSMRG99A23206D");
var condition1 = new Condition<string>("code", Operator.CONTAINS, "2022/");

var filter = new Filter();
filter.Where("vat_number", Operator.EQ, "03812340161");
filter.OrExpression(condition1);
filter.OrExpressiom(condition2);

var query = filter.BuildQuery(); // ((vat_number = '03812340161' or tax_code = 'RSSMRG99A23206D') or code contains '2022/')
AndFilter(filter) & OrFilter(filter)โ€‹

In this method you have to pass a Filter object as shown here:

  var filter = new Filter();
filter.Where("vat_number", Operator.EQ, "03812340161");

var filter1 = new Filter();
filter1.Where("tax_code", Operator.EQ, "RSSMRG99A23206D");

filter.AndFilter(filter1);

var query = filter.BuildQuery(); // (vat_number = '03812340161' and tax_code = 'RSSMRG99A23206D')

Now that your query is ready the last thing to do is to set the q parameter equal to the just obtained query and you are ready to make your request!