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

Retrive {{webhookData}} by ScriptRunner in Automation for jira.

Michael Smith January 19, 2022

From Jira1 we send post requests to Jira2 when an issue is created using the Automation for Jira plugin. The screenshot of the rule:

image.png

 

 

Jira2 receives it using another automation rule. Screenshot below:

image.png
So in the ScriptRunner script, I try to parse {{webhookData}} using the code below:

 

ruleContext.renderSmartValues('{{webhookData.fields.attachment}}')

It returns a JSON string without quotes like the example below:

 

{
self: https://test2.atlassian.net/rest/api/2/attachment/10240,
id: 10240,
filename: image001 (1).png,
author: {
self: https://test2.atlassian.net/rest/api/2/user?accountId=5d978c421d47a50c34d54152,
accountId: 5d978c421d47a50c34d54152,
accountType: atlassian
},
created: 1642631366135,
size: 8854,
mimeType: image/png,
content: https://test2.atlassian.net/rest/api/2/attachment/content/10240
},
{
self: https://test2.atlassian.net/rest/api/2/attachment/10239,
id: 10239,
filename: notes.png,
author: {
self: https://test2.atlassian.net/rest/api/2/user?accountId=5d978c421d47a50c34d54152,
accountId: 5d978c421d47a50c34d54152,
accountType: atlassian
},
created: 1642631367048,
size: 25333,
mimeType: image/png,
content: https://test2.atlassian.net/rest/api/2/attachment/content/10239
}

Is it possible to get correct JSON with quotes like another example below:

{
"self": "https://test2.atlassian.net/rest/api/2/attachment/10240",
"id": 10240,
"filename": "image001 (1).png",
"author": {
"self": "https://test2.atlassian.net/rest/api/2/user?accountId=5d978c421d47a50c34d54152",
"accountId": "5d978c421d47a50c34d54152",
"accountType": "atlassian"
},
"created": 1642631366135,
"size": 8854,
"mimeType": "image/png",
"content": "https://test2.atlassian.net/rest/api/2/attachment/content/10240"
},
{
"self": "https://test2.atlassian.net/rest/api/2/attachment/10239",
"id": 10239,
"filename": "notes.png",
"author": {
"self": "https://test2.atlassian.net/rest/api/2/user?accountId=5d978c421d47a50c34d54152",
"accountId": "5d978c421d47a50c34d54152",
"accountType": "atlassian"
},
"created": 1642631367048,
"size": 25333,
"mimeType": "image/png",
"content": "https://test2.atlassian.net/rest/api/2/attachment/content/10239"
}

Or maybe you know a way how can I retrieve "content" and "filename" of each attachment from JSON without quotes?

Thank you.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events