Survey Feedback Link

Jyoti Verma August 28, 2019

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.

 

3 answers

0 votes
Сергей Шутов January 11, 2023

@Anderson Barbosa 

Hi!
Maybe you know how to fix this error
Screenshot_6.png

Jyoti Verma January 11, 2023

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.CustomFieldManager
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.issue.fields.CustomField
import org.apache.commons.lang.RandomStringUtils
import com.atlassian.jira.config.properties.APKeys

IssueService issueService = ComponentAccessor.getComponent(IssueService);


MutableIssue mutIssue = (MutableIssue)issue

def user = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
def 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 = 30
String randomString = RandomStringUtils.random(length, charset.toCharArray())

def issueManager = ComponentAccessor.getIssueManager()
MutableIssue mutIssue = (MutableIssue)issue
def issuekey = mutIssue.key
def 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 = true
connection.connect()

DataOutputStream wr = new DataOutputStream (connection.getOutputStream ());
wr.writeBytes (data);
wr.flush ();
wr.close ();

println "responseCode: " + connection.getResponseCode()
InputStream response
if (connection.getResponseCode() == 200){
response = connection.getInputStream()
}
return response
System.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_Survey
while(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...

0 votes
Anderson Barbosa September 15, 2022

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

1.jpg

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

2.jpg

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)

3.jpg

I run again a Web Request to get the token that has just been generated

1.jpg

Then I send the email:

https://luxclusif.atlassian.net/servicedesk/customer/portal/15/{{issue.key}}/feedback?token={{webResponse.body.value.token}}

4.jpg

Best Regards,

Anderson.

Dominik Poważa January 18, 2024

Hi,

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)

0 votes
Alban Ligout August 18, 2020

Hi Jyoti,

I am facing a similar issue. Have you found a solution to your problem? Thank you.

Best regards,

Alban 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events