Hi,
I'm trying to post a simple REST API call (hard-coded issue creation) to a test instance via Script Runner. The call should actually happen in a Script Listener but for debugging I'm using the Script Console. Unfortunately I'm stuck with a HTTP 400 response althought the call is successful using Postman.
import groovy.json.StreamingJsonBuilder
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import java.text.SimpleDateFormat
import java.text.DateFormat
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
def baseURL = "http://test2.mydomain:8080/rest/api/2/issue/";
def body_req = [
"""
{ "fields":
{
"project": {"key": "ABC"},
"issuetype": {"name": "Bug"},
"summary": "My Issue.",
"description": "Test"
}
}
"""
]
URL url = new URL(baseURL);
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
connection.setRequestProperty( "Authorization", "Basic T****************************************************************4" );
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();
println("url: " + url);
println("Content:" + connection.getContent())
println("ResponseCode:" + connection.getResponseCode())
println("getResponseMessage:" + connection.getResponseMessage())
Outcome:
java.io.IOException: Server returned HTTP response code: 400 for URL: http://test2.mydomain:8080/rest/api/2/issue/
at java_net_URLConnection$getContent.call(Unknown Source)
at Script337.run(Script337.groovy:36)
In Postman it works:

Jira Core 7.12.3
Script Runner 5.4.48
Thanks for your help!
Cheers, Tom