Updating a User Field with Zendesk Api
AnsweredHi, I want to use Zendesk Api to update a user field in the profile. In order words, I would like to pass from a blank or "-" value to a new value that i want to specify within the Put request. I do not know if Zendesk provides a command for doing so. Currently, I have found the doc for managing user fields with the API and I see comands for (Update User Field, create or update user field option, etc), but I am not sure which one should I use to update a blank space in that user field and set it to a new value.
https://developer.zendesk.com/api-reference/ticketing/users/user_fields/#update-user-field
Note: The user field type is drop-down
-
Hi Juan Julio Montreuil Berrocal
I think what you are looking for is updating the values of user fields that you already created. So you will need to do so from the user end point `/api/v2/users/{user_id}`
Example:
curl https://{subdomain}.zendesk.com/api/v2/users/{user_id}.json \
-d '{"user":
{"user_fields": {
"user_field_key_1": "option"
}
}}' \
-H "Content-Type: application/json" -X PUT \
-v -u {user}:{api_key}
To set it to null (-), simply replace the "option" value with "".
I hope I managed to help.
-
Hi Ahmed! thanks for your help. So in order to specify the user field to be changed, I replace "user_field_key_1" with the user field ID or I should put it in another part of that code block?
-
Hi Juan Julio Montreuil Berrocal
You would actually need the field unique 'key', rather than its id. It should replace 'user_field_key_1' as you expected.
-
Thanks for jumping in to problem solve, Ahmed Zaid!
-
Hello everybody,
I am currently working on the idea of a contact counter in the user profile, with which one can track how often a customer has been contacted.
The function should look something like this: Lightagents try to contact users. With each attempt, the light agents leave an internal comment with a certain keyword. This keyword activates a trigger with a webhook that updates the user field (contact attempt).
I have copied the above-mentioned suggestion as a basis. However, I would now need a function that increases the value in the user field by 1 for each contact attempt.
Does anyone have an idea how to implement this?
So in principle:
curl https://{subdomain}.zendesk.com/api/v2/users/{user_id}.json \
-d '{"user": {"user_fields": {"counter": "increase value by 1"}}}' \
-H "Content-Type: application/json" -X PUT \
-v -u {user}:{api_key} -
Hi luz.marsen,
Do you plan to run it in your backend or using Zendesk webhooks? if the later, you can use liquid placeholder.
-
Hi Ahmed, thank you for your reply :)
I would use a Zendesk webhook. How would it work with a liquid placeholder?
-
Your webhook end point should be set to
https://subdomain.zendesk.com/api/v2/users/{{ticket.requester.id}}
And, assuming your field key is "counter" and type is "numeric", the trigger that would notify the webhook should have this payload:
{% assign counter = {{ticket.requester.custom_fields.counter}} | plus: 1 %}
{
"user": {
"user_fields": {
"counter": {{counter}}
}
}
}This is a mixture of liquid and JSON.
It worked well on my Sandbox.
-
Hello Ahmed,
It took a while to get back to this issue.
Yes, this code works exactly as it should! Thanks again for your help :)
Please sign in to leave a comment.
9 Comments