ScriptRunner (Groovy Script) to create remote link for an issue

andy zhu August 16, 2022

I am trying to create remote web link using Groovy Script via ScriptRunner with the following:

post("/rest/api/3/issue/${issue}/remotelink")

   .header('Content-Type','application-json')

   .body(
               [
                   title: 'weblink',
                   url: 'https://a.b.com/'

          ])

    .asString().body

But nothing happens, when I look at the Script Runner log, I saw the following:

2022-08-16 13:48:51.115 INFO - POST /rest/api/3/issue/JIRATEST2-225/remotelink asString Request Duration: 254ms
2022-08-16 13:48:51.116 WARN - POST request to /rest/api/3/issue/JIRATEST2-225/remotelink returned an error code: status: 400 - Bad Request
body: 









<html>

<head>
    <title>Bad Request (400)</title>
    





<!--[if IE]><![endif]-->
<script type="text/javascript" >
    var contextPath = '';
    var DeferScripts = { deferState: 'disabled' };
</script>

 Why it is a bad request and POST body is empty?

1 answer

Suggest an answer

Log in or Sign up to answer
1 vote
Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 17, 2022

Looking at the documentation of the REST API end-point you're trying to call, it seems to me that your request body contains only 2 fields, but the end-points expects much more details.

See: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-remote-links/#api-rest-api-3-issue-issueidorkey-remotelink-post

andy zhu August 18, 2022

When I use RestAPI tool (postman) to call the Jira Cloud API directly, i was able to create the remote link correctly with the following body

{
"object": {
"title": "TestTitle",
"url": "https://a.b.com"
}
}

The API endpoint is: https://xxx.atlassian.net/rest/api/3/issue/{issueId}/remotelink

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events