Create issue in a Remote JIRA instance from another JIRA using REST API

amit raj March 10, 2017
Hi ALL,
I am trying to create a JIRA issue from one JIRA instance to the other using JIRA API. I am using

groovy. This code works perfectly fine when I run it from intellijIDEA , when I run the same code in scriptrunner console, it doesnt throw any error and never creates the issue. could anyone help please.

I mean create issue in another remote JIRA instance from a local JIRA instance using 
scriptrunner postfunction.

//code starts here-----------------------------------------------------

import groovy.json.StreamingJsonBuilder

def baseURL = "http://19.91.94.39:8080/rest/api/latest/issue";
def authString = "admin:*****".getBytes().encodeBase64().toString();

def body_req = [
"fields": [
"project":
[
"key": "AOBD"
 ],
"summary": "REST Test",
"issuetype": [
"name": "Task"
 ]

]
]
URL url = new URL(baseURL);
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
connection.setRequestProperty( "Authorization", "Basic ${authString}" );
connection.requestMethod = "POST";
connection.doOutput = true;
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, body_req) }
connection.connect();

//code ends here------------------------------

Thank you

1 answer

0 votes
Niclas Sandstroem
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.
March 11, 2017

You calling the wrong URL for REST API create issue to start with.

https://docs.atlassian.com/jira/REST/server/#api/2/issue

 

amit raj March 12, 2017

Hi Niclas,

Thank you very much for your response.

I changed the URL from 

http://19.91.94.39:8080/rest/api/latest/issue to "
http://19.91.94.39:8080/rest/api/2/issue
"

but it still doesnt work. Basically I replaced "latest" with "2" . is that correct?

 

Thank you

Niclas Sandstroem
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.
March 12, 2017

You can find plenty of examples here. Make sure it works with cURL first.

https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-create-issue

Your payload seem to [] instead of expected {}.

Br, Niclas

 

 

adammarkham
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.
March 13, 2017

In addition to what Niclas has said, if you have an application link setup between both you're best off using that. There's some examples of how to do that to intregrate between Atlassian application using ScriptRunnner here: https://scriptrunner.adaptavist.com/4.3.18/jira/interacting-with-other-apps.html

Rajesh_Ramankutty
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 15, 2022

Hi team can u give me this code for creating issue m trying to create issue from one jira to another using script runner

Suggest an answer

Log in or Sign up to answer