Recent searches
No recent searches
Synchronizing user and ticket fields
Posted Jul 13, 2021
Hi community,
since Zendesk seems to be far from an, in my opinion, normal customer service application, I need to script a solution, which just doesn't work, and due to a lack of, for me, understandable documentation, I cannot figure out where it goes wrong.
We are an online shop with customer service via Zendesk, and we need to get customer account numbers synced. There are primary keys in our ERP software and shop, but both are not connected to Zendesk.
I want to achieve, that if the account number is entered in a ticket, but not present in the user (customer), to write it to the customer field as well.
On the other hand, if we know the user (customer) and his/her account number, we will write it into the ticket account number field for quick reference, in case it is blank.
User:
custom field called "Kundennummer" with key "kundennummer"
Ticket:
custom field called "Kundennummer" with ID "********3817"
I have set two http-targets:
The first "pointing" to {{ticket.id}}.json:
The second to {{ticket.requester.id}}.json:
Also, I have set two triggers:
The first syncs the customer number from the user field to the ticket. Conditions are: [Status<closed] + [ticket.kundennummer = not available] + [user.kundennummer = available] (and to only affect test tickets for now: [group = management], as well as [status = changed] OR [status = new] to trigger.
Code for JSON is:
{
"ticket": {
"custom_fields": [{
"id": ********3817, "value": "{{ticket.requester.custom_fields.kundennummer}}"
}]
}
}
The second syncs the customer number back from ticket to user, if the user doesn't already have a number. The trigger does pretty much the same, with inverted customer null values, uses the other http-target (though I have tried with the "sync to ticket" target as well) and this code:
{
"user": {
"custom_fields": {
"kundennummer": "{{ticket.ticket_field_********3817}}"
}
}
}
I also have pretty much tried every way of putting this, but the documentation seems to spare this usage of user custom fields completely, not telling me what exact structure and syntax I need to use here to hit the user custom field with title "Kundennummer" and key "kundennummer".
I tried to hit the field, e.g., with the following and some more:
- ticket.requester.custom_fields.kundennummer
- ticket.requester.user_fields.kundennummer
- ticket.user.user_fields.kundennummer
- ticket.user.custom_fields.kundennummer
and variations including [{"key": "kundennummer", "value": "{{variable}}"}] and such
The first trigger hits every time flawlessly, syncing user "kundennummer" to ticket "kundennummer".
The second trigger never works.
What am I doing wrong here?
0
16 comments
Fabio
I think the second JSON should say "user_fields" instead of "custom_fields":
0
Sebastian Bornemann
Hi Fabio,
thanks for the answer. I just tried this (and am pretty sure to have tried that before), and without luck. The trigger gets fired (writes its tag into the ticket, so I know), but the customer number doesn't get synced...
0
Fabio
Hi @...,
okay, then try without the " " outside the placeholder.
0
Sebastian Bornemann
Hi, doesn't work either. But it underlines the first { bracket if I spare the ".
0
Daniel Dobrzensky
Just an idea - have you tried utilizing the user field `external_id` instead of a custom field? Admittedly, I'm not sure if that will make any difference, but might be worth a try.
But I do suggest you look into integrating your backend systems into Zendesk. We do something similar. In our case, we built custom code that evaluates every new ticket that comes in. We look at the user email and determine if there's an existing account. If so, we use the Zendesk API to update the user external_id field. We don't send it to a ticket field, but it'd be easy to do so.
Obviously that's not an immediate solution, but it would be a more stable solution, IMO.
0
Sebastian Bornemann
Hi,
I doubt this will work since the agents should be able to write this field and read from it, too.
What about using the user "details" field, how would you write the script then? I seem to fail understanding how the fields have to be accessed.
Also, does the "file name" for the http target have any impact on the outcome?
(edit: Of course, in the long run, we will want to sync to our ERP system, but this is not possible at the moment.)
0
Brandon Tidd
Hi @...,
You'll actually need to add quotes around your placeholder here as well:
Hope this helps!
Brandon Tidd
729 Solutions
0
Brett Bowser
Thanks for sharing the solution here Brandon!
0
Sebastian Bornemann
Hi Brandon,
this is unfortunately also no solution. It doesn't work.
Also, my question from above, if the outcome is affected by the file name of the json file (different variables used), hasn't been answered. Which target should I use?
I tried both targets with this code in the trigger:
No luck, nothing syncs in this direction.
The comma in your script doesn't validate, by the way, I assume it is wrong there.
0
Brandon Tidd
Hi @... -
Good catch on the comma, this was borrowed from a script that had multiple field updates.
The file name shouldn't matter. What type of error are you getting on the API > Target Failure screen?
Brandon
0
Sebastian Bornemann
Hi,
this is the error:
Anfrage
Antwort
Authentification is the same as in the working script.
The erroneous script file is called {{ticket.requester.id}}.json whereas the working one is called {{ticket.id}}.json (but works the wrong direction.
Is there any relevance to these variables??? Also, is there any (?!) documentation about the file naming and variable structure regarding my problem? I didn't find anything specific and have no way to get deeper knowledge about this topic by myself.
0
Brandon Tidd
Hi @... -
Here is more information on the authentication error.
Here is more information on placeholders.
Here is more information on api calls & placeholders.
Hope this points you in the right direction!
Brandon
0
Sebastian Bornemann
Hi Brandon,
please allow me, after reading your links, to post the remaining specific questions:
"Important: Remember to replace user with one of the user types shown above (for example, ticket.requester)." This contradicts your aforementioned "solution" and several of my tested snippets.
The correct script should be:
The exact script "structure" works the other way around, but calling the field by it's ID, not it's key. For this field, I have no ID mentioned anywhere.
This doesn't work, though. I switched to "basic" password authentification yesterday, and the API error now reads:
Which tells me what? I guess, that this field cannot be found using the "key"? But I don't have any other value to point to it.
I also found this thread: https://develop.zendesk.com/hc/en-us/community/posts/360001646788-End-Users-API-is-always-responding-with-404-RecordNotFound
It seems that the path for the target is wrong. But I never received any answer to my several questions regarding target paths. Is there any documentation?
I assume, the correct path would be: .../users/{{id}}.json
Before, the target path was: .../tickets/{{ticket.requester.id}}.json
0
Brandon Tidd
Hi @...,
Thanks for your patience here - I believe it depends on which API end-point you're hitting.
If you're using the user's end-point, you should be able to write to the custom user field using the {{id}} placeholder. If, however, you're using the Tickets endpoint, the 'user' is swapped for 'ticket.requester,' so as the documentation suggests you are updating the ticket.requester.custom_field (aka the user custom field).
I believe you're receiving a 404 error because you are asking Zendesk to reference a custom ticket field from within the ticket requester's (aka users) array. Since ticket data is not nested within user data, this results in the error.
I'm going to reach out to some of the other moderators to see if they can provide any additional context here. I hope this helps!
Brandon
0
Sebastian Bornemann
Hi Brandon,
thank you for clarifying. Now it makes a lot more sense.
If I would use a target with the file name .../{{user.id}}.json, I should be able to write into that field, correct?
But can I reference the ticket field this way around? If the file name in the target influences the "visible" fields, the script wouldn't be able to look the ticket field up, since it doesn't know which ticket to look at, correct?
Can I point to two different instances to get both fields?
0
Brandon Tidd
Hey @... correct and correct. At that point you'd have to take it into a script and store the data as variables as it would require two different targets and there would be no place to store the data. You could also look at some of the documentation around Sunshine Objects, but that's a bit out of scope for me, unfortunately. The team at 729 Solutions may be able to assist further though!
Brandon
0