List objects for a user
Let's say I have the following object type:
{
"custom_object_records": [
{
"url": "https://d3v-verschoren.zendesk.com/api/v2/custom_objects/pokemon_captured/records/01GXXWZ8GWTDSTNEQHFZV02RAQ.json",
"id": "01GXXWZ8GWTDSTNEQHFZV02RAQ",
"name": "Ash's Bulbasaur",
"custom_object_key": "pokemon_captured",
"custom_object_fields": {
"trainer": "10992004688146"
}
},
...
]
}
Where trainer is a Lookup Field for End-Users.
And I want to capture this data via API: a list of all objects linked to that user.
1. List records and filter
One approach might be doing a GET on
GET /api/v2/custom_objects/{custom_object_key}/records
And then filter the result on the trainer value. But since these results can't be filtered in advance this requires paginating through all records and gets expensive and slow fast.
2. Search records
Another approach could be searching for the records by name. If I'm lucky all items have a name that contains the Trainers' name. If that's not the case, search is not an option.
3. Lookup Relationship
Another approach might be the Lookup Relationships API
/api/v2/zen:user/{{user_id}}/relationship_fields/{{object_id}}/zen:custom_object:{{recordkey}}
But since this object is not explicitly linked to a Custom Ticket Field, I can't always map my records against object fields.
What would be the best way to get all records linked to a user?
Use cases:
- Sidebar app that shows all IT materials owned by a user
- Custom Help Center integration that allows a user to select it's license
...
See here for my full list of EAP Remarks
-
Official comment
Let's say you have an object called "Device" which captures all the devices that your company owns. And you have a lookup field called "Assigned to" in the Device object, which points to a User Record. If you want to know what devices have been assigned to John Doe using APIs, you can use this Lookup field API to get the list of devices
GET /api/v2/zen:user/{John doe's Record ID}/relationship_fields/{field_id of assigned_to field}/zen:custom_object:device
Hope this helps
-
This is a good question. Option 3 is the right approach to go with..
You can build the API path in this way:
GET /api/v2/zen:user/{target_id}/relationship_fields/{field_id}/zen:custom_object:pokemon_captured
However, let me respond back with a more descriptive approach to retrieve source relationships.
-
Having said that, we also do have another internal API to retrieve the Lookup fields pointing to a specific target record type..
In the above example:
Give me all the Lookup fields where the target is a User Object..
Do you see that being useful in any of your use cases? If yes, we can externalize that API.. -
Thanks for the feedback,
(Not sure if troubleshooting can happen in this thread or if I should raise a Support ticket?)
When I enter
https://{{domain}}.zendesk.com/api/v2/zen:user/10992004688146/relationship_fields/0991933583506/pokemon_captured
with 10992004688146 the ID of my user and 0991933583506 the ID of my lookup field
I get an error
"error": "InvalidEndpoint",
Give me all the Lookup fields where the target is a User Object..
I think it might be useful for more complex setups where Custom Objects are really a part of a flow.
- You might want to build a sidebar app that loads Devices, Service Logs and Software for a user across multiple objects and make the API generic so that if someone adds another record type (e.g. peripherals) that the Facility App will also show those since it's a Lookup Target > user object.
-
Can you try
https://{{domain}}.zendesk.com/api/v2/zen:user/10992004688146/relationship_fields/0991933583506/zen:custom_object:pokemon_captured
Please sign in to leave a comment.
5 Comments