Prerequisites
Before you write custom field values through the API, confirm the following:- API key: Your requests send your organization’s API key in the
X-API-KEYheader. See authenticating your requests. - Field definition: A custom field exists for the record type you write to, at the level you need. Create it in the app under Configuration > Accounting Setup > Custom Fields, or through the API as described below.
- Field name or ID: You know the field’s exact name, or its
idif two fields share a name.
Set a field’s header or line level
A custom field’s level is set per record type in itsapplies_to list, so one definition can hold a header value, a line value, or both on each record type. Each entry has a type, the record type such as bill, and a layer: transaction for the header level (the default when you omit it) or entry for the line level. To show one field at both levels on a record type, send two entries for that type, one per layer.
The following request body creates a text field named Project code that bills hold at both the header and line levels. Send it with POST /public/v2/custom-fields/:
PUT /public/v2/custom-fields/{custom_field_id}/ replaces the whole applies_to list, so send every entry you want to keep. To list fields and find each field’s id, call GET /public/v2/custom-fields/. Filter it with layer=entry to list only fields available at the line level.
Because definitions are writable through the API, an integration can create the fields it needs when it’s installed and then fill them on every record it writes. Definitions are shared across the organization, so agree on field names with any other integration that writes to the same record types.
Send custom field values on a record
Record create and update requests take custom field values incustom_fields arrays: one at the top level of the record for header values, and one on each line for line values. A field available only at the line level is rejected if you send it in the header custom_fields.
To write a value, follow these steps:
- Find the field’s exact name, or its
idif two fields share a name, withGET /public/v2/custom-fields/. - Add an item for the field to the record’s top-level
custom_fieldsfor a header value, or to a line’scustom_fieldsfor a line value, in either shape described below. - Send the record’s create or update request.
- Check the
custom_fieldsarrays in the response. They return the stored value for the field in the canonical shape.
custom_fields are on the line objects for bills, direct expenses, vendor credits, purchase orders, invoices, cash sales, customer credits, sales orders, customer payments, customer deposits, customer refunds, item receipts, item fulfillments, and journal entries in API v1, v2, and v3-alpha, and on quote lines from v2. The public intercompany journal entry endpoints carry no custom fields at either level; enter those values in the app.
The DualEntry CLI has no line-level options of its own. Put layer and line custom_fields in the JSON file you pass with --file to dualentry custom-fields create, dualentry custom-fields update, or a record’s create and update commands.
Each item in a custom_fields array sets one field. You can write an item in either of two shapes, described below, and mix them in one array.
Name-keyed shape
A name-keyed item is a one-key object whose key is the field’s exact name and whose value is the value to store. In the following bill fragment, the header setsDepartment code and one expense line sets Project code. Other required bill and line fields are left out:
Canonical shape
A canonical item is an object with the field’s ID underfield and the value under value:
Update, clear, and read values
On an update, only the custom fields you send change, and a field you leave out of the array keeps its current value. To clear a field, send its item with the valuenull, either { "Project code": null } or "value": null in the canonical shape. On lines, send each existing line’s id so its values carry over. A line without an id is created as a new line.
The following bill update fragment clears Department code on the header and changes Project code on an existing expense line, identified by its id. Other required bill and line fields are left out:
field holds the full field definition, including id, name, and field_type, and value holds the stored value with its custom_field_id and custom_field_name. List and detail endpoints return the same arrays, so you don’t need a second call per record to read values.
Errors
A request with a custom field problem fails with a validation error that lists each problem. The table below lists the messages, what causes each one, and how to fix it:
For the error format that applies to every endpoint, see Errors.
Related pages
- Custom Fields: Record Types, Types, and Limits for the record types, field types, company scoping, and reporting behavior.
- How to add custom fields to transaction lines for setting up line-level fields in the app.
- List custom fields and Create custom field in the API reference.
- How Custom Integrations Work for integration design guidance.