Synchronizing user and ticket fields

16 Comments

  • Fabio Strasser

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

    {
    "user": {
    "user_fields": {
    "kundennummer": "{{ticket.ticket_field_********3817}}"
    }
    }
    }
    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 Strasser

    Hi Sebastian Bornemann,

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

    {
    "user": {
    "user_fields": {
    "kundennummer": {{ticket.ticket_field_********3817}}
    }
    }
    }
    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
    Community Moderator

    Hi Sebastian Bornemann,

    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
  • Brett Bowser
    Zendesk Community Team

    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:

    {
    "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
  • Brandon Tidd
    Community Moderator

    Hi Sebastian Bornemann -

    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:

     

    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
  • Brandon Tidd
    Community Moderator

    Hi Sebastian Bornemann - 

    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:

    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
  • Brandon Tidd
    Community Moderator

    Hi Sebastian Bornemann,

    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
  • 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
    Community Moderator

    Hey Sebastian Bornemann 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

Please sign in to leave a comment.

Powered by Zendesk