Retrieving the list of customFields enabled for an expense nature

Custom fields activation depends on the expense nature. For example, custom field “Bill back client (bool)” may be activated for travel expenses, but not for team building expenses.

GET /api/expenseNatures?fields=id,name,url,customFields.id,customFields.name,customFields.url,customFields.type.tag,customFields.case.tag,customFields.compulsory,customFields.minLength,customFields.maxLength,customFields.defaultValue HTTPS/2
Host: example.ilucca.net
Authorization: lucca application={API_KEY}
Accept: application/json

< Response
{
    "data": [
        {
            "id": 1,
            "name": "Diner",
            "url": "https://example.ilucca.net/api/expenseNatures/49"
            "customFields": [
                {
                    "id": "1",
                    "name": "Bill back client",
                    "url": "https://example.ilucca.net/api/expenseCustomFields/1",
                    "type": {
                        "tag": "Bool"
                    },
                    "case": {
                        "tag": "Insensitive"
                    },
                    "compulsory": false,
                    "minLength": 0,
                    "maxLength": null,
                    "defaultValue": "false"
                }
            ]
        }
    ]
}

Each custom field is typed, as indicated by the customField.type.tag discriminator:

Type.TagExpected value (code) - actual values are always stringsExample
StringAny text string as long as it conforms to MinLength and MaxLength."test"
BoolStringified boolean."true" or "false"
IntStringified integer"48"
FloatStringified float."18.25"
DigitsString of numbers, that must potentially conform to a minLength and maxLength."0495846"
ListValuesString among a list (i.e. enum; refer to values dictionary property)."foo"
title: customField
type: object
properties:
    id:
        type: string
        description: Unique identifier of the custom field. Keep in mind one custom field can apply to multiple expense natures.
    name:
        type: string
        description: Name of the custom field
    url:
        type: string
        format: uri
    type:
        type: object
        properties:
            tag:
                type: string
                enum: [String, Bool, Int, Float, Digits, ListValues]
                description: |-
                    - `String`: any text string;
                    - `Bool`: stringified boolean value, i.e. `"true"` or `"false"`.
                    - `Int`: stringified integer value, i.e. `"234"`.
                    - `Float`: stringified float value, i.e. `"0.123"`.
                    - `Digits`: string of numbers, i.e. "0123456789".
                    - `ListValues`: string among an list of accepted values (i.e. enumeration).
    case:
        type: object
        properties:
            tag:
                type: string
                enum: [Insensitive, Uppercase, Lowercase]
                description: Case sensitivity.
    compulsory:
        type: boolean
        description: Whether a value MUST be set on expenses of this expense-nature or not.
        default: false
    minLength:
        type: [integer, "null"]
        minimum: 0
        default: null
        description: Minimum number of characters accepted for a value.
    maxLength:
        type: [integer, "null"]
        minimum: 0
        descritpion: Maximum number of characters accepted for a value.
    defaultValue:
        type: string
        description: Explicit default for values.
    values:
        type: object
        description: Dictionary valueCode => valueDisplayName. Lists the enum values for a `ListValues` typed custom field.
        additionalProperties:
            type: string

Retrieving the customFields values for an expense

In order to retrieve the list of customField values for an ExpenseTempItem or an ExpenseClaimItem, simply add “customFields” to the list of fields requested through the ?fields query parameter:

GET /api/v3/expenseTempItems?fields=id,customFields HTTPS/2
Host: example.ilucca.net
Authorization: lucca application={API_KEY}
Accept: application/json

The customFields field you’ll retrieve is a JSON object whose keys are the IDs of the customField.

{
    "id": 23,
    "customFields": {
        "2": {
            "code": "false",
            "name": "No"
        }
    }
}