Recent searches


No recent searches

Synchronizing user and ticket fields

Answered


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

16 comments

I think the second JSON should say "user_fields" instead of "custom_fields":

{
"user": {
"user_fields": {
"kundennummer": "{{ticket.ticket_field_********3817}}"
}
}
}

0


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


Hi @...,

okay, then try without the " " outside the placeholder.

{
"user": {
"user_fields": {
"kundennummer": {{ticket.ticket_field_********3817}}
}
}
}

0


Hi, doesn't work either. But it underlines the first { bracket if I spare the ".

0


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


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


image avatar

Brandon Tidd

Zendesk LuminaryUser Group LeaderThe Humblident Award - 2021Community Moderator

Hi @...,

You'll actually need to add quotes around your placeholder here as well:

{ "user": {
"user_fields": {
"key": "{{ticket.ticket_field_******5101}}",
}
}
}

Hope this helps!

Brandon Tidd
729 Solutions

0


image avatar

Brett Bowser

Zendesk Community Manager

Thanks for sharing the solution here Brandon!

0


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:

{
"user": {
"user_fields": {
"kundennummer": "{{ticket.ticket_field_360015443817}}"
}
}
}

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


image avatar

Brandon Tidd

Zendesk LuminaryUser Group LeaderThe Humblident Award - 2021Community Moderator

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


Hi,

 

this is the error:

 

Sync customer number from ticket

Anfrage

PUT /api/v2/tickets/384518815337.json HTTP/1.1  
Authorization Basic aW5mb0B2b2x0dXMuZGUvdG9rZW46
User-Agent Zendesk Target
Content-Type application/json; charset=utf-8
Accept-Encoding gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept */*
Connection close
Host xxxxxx.zendesk.com
Content-Length 67
{
  "user": {
    "user_fields": {
      "kundennummer": "12345"
    }
  }
}

Antwort

HTTP/1.1 401 Unauthorized  
Date Mon, 02 Aug 2021 12:46:04 GMT
Content-Type application/json; charset=UTF-8
Content-Length 37
Connection close
WWW-Authenticate Basic realm="Web Password"
Strict-Transport-Security max-age=31536000;
Cache-Control no-cache
X-Zendesk-Origin-Server classic-app-server-65cbc7b6cf-84bbh
X-Request-Id 67876829f95460f1-DUB
X-Runtime 0.868412
X-Zendesk-Zorg yes
X-Request-ID 67876829f95460f1-DUB
CF-Cache-Status DYNAMIC
Expect-CT max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Report-To {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=ga6FsURew2p%2FkNw1XEyd2d%2BA6pkGDqW3o%2BG4XqXcqZ12MTI3SPGOragbg9l9j3Kwj7EKxN3giThj8RmKBil3fr6%2Fo999UyfVu%2BwRyRZXqeFMjrKFW0c7AyhDXC0fqSUdykDXYg%3D%3D"}],"group":"cf-nel","max_age":604800}
NEL {"report_to":"cf-nel","max_age":604800}
Server cloudflare
CF-RAY 67876829f95460f1-DUB
{
  "error": "Couldn't authenticate you"
}

 

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


image avatar

Brandon Tidd

Zendesk LuminaryUser Group LeaderThe Humblident Award - 2021Community Moderator

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


Hi Brandon,

please allow me, after reading your links, to post the remaining specific questions:

  1. Why is "user_fields" never mentioned on the whole of the placeholders reference?
  2. Do I need to use "user_fields" or do I need to use "custom_fields", which IS mentioned there for using with custom user fields?
  3. Can anyone tell me for sure that this custom user field is writeable?

 

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

 

{
"ticket": {
"requester": {
"custom_fields": [{
"key": "kundennummer", "value": "{{ticket.ticket_field_********3817}}"
}]
}
}
}

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:

{
  "error": "RecordNotFound",
  "description": "Not found"
}

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


image avatar

Brandon Tidd

Zendesk LuminaryUser Group LeaderThe Humblident Award - 2021Community Moderator

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.

   "ticket": {
"requester": { ##User Data
"custom_fields": [{
"key": "kundennummer", "value": "{{ticket.ticket_field_********3817}}" ## Ticket Data
}]
}
}

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


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


image avatar

Brandon Tidd

Zendesk LuminaryUser Group LeaderThe Humblident Award - 2021Community Moderator

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


Post is closed for comments.

Didn't find what you're looking for?

New post