I need to turn off JIRA notification scheme and use my own Custom Email for sending updates on Issues - I am sending an email to Reporter when Issue is resolved and need to include Survey link in the Resolution email - I was trying to use below:
https://serverurl/servicedesk/customer/portal/3/IT-XXX/feedback?
But this doesn't seem to work - do we need token that is sent in JIRA resolution email.
https://serverurl/servicedesk/customer/portal/3/IT-XXX/feedback?token=f5b6c9ab3f136ed4b3653ee2a4f476320a5af9bf&rating=3
I know I need to use Script in JIRA Post function to set a Custom field using JIRA Rest API for token - /rest/api/2/issue/{issueIdOrKey}/properties/feedback.token.key
Does anyone has Sample script to Call Rest API and set Custom field with response value. Please help.
Hi Jyoti,
I am facing a similar issue. Have you found a solution to your problem? Thank you.
Best regards,
Alban
Hi,
Perhaps the following solution can help you:
I solved that by 1st checking if the ticket already has a token generated because I realized sometimes that token in not created right after the ticket was moved to Resolved/Closed (or Resolution = Done)
https://company.atlassian.net/rest/api/2/issue/{{issue.key}}/properties/feedback.token.key
After that, I check if the web response is empty. If so, it means you need to generate the token in order to compose the link that will be sent to the user and allow him/her to respond to CSAT
Finally, I add another Web Request to generate the token. Here there is a risk: I'm not generating random tokens (probably more secure to avoid smart people acting like a user and responding to the survey - anyway, in my scenario this is not a concern)
I run again a Web Request to get the token that has just been generated
Then I send the email:
https://luxclusif.atlassian.net/servicedesk/customer/portal/15/{{issue.key}}/feedback?token={{webResponse.body.value.token}}
Best Regards,
Anderson.
@Anderson Barbosa Hi!Maybe you know how to fix this error
I am using a script post function to set Feedback token property using Rest call in script itself - here is the code:
#################################################################
import groovy.json.JsonSlurper;import com.atlassian.jira.issue.CustomFieldManagerimport org.apache.log4j.Loggerimport org.apache.log4j.Levelimport com.atlassian.jira.bc.issue.IssueServiceimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.link.IssueLinkTypeManagerimport com.atlassian.jira.issue.IssueInputParametersimport com.atlassian.jira.issue.IssueManagerimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.ModifiedValueimport com.atlassian.jira.event.type.EventDispatchOptionimport com.atlassian.jira.issue.index.IssueIndexManagerimport com.atlassian.jira.issue.util.DefaultIssueChangeHolderimport com.atlassian.jira.issue.util.IssueChangeHolderimport com.atlassian.jira.issue.index.IssueIndexingServiceimport com.atlassian.jira.issue.fields.CustomFieldimport org.apache.commons.lang.RandomStringUtilsimport com.atlassian.jira.config.properties.APKeys
IssueService issueService = ComponentAccessor.getComponent(IssueService);
MutableIssue mutIssue = (MutableIssue)issue
def user = ComponentAccessor.getJiraAuthenticationContext().loggedInUserdef groupManager = ComponentAccessor.getGroupManager();def customFieldManager = ComponentAccessor.customFieldManager
IssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder()IssueIndexManager issueIndexManager = ComponentAccessor.getComponent(IssueIndexManager.class)IssueIndexingService issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService.class)
def issueManager = ComponentAccessor.getIssueManager()def issuekey = mutIssue.key
String base_Url = ComponentAccessor.getApplicationProperties().getDefaultBackedString(APKeys.JIRA_BASEURL)def itSurvey = base_Url+"/rest/api/2/issue/"+issuekey+"/properties/feedback.token.key"System.out.println("itSurvey :::: "+ itSurvey)InputStream response = get(itSurvey)
def baseURL = base_Url+"/rest/api/2/issue/"+issuekey+"/properties/feedback.token.key"private InputStream get(String baseURL) {String charset = (('a'..'z') + ('0'..'9')).join()Integer length = 30String randomString = RandomStringUtils.random(length, charset.toCharArray())
def issueManager = ComponentAccessor.getIssueManager()MutableIssue mutIssue = (MutableIssue)issuedef issuekey = mutIssue.keydef issueID = mutIssue.getId()def data ="{\"token\":\""+randomString+"\",\"issueID\":"+issueID+"}"def url = new URL(baseURL);System.out.println ("+++++++Issue Key ::::: "+issuekey)System.out.println ("+++++++Issue ID ::::: "+issueID)System.out.println ("+++++++Token ::::: "+randomString)HttpURLConnection connection = url.openConnection() as HttpURLConnection;connection.requestMethod = "PUT"connection.setRequestProperty("Authorization", "Basic amlyYXNkX2ludGVncmF0aW9uOmppcmFzZGludGVndHN0")connection.setRequestProperty("OSLC-Core-Version", "2.0")connection.setRequestProperty("Accept", "application/json")connection.doOutput = trueconnection.connect()DataOutputStream wr = new DataOutputStream (connection.getOutputStream ());wr.writeBytes (data);wr.flush ();wr.close ();
println "responseCode: " + connection.getResponseCode()InputStream responseif (connection.getResponseCode() == 200){response = connection.getInputStream()}return responseSystem.out.println("Response::::" + response)}
def curl = "curl -u user:pwd -X GET -H \"Content-Type: application/json\" "+base_Url+"/rest/api/2/issue/"+issuekey+"/properties/feedback.token.key"System.out.println("CURL:::: "+ curl)
def output = curl.execute().text
String contentM = new java.util.Scanner(output).useDelimiter("\\A").next();def jsonSlurperM = new JsonSlurper()def objectM = jsonSlurperM.parseText(contentM)def token = objectM['value']['token']System.out.println ("Token ::::::"+token)Collection cf_Survey = customFieldManager.getCustomFieldObjectsByName("Survey Token")def iterator1 = cf_Survey.iterator()CustomField customField_Surveywhile(iterator1.hasNext()){customField_Survey = iterator1.next()}ModifiedValue modifiedValue = new ModifiedValue(mutIssue.getCustomFieldValue(customField_Survey), token)mutIssue.setCustomFieldValue(customField_Survey, token)customField_Survey.updateValue(null, mutIssue, modifiedValue, issueChangeHolder)issueIndexingService.reIndex(mutIssue)
############################################################
Then using this custom field in email sent to customer. You can try and let me know if this helps...
It is important to remember about token, because your website might not have public access.
It is explained here:https://confluence.atlassian.com/jirakb/how-to-send-csat-link-to-customer-using-custom-notification-via-automation-when-default-request-resolved-customer-notification-disabled-1086405958.html
How to create token and how to use it. (You can still use get method instead of POST)
It looks like you're new here. Sign in or register to get started.