Sync "Submitter" in Zendesk to JIRA Reporter

Originally asked by Spencer Johnson on 21 October 2020 (original question)


Hi I am trying to sync a hidden zendesk field “Submitter” it is a system field only accessible via the API but represents who actually created the ticket (see here for more details: https://developer.zendesk.com/rest_api/docs/support/tickets) to the reporter in JIRA. However, it looks like that field is not accessible via exalate.

The “Submitter” also creates the first comment on the zendesk ticket so I was trying to use that to set reporter by getting the author of the first comment but was struggling with that as well and it was not working:

Zendesk Outgoing:

replica.comments = issue.comments

JIRA Incoming:

if(firstSync){
issue.projectKey = "NOC"
// Set type name from source issue, if not found set a default
issue.typeName = "Incident"
def reporter = null
issue.comments = commentHelper.mergeComments(issue, replica)

{ reporter = it.author?.email it.executor = nodeHelper.getUserByEmail(it.author?.email) }

if (reporter != null)

{ issue.reporter = userHelper.getByEmail(reporter) }

}

Answer by Spencer Johnson on 23 October 2020

Francis Martens (Exalate) thank you for all the help, I wanted to post the final solution that I got to work:

Zendesk Outgoing:

// Submitter of Ticket (ie Reporter)
def ticketDetails = httpClient.get("/api/v2/tickets/${issue.key}.json")
Long submitterId = ticketDetails["ticket"]["submitter_id"]
def userDetails = httpClient.get("/api/v2/users/${submitterId}.json")
replica.customKeys."Reporter Email" = userDetails.user.email

JIRA Incoming:

def reporterEmail = replica.customKeys."Reporter Email"
if (reporterEmail) {
    issue.reporter = userHelper.getByEmail(reporterEmail) ?: defaultUser
} 

Comments:

Francis Martens (Exalate) commented on 24 October 2020

Awesome

Answer by Francis Martens (Exalate) on 22 October 2020

Aparently an oversight in the Exalate API

A workaround can be based by using the httpclient

def ticketDetails = httpClient.get("/api/v2/tickets/${issue.key}.json")
Long submitterId = ticketDetails["ticket"]["submitter_id"]

def userDetails = httpClient.get("/api/v2/users/${submitterId}.json")
throw new Exception("Submitter = ${submitterId}, user = ${userDetails}")

Give it a try. I will raise some requests on our backlog…


Comments:

Spencer Johnson commented on 22 October 2020

Francis Martens (Exalate) where should I put that? The error thrown from the exception displayed the userDetails properly but I am not sure how to send that to JIRA

This is what I tried but am getting an error on the zendesk side (Details: Cannot cast object):

Zendesk Outgoing:

// Submitter of Ticket (ie Reporter)
def ticketDetails = httpClient.get("/api/v2/tickets/${issue.key}.json")
Long submitterId = ticketDetails["ticket"]["submitter_id"]

def userDetails = httpClient.get("/api/v2/users/${submitterId}.json")
//throw new Exception("Submitter = ${submitterId}, user = ${userDetails}")
replica.reporter = userDetails

JIRA Incoming:

if (replica.reporter != null){
    issue.reporter = userHelper.getByEmail(replica.reporter?.email)
}

I also tried this and didn’t get an error but the value isn’t there on the JIRA side:

Zendesk Outgoing:

// Submitter of Ticket (ie Reporter)
def ticketDetails = httpClient.get("/api/v2/tickets/${issue.key}.json")
Long submitterId = ticketDetails["ticket"]["submitter_id"]

def userDetails = httpClient.get("/api/v2/users/${submitterId}.json")
//throw new Exception("Submitter = ${submitterId}, user = ${userDetails}")
replica.customFields."Reporter Email" = userDetails.email // this is not an actual custom field name 

JIRA Incoming:

def reporterEmail = replica.customFields."Reporter Email"?.value
if (replica.customFields."Reporter Email"?.value != null){
    issue.reporter = userHelper.getByEmail(replica.customFields."Reporter Email".value)
}

I also tried to throw an exception with the value of reporterEmail on the JIRA side but it came back as null

Francis Martens (Exalate) commented on 23 October 2020

Instead of

replica.customFields."Reporter Email" = userDetails.email // this is not an actual custom field name 



You can use customKeys

Outgoing Zendesk

replica.customKeys."Reporter Email" = userDetails.email 

And then on the receiving side

if (replica.customKeys."Reporter Email") {
   issue.reporter = userHelper.getByEmail(replica.customKeys."Reporter Email")
}
Spencer Johnson commented on 23 October 2020

Thanks for the help Francis Martens (Exalate) I had to make a small tweak which I posted as answer but it is working now!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.