Tree fields
Create a tree field and manage its nodes. Tree fields are custom fields whose values form a hierarchy, for taxonomies such as categories, industries or topics. You can assign their values to exhibitors, people, products (items in the API) and sessions (plannings in the API).
Reference: TreeFieldDefinition and TreeFieldNode objects
On this page you can:
- Create a tree field with its initial structure.
- Replace the whole tree, before any value is assigned.
- Add, update, move and delete nodes once the tree is in use.
How tree fields work
A tree field is made of nodes, each identified by a path:
- A selectable node can be assigned to an entity.
- A non-selectable node is only a grouping label in the hierarchy.
- Each node has its own translated labels.
A path is a string that joins node identifiers with the |~^ separator. For example, the sub-category SUB-1, under the category CAT-1, under ROOT, has the path ROOT|~^CAT-1|~^SUB-1.
Before you begin
- An API key, sent in the
Authorizationheader. The key acts with the roles and permissions of the user who created it. See Authentication. - The ID of your event (
eventId). See Events. - To manage nodes, the ID of the tree field (
fieldDefinitionId). See List custom fields.
Create a tree field
Use the createFieldDefinition mutation with type set to TREE to create a tree field and its initial structure. Describe the structure with two inputs:
treeOptions: the list of selectable nodes. Each option has apath: an array of node identifiers, from the root to the target node.treeTranslations: the translated labels of every node in the tree, selectable or not. Each entry has avalue(the full node path joined with|~^) and a list oftranslations, one per language.
Not every node needs to be selectable. Intermediate (grouping) nodes can exist in treeTranslations without appearing in treeOptions. However, every node referenced in a path, selectable or not, must have an entry in treeTranslations so it can be displayed with a proper label.
| Argument | Description |
|---|---|
eventId | The ID of the event on which to create the custom field. |
name | The name of the custom field. |
target | The entity the custom field applies to (PEOPLE, EXHIBITOR, SESSION or ITEM). |
type | Must be TREE. |
treeOptions | The paths of the selectable nodes. |
treeTranslations | The labels of every node of the tree, in every language. |
mutation createFieldDefinition($input: CreateFieldDefinitionV2Input!) {
createFieldDefinition(input: $input) {
event {
id
}
fieldDefinition {
... on TreeFieldDefinition {
id
name
tree {
value
path {
value
translations {
language
value
}
}
}
}
}
errors {
code
message
}
}
}
{
"input": {
"eventId": "RXZlbnRfMQ==",
"name": "Industry",
"target": "EXHIBITOR",
"type": "TREE",
"isEditable": true,
"isVisible": true,
"translations": [
{ "language": "en_US", "name": "Industry" },
{ "language": "fr_FR", "name": "Secteur d'activité" }
],
"treeOptions": [
{ "path": ["ROOT", "CAT-1"] },
{ "path": ["ROOT", "CAT-1", "SUB-1-1"] },
{ "path": ["ROOT", "CAT-1", "SUB-1-2"] },
{ "path": ["ROOT", "CAT-2"] },
{ "path": ["ROOT", "CAT-2", "SUB-2-1"] }
],
"treeTranslations": [
{
"value": "ROOT",
"translations": [
{ "language": "en_US", "value": "Root" },
{ "language": "fr_FR", "value": "Racine" }
]
},
{
"value": "ROOT|~^CAT-1",
"translations": [
{ "language": "en_US", "value": "Category 1" },
{ "language": "fr_FR", "value": "Catégorie 1" }
]
},
{
"value": "ROOT|~^CAT-1|~^SUB-1-1",
"translations": [
{ "language": "en_US", "value": "Sub Category 1-1" },
{ "language": "fr_FR", "value": "Sous-catégorie 1-1" }
]
},
{
"value": "ROOT|~^CAT-1|~^SUB-1-2",
"translations": [
{ "language": "en_US", "value": "Sub Category 1-2" },
{ "language": "fr_FR", "value": "Sous-catégorie 1-2" }
]
},
{
"value": "ROOT|~^CAT-2",
"translations": [
{ "language": "en_US", "value": "Category 2" },
{ "language": "fr_FR", "value": "Catégorie 2" }
]
},
{
"value": "ROOT|~^CAT-2|~^SUB-2-1",
"translations": [
{ "language": "en_US", "value": "Sub Category 2-1" },
{ "language": "fr_FR", "value": "Sous-catégorie 2-1" }
]
}
]
}
}
Replace the whole tree
The updateFieldDefinition mutation also works on tree fields: it replaces the whole tree structure (treeOptions and treeTranslations) in a single call. Use it only while no value is assigned yet.
Avoid using updateFieldDefinition to change the tree structure of a field whose values are already assigned to entities (exhibitors, people, products or sessions). This mutation overwrites the whole tree and doesn't check existing assignments, which can leave orphaned or inconsistent values.
Once the tree is in use, use the node-level mutations instead:
These mutations validate each change and keep data consistent when you add, rename, move or remove nodes.
Add a node
Use the createTreeFieldNode mutation to add a node to an existing tree, at a position relative to an existing reference node.
| Argument | Description |
|---|---|
fieldDefinitionId | The ID of the tree field to add the node to. |
targetNode | The full path of the reference node used for positioning, for example ROOT|~^CAT-1. |
position | Where to place the new node relative to targetNode: ABOVE, BELOW or INSIDE. |
nodeId | The identifier of the new node, for example SUB-NEW. Combined with its parent path, it forms the full path of the new node. |
translations | The translated labels of the new node. |
isSelectable | Whether the new node can be assigned to entities (it is added to treeOptions) or is only a grouping label. |
mutation CreateTreeFieldNode($input: CreateTreeFieldNodeInput!) {
createTreeFieldNode(input: $input) {
fieldDefinition {
... on TreeFieldDefinition {
id
tree {
value
path {
value
translations {
language
value
}
}
}
}
}
errors {
code
message
path
}
}
}
{
"input": {
"fieldDefinitionId": "RmllbGREZWZpbml0aW9uXzY=",
"targetNode": "ROOT|~^CAT-1",
"position": "INSIDE",
"nodeId": "SUB-1-3",
"isSelectable": true,
"translations": [
{ "language": "en_US", "value": "Sub Category 1-3" },
{ "language": "fr_FR", "value": "Sous-catégorie 1-3" }
]
}
}
Update a node
Use the updateTreeFieldNode mutation to change the translations of a node, whether it is selectable, or both. To move a node, use moveTreeFieldNode instead.
| Argument | Description |
|---|---|
fieldDefinitionId | The ID of the tree field. |
currentNodePath | The full path of the node to update, for example ROOT|~^CAT-1|~^SUB-1-1. |
translations | Optional. Replaces all the existing translations of the node. |
isSelectable | Optional. Sets whether the node can be assigned to entities. |
mutation UpdateTreeFieldNode($input: UpdateTreeFieldNodeInput!) {
updateTreeFieldNode(input: $input) {
fieldDefinition {
... on TreeFieldDefinition {
id
tree {
value
path {
value
translations {
language
value
}
}
}
}
}
errors {
code
message
path
}
}
}
{
"input": {
"fieldDefinitionId": "RmllbGREZWZpbml0aW9uXzY=",
"currentNodePath": "ROOT|~^CAT-1",
"isSelectable": true,
"translations": [
{ "language": "en_US", "value": "Category 1 — Updated" },
{ "language": "fr_FR", "value": "Catégorie 1 — Mise à jour" }
]
}
}
Move a node
Use the moveTreeFieldNode mutation to move a node, and all its descendants, to another position in the tree. Values already assigned to the node or its descendants follow the new path.
| Argument | Description |
|---|---|
fieldDefinitionId | The ID of the tree field. |
currentNodePath | The current full path of the node to move. |
targetNode | The full path of the reference node for the destination. |
position | Where to place the node relative to targetNode: ABOVE, BELOW or INSIDE. |
mutation MoveTreeFieldNode($input: MoveTreeFieldNodeInput!) {
moveTreeFieldNode(input: $input) {
fieldDefinition {
... on TreeFieldDefinition {
id
tree {
value
path {
value
translations {
language
value
}
}
}
}
}
errors {
code
message
path
}
}
}
{
"input": {
"fieldDefinitionId": "RmllbGREZWZpbml0aW9uXzY=",
"currentNodePath": "ROOT|~^CAT-2|~^SUB-2-1",
"targetNode": "ROOT|~^CAT-1|~^SUB-1-1",
"position": "ABOVE"
}
}
Delete a node
Use the deleteTreeFieldNode mutation to delete a node and all its descendants. The response returns the IDs of the deleted FieldValue entities in deletedFieldValueIds, so you can update your own data.
Deleting a branch node also deletes all its descendants. Any value assigned to the deleted nodes is removed from the related exhibitors, people, products or sessions.
| Argument | Description |
|---|---|
fieldDefinitionId | The ID of the tree field. |
currentNodePath | The full path of the node to delete. |
mutation DeleteTreeFieldNode($input: DeleteTreeFieldNodeInput!) {
deleteTreeFieldNode(input: $input) {
deletedFieldValueIds
fieldDefinition {
... on TreeFieldDefinition {
id
tree {
value
path {
value
translations {
language
value
}
}
}
}
}
errors {
code
message
path
}
}
}
{
"input": {
"fieldDefinitionId": "RmllbGREZWZpbml0aW9uXzY=",
"currentNodePath": "ROOT|~^CAT-1"
}
}