Updating a User Field with Zendesk Api

답변함

9 댓글

  • Ahmed Zaid
    User Group Leader Community Moderator
    Zendesk Luminary

    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.

    3
  • Ahmed Zaid
    User Group Leader Community Moderator
    Zendesk Luminary

    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.

    1
  • Juan Julio Montreuil Berrocal

    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?

    0
  • Nicole Saunders
    Zendesk Community Manager

    Thanks for jumping in to problem solve, Ahmed Zaid!

    0
  • Luz Marsen

    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}
    0
  • Ahmed Zaid
    User Group Leader Community Moderator
    Zendesk Luminary

    Hi Luz Marsen,

    Do you plan to run it in your backend or using Zendesk webhooks? if the later, you can use liquid placeholder.

    0
  • Luz Marsen

    Hi Ahmed, thank you for your reply :)

    I would use a Zendesk webhook. How would it work with a liquid placeholder?

    0
  • Ahmed Zaid
    User Group Leader Community Moderator
    Zendesk Luminary

    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.

    0
  • Luz Marsen

    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 :)

    0

댓글을 남기려면 로그인하세요.

Zendesk 제공