Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,559,220
Community Members
 
Community Events
184
Community Groups

Notify rest with ScriptRunner for Jira cloud is not working

Neta Elyakim
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 10, 2018

Hey,

I'm trying to send an email to some user with ScriptRunner plugin.

This is my code:

import org.apache.commons.codec.binary.Base64;
import static io.github.openunirest.http.Unirest.post

//Define authorisation credentails
String authString = "USER:PASS"
byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
String authStringEnc = new String(authEncBytes);

// Add this header into your rest call to specify basic authentication


def resp = post("/rest/api/2/issue/MSD-35/notify")
.header("Authorization", "Basic ${authStringEnc}")
.header("Content-Type", "application/json")
.body([
subject: 'Service desk automation success',
textBody: "Service desk ticket created with script runner automation.",
htmlBody: "test",
to: [
users: [[
name: "neta.elyakim",
active: true
]]
]
])
.asString()
assert resp.status == 204 

 The problem is it's not working- this is script runner docs on this http://scriptrunner-docs.connect.adaptavist.com/jiracloud/script-listeners.html#_email_notify_on_priority_change

I just want to send the email.

I tried it with/out the authorization and it's still not working

This is the error:

Assertion failed: assert resp.status == 204 | | | | 400 false status: 400 - Bad Request body: <html> <head><title>400 Bad Request</title></head> <body bgcolor="white"> <center><h1>400 Bad Request</h1></center> </body> </html> at Script1.run(Script1.groovy:44) at Script1$run.call(Unknown Source) at Script1$run.call(Unknown Source) at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:30) at com.adaptavist.sr.cloud.workflow.AbstractScript$evaluate$0.callCurrent(Unknown Source) at com.adaptavist.sr.cloud.workflow.AbstractScript$evaluate$0.callCurrent(Unknown Source) at com.adaptavist.sr.cloud.events.ScriptExecution.run(ScriptExecution.groovy:27) at ConsoleScriptExecution2_groovyProxy.run(Unknown Source)

Please advise!

Thanks

1 answer

1 accepted

0 votes
Answer accepted
Neta Elyakim
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Aug 01, 2018

With the help of script runner support-

I manage to send the email to a different user:

def resp = post("/rest/api/2/issue/${issueKey}/notify")
.header("Content-Type", "application/json")
.body([
subject: 'Service desk automation success!',
textBody: "Service desk ticket created with script runner automation.",
htmlBody: "<p>Service desk ticket created with script runner automation.</p>",
to: [
//users: [[
/// name: "neta.elyakim",
// active: true
//]]
groups: [[
name: 'some group'
]]
]
])
.asString()

but when I tried to send the request with different user auth (not my auth - different user and to send it to myself)  it's didn't work.

In order to send the post request with someone else auth it needs to be done like this:

https://stackoverflow.com/questions/25692515/groovy-built-in-rest-http-client#42664926

Bug with the notify rest:

https://ecosystem.atlassian.net/browse/ACJIRA-1137

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events