Skip to main content

Personalization

If you want to customize the output of the Ntropy API you can do so by setting a ruleset through the personalization API. With a ruleset, you can conditionally add or remove labels and change some of the fields returned by the Ntropy API.

Ruleset

There are two types of rulesets: API key rulesets and account holder rulesets. API key rulesets are applied to all transactions submitted, while account holder rulesets only apply to transactions that match a specific account holder. The API key rulesets is applied first.

There is a size limit of 50,000 bytes for API key rulesets, and 10,000 bytes for account holder rulesets, which is enough for approximately 2000 basic rules per key and 400 basic rules per account holder.

Uploading rulesets

Rulesets can be uploaded via POST request to the /v2/rules/ and /v2/rules/account-holder/{account_holder_id} endpoints.

Sending a GET request will return the currently set ruleset.

Modifying a ruleset

You can append a rule to a ruleset via a POST request to the /v2/rules/append and /v2/rules/account-holder/{account_holder_id}/append endpoints.

To delete a rule, send a DELETE request to the /v2/rules/{index} and /v2/rules/account-holder/{account_holder_id}/{index} endpoints, where index is the zero based index of the rule you wish to delete.

To replace a rule, send a PATCH request to the /v2/rules/{index} and /v2/rules/account-holder/{account_holder_id}/{index} endpoints.

You can also of course reupload the entire ruleset.

Specification

A ruleset is a list of rules. Rulesets are type checked when uploaded.

Rules

There are 4 kinds of actions a rule can perform.

Set property

{"set": "property", "to": expression}

Properties that can be set are:

propertytype
logostring
websitestring
merchantstring
merchant_idstring
locationstring
personstring
transaction_typestring

Modify labels

You can add labels, remove labels, or replace all the labels. These expect strings.

{"set_labels": [expressions...]}
{"add_label": expression}
{"remove_label": expression}

Modify MCCs

Similarly, you can add, removes, or replace all the MCCs. These expect numbers.

{"set_mcc": [expressions...]}
{"add_mcc": expression}
{"remove_mcc": expression}

Conditional

Execute some rules if a condition is satisfied.

{"if": expression, "then": [rules...]}
{"if": expression, "then": [rules...], "else": [rules...]}

Expressions

Expressions can have one of three types: number, boolean, or string. null is not an allowed value. All numbers are interpreted as floats.

Literals

0
true
"string"

Function calls

There are currently 5 functions.

{"is_substring": [expression, expression]}
{"to_lower": [expression]}
{"to_upper": [expression]}
{"has_label": expression}
{"get": "property"}

is_substring takes two strings and returns a boolean, indicating whether the 2nd argument is a substring of the 1st.

to_lower takes a string converts it to lowercase.

to_upper takes a string converts it to uppercase.

has_label takes a string and returns a boolean

get returns the value of a property. property can be one of the settable properties, or description. The valid properties are:

propertytype
logostring
websitestring
descriptionstring
merchantstring
merchant_idstring
locationstring
personstring
transaction_typestring

Operators

These are technically also function calls.

Operators that take an arbitrary number of arguments are evaluated as ((arg1 <op> arg2) <op> arg3) <op> ....

{"!": expression} // logical not, accepts a boolean
{"&&": [expressions...]} // logical and, accepts a list of booleans
{"||": [expressions...]} // logical or, accepts a list of booleans
{"==": [expressions...]} // equals, accepts a list of expressions of the same type
{"+": [expressions...]} // accepts a list of numbers
{"*": [expressions...]} // accepts a list of numbers
{"/": [expressions...]} // accepts a list of numbers
{"-": [expressions...]} // accepts a list of of numbers
{"//": [expressions...]} // integer division, accepts a list of numbers
{"<": [expression, expression]} // accepts two numbers
{"<=": [expression, expression]} // accepts two numbers
{">": [expression, expression]} // accepts two numbers
{">=": [expression, expression]} // accepts two numbers

Examples

This example checks if the website contains "ntropy" and replaces the logo if so, and adds a label otherwise.

$ curl \
-H "X-API-KEY: <YOUR-API-KEY>" \
-H "Content-Type: application/json" \
-X POST \
--data '[
{
"if": {
"is_substring": [
{"get": "website"},
"ntropy"
]
},
"then": [
{"set": "logo", "to": "http://example.com/favicon.ico"}
],
"else": [
{"add_label": "not ntropy :("}
]
}
]' \
https://api.ntropy.com/v2/rules/

Here's another example to add the income label for interest payments.

$ curl \
-H "X-API-KEY: <YOUR-API-KEY>" \
-H "Content-Type: application/json" \
-X POST \
--data '[
{
"if": {
"||": [
{"has_label": "interest"},
{"is_substring": [{"to_lower": {"get": "description"}}, "interest"]},
]
},
"then": [{"add_label": "income"}],
}
]' \
https://api.ntropy.com/v2/rules/