Hi, I have 2 Jira cloud instances;
https://progrezdev.atlassian.net and https://theelite.atlassian.net/
I want to create automation from https://progrezdev.atlassian.net through ScriptRunner for Jira Cloud to automatically create issue at https://theelite.atlassian.net/ if there is a transition (post function) from progrezdev's workflow.
I followed this two references;
https://library.adaptavist.com/entity/using-external-apis-in-sr (cloud code)
and
https://scriptrunner-docs.connect.adaptavist.com/jiracloud/#_static_type_checking(create an issue part)
But it turns out doesn't work.
I have tried with postman, the API Key works on it and I'm able to use POST on both sites, so I guest there's no problem with the API Token and permissions on both jira sites. Also checked the project key and issue type, they do exist on the site.
Please advise, thanks
Here's the script i tried on Script Runner Console and run as current user
import groovy.json.JsonOutput
final externalUrl = "https://theelite.atlassian.net/"
def projectKey = 'TIS'
def taskType = get('/rest/api/3/issuetype').asObject(List).body.find { it['Task'] == 'Task' } [10033]
post('/rest/api/3/issue')
.header('Content-Type', 'application/json')
.body(
[
fields: [
summary : 'Task Summary',
description: "Don't forget to do this!.",
project : [
key: projectKey
],
issuetype : [
id: taskType
]
]
])
.asString().body
def get(def hostUrl, def endpointAndQuery) {
def token = "---inserted my token---------"
get("$hostUrl$endpointAndQuery")
.header('Accept', 'application/JSON')
.header('Authorization', "Bearer $token")
.asObject(Map)
.body
}
def post(def hostUrl, def endpointAndQuery, def bodyJson) {
post("$hostUrl$endpointAndQuery")
.header('Accept', 'application/JSON')
.header('x-api-key', '---inserted my token---------')
.basicAuth('----my email---', '---my password---')
.body(bodyJson)
.asObject(Map)
.body
}
def put(def hostUrl, def endpointAndQuery, def bodyJson) {
put("$hostUrl$endpointAndQuery")
.header('Accept', 'application/JSON')
.header('Authorization', 'Basic ' + '----my email---:---my password---'.bytes.encodeBase64().toString())
.body(bodyJson)
.asObject(Map)
.body
}
The result
java.lang.NullPointerException: Cannot invoke method getAt() on null object
at Script1.run(Script1.groovy:6)
at Script1$run.call(Unknown Source)
at Script1$run.call(Unknown Source)
at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:39)
at com.adaptavist.sr.cloud.events.ScriptExecution.run(ScriptExecution.groovy:29)
at ConsoleScriptExecution1_groovyProxy.run(Unknown Source)
The Logs
Serializing object into 'interface java.util.List'
GET /rest/api/3/issuetype asObject Request Duration: 1119ms
Cannot invoke method getAt() on null object on line 6
Class: com.adaptavist.sr.cloud.events.ConsoleScriptExecution, Config: [:]