Hi everyone,
I' trying to send a notification to a specific user using the rest api, I have been at this for a while now but cannot get the notification to the sed user, instead I'm getting the notification.
I have tried multiple combinations in the users section with no luck at all.
Can anyone tell me what I'm doing wrong here ?
def writer = new StringWriter()
def markupBuilder = new MarkupBuilder(writer)
// Note that markup builder will result in static type errors as it is dynamically typed.
// These can be safely ignored
markupBuilder.div {
p {
// update url below:
a(href: "https://example.atlassian.net/issue/${issue.key}", issue.key)
span(" has been created for this incident.")
}
p("Thank you")
p("Your Dev Team")
}
def htmlMessage = writer.toString()
def textMessage = new XmlSlurper().parseText(htmlMessage).text()
logger.info("Sending email notification to TopDesk for issue {}", issue.key)
def resp = post("/rest/api/2/issue/${issue.key}/notify")
.header("Content-Type", "application/json")
.body([
subject: "Incident: ${TOPDESKnumber}",
textBody: textMessage,
htmlBody: htmlMessage,
to: [
reporter: false,
assignee: false,
watchers: false,
voters: false,
users: [[
name: 'support2',
emailAddress: 'support@example.com',
active: true
]]
]
])
.asString()
logger.info(resp.toString())
assert resp.status == 204
Thank you
Philippe
Hi Philippe,
I'm not very familiar with this REST endpoint, but I can see that you've used the wrong brackets in the users attribute:
This is what you've used (at least in your code above):
users: [[
name: 'support2',
emailAddress: 'support@example.com',
active: true
]]
However, according to the documentation, it should be this:
users: [ {
name: 'support2',
emailAddress: 'support@example.com',
active: true
} ],
Also you seem to be missing the comma after the last bracket.
I always recommend to use a REST client on your desktop and build the REST request with that, so you get the most output and maybe even syntax highlighting/error handling. And only, after you've successfully tested it, you can add it to your script to run it inside the application.
I hope that helps!
Regards,
Philipp
That being said, there might be additionall errors with the brackets.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Philipp,
Thanks for your reply,
I'm using Scriptrunner for this request, and as I thought, the syntax I use is correct, if I use the { instead of [ I get an error back from the runner:
Error: java.lang.RuntimeException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 73: unexpected token: support2 @ line 73, column 47. name: 'support2' ^ 1 error at com.adaptavist.sr.cloud.workflow.AbstractScript.parseScript(AbstractScript.groovy:56) at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:37) at com.adaptavist.sr.cloud.workflow.RunScript.run(RunScript.groovy:43)
Regards
Philippe
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Philippe,
okay, right. You're building the body with the script runner functions.
What's the output you get from
logger.info(resp.toString())
?
Regards,
Philipp
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got a 204, so it says its successful:
2020-08-11 07:34:44.151 INFO - status: 204 - No Content body: 2020-08-11 07:34:44.665 INFO - PATCH
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Philippe,
is the email address you've entered used for an account in Jira? And if so, does the account have Browse Projects permission to the project/issue you're testing with?
Regards,
Philipp
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Philippe,
Okay, then I'm out of theoretical reasons, I'm afraid.
I would still use a REST client to send the request directly to ensure the request itself is working properly.
Also, since you have script runner installed anyway, you might also trigger a custom mail using this.
Or, instead of using the REST endpoint for sending a notification, you could use an email object from inside your SR code.
You can have a look at this post how this can be achieved: https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Send-email-with-ScriptRunner/qaq-p/75063
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your help Philipp,
The thing is that I did try this out, but this only works on on premise installations and we are using cloud :)
I'll continue to play around and see what I can find ;)
thank you again
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Philippe,
in that case, you could try to use "accountId" instead of name and emailAddress as stated in the cloud documentation here: https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api-rest-api-2-issue-issueidorkey-notify-post
Maybe that helps.
Regards,
Philipp
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Philipp,
This one actually worked, I'm really great-full for your help
thank you very much :)
Have a great day
Philippe
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Philippe,
I'm glad we could solve this.
Feel free to mark this as the solution, so that those that run into the same issue find it easier.
Have a great day!
Regards,
Philipp
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.