Skip to content
Last updated

Conditional custom fields

This guide explains how to set a custom field to only appear only when the traveler gives a particular answer to another custom field. For example, a company might ask whether a traveler is extending their stay, and collect an emergency contact number only if the traveler answers Yes.

Be sure to read custom field concepts to familiarize yourself with this feature before starting to use it.

Creating the main custom field

Create the custom field that asks a question. For example, Are you planning to extend your stay?. You would do this using the create custom field endpoint as shown below:

POST /v3/companies/{companyId}/custom-fields?companyRole=ORG
{
  "name": "Are you planning to extend your stay?",
  "description": {
    "value": "Captures whether the traveler stays beyond the event dates"
  }
}

Add an arm with a create custom field arm request. This arm has no audience conditions, so it applies to every traveler who makes a booking. The action is set to USER and the option source type is set to MANUAL as it requires a manual response from the traveler.

The API response contains an optionGroupId which will be used in creating a dependent custom field.

POST /v3/companies/{companyId}/custom-fields/{customFieldId}/arms
{
  "name": "All travelers",
  "action": {
    "type": "USER",
    "required": true,
    "format": {
      "type": "OPTION_LIST",
      "optionListTypeFormat": {
        "isMultiSelect": false,
        "isPctType": false
      },
      "customValueFormat": {
        "isCustomValueAllowed": false
      }
    },
    "userOptionSource": {
      "type": "MANUAL"
    }
  }
}

Add the two answers with an update options API call. The name of each option will be displayed to the traveler for them to choose.

PATCH /v3/companies/{companyId}/custom-fields/{customFieldId}/option-groups/{optionGroupId}
{
  "toUpdate": [
    {
      "name": "Yes"
    },
    {
      "name": "No"
    }
  ]
}

Creating the dependent custom field

Create the second custom field using the same create custom field endpoint.

POST /v3/companies/{companyId}/custom-fields?companyRole=ORG
{
  "name": "Enter your emergency contact number",
  "description": {
    "value": "Collected only when the traveler extends their stay"
  }
}

Create a custom field arm to include it's dependency on the main custom field.

Set the following values:

  • audience > predicates > type as CUSTOM_FIELD_RESPONSE
  • id as the optionGroupId of the main custom field's arm
  • comparator as EQ
  • values as Yes.

The above set of conditions translates to: Answers where the main custom field response equals to Yes.

Now that we have the condition, set the action in the same API request as follows:

  • action > type as USER (i.e., requires a user input)
  • format > type as TEXT_INPUT (i.e., the user needs to type into a text box)
  • allowedChars as NUMERIC (i.e., only allow numbers since the user is entering their phone number).

Below is a sample request where all the fields mentioned above are being set as described:

POST /v3/companies/{companyId}/custom-fields/{customFieldId}/arms
{
  "name": "Travelers extending their stay",
  "audiences": [
    {
      "name": "Answered Yes to the extended stay question",
      "predicates": [
        {
          "type": "CUSTOM_FIELD_RESPONSE",
          "id": "c73b1e58-9d24-4f07-a6b8-1e5c9d380f2a",
          "comparator": "EQ",
          "values": [
            "Yes"
          ]
        }
      ]
    }
  ],
  "action": {
    "type": "USER",
    "required": true,
    "format": {
      "type": "TEXT_INPUT",
      "userInputFormat": {
        "type": "NON_REGEX",
        "allowedChars": "NUMERIC",
        "minLength": 7,
        "maxLength": 15
      }
    }
  }
}

Every new custom field is disabled by default. Use the update custom field status endpoint to enable the custom fields using their ids.