Payload Filters

Restrict which records are visible through an API key

Enterprise support

This feature is restricted to customers on the Enterprise plan. Please reach out to your Account Team or contact us if you are interested in enabling and setting up this feature.

Payload filters restrict which records are visible through a given API key. When a payload filter is configured, the serialized JSONAPI response for each record is matched against the filter:

  • List endpoints: Non-matching records are filtered out of the response.
  • Single-resource endpoints: A 403 Forbidden status is returned if the record does not match the filter.

If the payload filter is empty or not set, the API key behaves normally and all records are returned.

Configuring a payload filter

You can configure a payload filter for an API key in the Dashboard. Navigate to API Keys, click into a specific key, and select the Payload filter tab. The filter is a JSON object that you can edit directly.

api-key-payload-filters

Examples

The examples below assume a key using kebab-case key inflection.

Filtering by status

To restrict an API key to only return completed Inquiries, you would set the following payload filter:

json
1{
2 "data": {
3 "attributes": {
4 "status": "completed"
5 }
6 }
7}

When listing Inquiries with this filter, only those with "status": "completed" in their serialized payload will appear. Retrieving a single Inquiry that is not completed will return a 403.

Filtering by relationship

To restrict an API key to only return records associated with a specific Inquiry Template:

json
1{
2 "data": {
3 "relationships": {
4 "inquiry-template": {
5 "data": {
6 "id": "itmpl_abc123def456"
7 }
8 }
9 }
10 }
11}

Designing a payload filter

Start by looking at the API response for the resource you want to filter. For example, retrieving an Inquiry (via Retrieve an Inquiry) might return:

json
1{
2 "data": {
3 "type": "inquiry",
4 "id": "inq_XN8jxMoEhUeihzNypSaFKFfo",
5 "attributes": {
6 "status": "completed",
7 "reference-id": null,
8 "...": "...",
9 "tags": ["INBOUND", "CAMPAIGN ABC"],
10 "fields": {
11 "address-country-code": {
12 "type": "string",
13 "value": "US"
14 },
15 "...": "..."
16 }
17 },
18 "relationships": {
19 "inquiry-template": {
20 "data": {
21 "type": "inquiry-template",
22 "id": "itmpl_abc123def456"
23 }
24 },
25 "...": "..."
26 }
27 }
28}

Pick the value you want to filter on and keep only the keys in the path leading to that value. For example, to filter for Inquiries with country code US:

json
1{
2 "data": {
3 "attributes": {
4 "fields": {
5 "address-country-code": {
6 "value": "US"
7 }
8 }
9 }
10 }
11}

Fields with null values cannot be matched by a payload filter. For example, filtering on "address-country-code": { "value": "US" } will only return records where that field is explicitly "US" — records where the field is null will not match.

Matching against arrays

To match against an array value in the payload, provide an array in the filter containing the elements you want to check for. All elements in the filter array must be present in the payload array for the record to match.

Matching on Inquiries with a tag named “INBOUND”:

json
1{
2 "data": {
3 "attributes": {
4 "tags": [
5 "INBOUND"
6 ]
7 }
8 }
9}

Matching on Inquiries with both “INBOUND” and “CAMPAIGN ABC” tags:

json
1{
2 "data": {
3 "attributes": {
4 "tags": [
5 "INBOUND",
6 "CAMPAIGN ABC"
7 ]
8 }
9 }
10}

$or operator

To allow for multiple criteria, use the $or operator. It can be used on a list of values or JSON object literals.

Value example — match Inquiries with either of two Inquiry Templates:

json
1{
2 "data": {
3 "relationships": {
4 "inquiry-template": {
5 "data": {
6 "id": {
7 "$or": [
8 "itmpl_abc123def456",
9 "itmpl_ghi789jkl012"
10 ]
11 }
12 }
13 }
14 }
15 }
16}

Object example — match Inquiries that are either approved or completed:

json
1{
2 "data": {
3 "attributes": {
4 "$or": [
5 {
6 "status": "approved"
7 },
8 {
9 "status": "completed"
10 }
11 ]
12 }
13 }
14}

Pagination

Payload filtering is applied after pagination. This means a page may return fewer results than the requested page[size], including empty pages with valid pagination cursors. Clients should continue paginating until no next cursor is returned.