Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira Cloud ScriptRunner Post Function (arbitrary script) fails when calling REST API with POST

Wayne May 6, 2021

I created a script to be run as ScriptRunner Add-On User (which I understand auto creates authentication). I tried my own function but when this failed tried the example for Notify on Priority Change. Below I have replaced the real issue ID and email for confidentiality. The real issue ID exists and the email address I used is my normal work email address (cloud based with SSO (Single Sign On)).

Both fail with

2021-05-04 16:43:12.586 INFO - Serializing object into 'interface java.util.List'
2021-05-04 16:43:12.639 INFO - GET /rest/api/2/field asObject Request Duration: 554ms
2021-05-04 16:43:12.818 INFO - Sending email notification for issue <my issue ID>
2021-05-04 16:43:13.024 INFO - POST /rest/api/2/issue/90367/notify asString Request Duration: 203ms
2021-05-04 16:43:13.025 WARN - POST request to /rest/api/2/issue/90367/notify returned an error code: status: 400 - Bad Request
body: {"errorMessages":["Can not deserialize instance of com.atlassian.jira.issue.fields.rest.json.beans.UserJsonBean out of START_ARRAY token\n at [Source: com.atlassian.plugin.connect.plugin.auth.scope.InputConsumingHttpServletRequest$1@541f4926; line: 1, column: 350] (through reference chain: com.atlassian.jira.issue.fields.rest.json.beans.NotificationJsonBean[\"to\"]->com.atlassian.jira.issue.fields.rest.json.beans.ToJsonBean[\"users\"])"]}
2021-05-04 16:43:13.026 INFO - Serializing object into 'interface java.util.Map'
2021-05-04 16:43:13.026 INFO - Run script completed

The script is

def resp = post("/rest/api/2/issue/<my issue ID>/notify")
.header("Content-Type", "application/json")
.body([
subject: 'Mail title',
textBody: "Body",
htmlBody: "<p>Body</p>",
to: [
users: [[
name: "firstname.lastname@mycompany.com",
active: true
]]
//groups: [[
// name: 'some group'
//]]
]
])
.asString()

1 answer

0 votes
Thomas Deiler
Community Champion
May 6, 2021

Dear @Wayne ,

I just copy & pasted your 'body' string into my editor. It seems that you are using the wrong brackets. Use '{' instead of '[' and the elements are not quoted. Have a look at the sample from Atlassian.

BtW: You do not use the latest version "3" of the API.

So long

Thomas

Wayne June 22, 2021

Using api version3 I still need double square brackets:

def resp = post("/rest/api/3/issue/${issue.key}/notify")
.header("Content-Type", "application/json")
.body([
subject: 'Component Bug Notification',
textBody: message,
htmlBody: message,
to: [
watchers: true,
users: [[
name: '<my email address'
]]
]
])
.asString()

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events