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

Post IssueLink with JIRA REST API

Anna Maria March 27, 2015

I try to create a new issue link between two existing issues via REST. I use JIRA v6.3.12. I post the following json (type is "application/json") to the resource /rest/api/2/issueLink and get a response with status 400.

 

The json I am posting looks as follows:

 {  

     "type": {  "name": "Relates"  },  

     "inwardIssue": {   "key": "KEY-1"  },

     "outwardIssue": {   "key": "KEY-2"  },  

     "comment": {   

          "body": "Linked related Issues",  

          "visibility": {    "type": "group",    "value": "jira-users"   }

      }

}

I am member of the group jira-users and I can create the link in JIRA by editing one of the issues. But I want to do it automatically via the REST API. What could be the reason of getting the response status 400?

 

Thanks

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
rsperafico
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 27, 2015

Hello Anna Maria,

Thank you for your question.

As @Andreas Ebert has mentioned on previous message, it is difficult for us to identify the reason you are experiencing status code 400 when running /rest/api/2/issueLink.

Could you please run the following command and provide its output:

# [USERNAME], i.e.: annamaria
# [ISSUE-KEY], i.e.: IK-1
# [ISSUE-KEY], i.e.: IK-2
# [JIRA-BASE-URL], i.e.: http://my.jira.domain
curl -u [USERNAME] -p -H "Content-Type: application/json" -X POST -d '{"type": {"name": "Duplicate"},"inwardIssue": {"key": "[ISSUE-KEY]"},"outwardIssue": {"key": "[ISSUE-KEY]"},"comment": {"body": "Testing /rest/api/2/issueLink","visibility": {"type": "group","value": "jira-users"}}}' http://[JIRA-BASE-URL]/rest/api/2/issueLink

Alternatively, you could run the following:

  • you will be prompted to type in password
  • please, notice I have replaced visibility type from GROUP to ROLE
# [USERNAME], i.e.: annamaria
# [ISSUE-KEY], i.e.: IK-1
# [ISSUE-KEY], i.e.: IK-2
# [JIRA-BASE-URL], i.e.: http://my.jira.domain
curl -u [USERNAME] -p -H "Content-Type: application/json" -X POST -d '{"type": {"name": "Duplicate"},"inwardIssue": {"key": "[ISSUE-KEY]"},"outwardIssue": {"key": "[ISSUE-KEY]"},"comment": {"body": "Testing /rest/api/2/issueLink","visibility": {"type": "role","value": "Users"}}}' http://[JIRA-BASE-URL]/rest/api/2/issueLink

In case you are running JIRA under HTTPS protocol, please run the cURL command as per following:

curl -D- -u [USERNAME] ...

If you find this answer useful, I would kindly ask you to accept it so the same will be visible to others who might be facing the same issue you have inquired.

Thank you for your understanding.

Kind regards,
Rafael P. Sperafico
Atlassian Support

Anna Maria March 31, 2015

Hi,

thanks for your answers.

I entered the following comand: 

curl -u [USERNAME] -p -H "Content-Type: application/jso n" -X POST -d '{"type": {"name": "Relates"},"inwardIssue": {"key": "[KEY-1]"}, "outwardIssue": {"key": "[KEY-2]"},"comment": {"body": "Testing /rest/api/2/is sueLink","visibility": {"type": "group","value": "jira-users"}}}' https://[JIRA-BASE]/rest/api/2/issueLink

 

and got the following result: 

curl: (3) [globbing] unmatched brace in column 1 curl: (3) [globbing] unmatched close brace/bracket in column 8 curl: (3) [globbing] unmatched brace in column 1 curl: (3) [globbing] unmatched close brace/bracket in column 10 curl: (3) [globbing] unmatched brace in column 1 curl: (3) [globbing] unmatched close brace/bracket in column 10 curl: (3) [globbing] unmatched brace in column 1 curl: (6) Could not resolve host: Testing curl: (3) [globbing] unmatched brace in column 1 curl: (6) Could not resolve host: group,value curl: (3) [globbing] unmatched close brace/bracket in column 11 curl: (60) SSL certificate problem: unable to get local issuer certificate More details here: http://curl.haxx.se/docs/sslcerts.htmlcurl performs SSL certificate verification by default, using a "bundle"  of Certificate Authority (CA) public keys (CA certs). If the default  bundle file isn't adequate, you can specify an alternate file  using the --cacert option. If this HTTPS server uses a certificate signed by a CA represented in  the bundle, the certificate verification probably failed due to a  problem with the certificate (it might be expired, or the name might  not match the domain name in the URL). If you'd like to turn off curl's verification of the certificate, use  the -k (or --insecure) option.

 

I can not see why there is a problem with the braces. And how can I solve the problem with SSL certificate?

Thanks a lot.

Anna Maria March 31, 2015

I tried it again with -k to turn off the SSL certificate verification and got the following response: curl: (3) [globbing] unmatched brace in column 1 curl: (3) [globbing] unmatched close brace/bracket in column 8 curl: (3) [globbing] unmatched brace in column 1 curl: (3) [globbing] unmatched close brace/bracket in column 10 curl: (3) [globbing] unmatched brace in column 1 curl: (3) [globbing] unmatched close brace/bracket in column 10 curl: (3) [globbing] unmatched brace in column 1 curl: (6) Could not resolve host: Testing curl: (3) [globbing] unmatched brace in column 1 curl: (6) Could not resolve host: group,value curl: (3) [globbing] unmatched close brace/bracket in column 11 HTTP/1.1 400 Bad Request Date: Tue, 31 Mar 2015 11:18:35 GMT X-AREQUESTID: [ID] X-ASEN: [SEN] Set-Cookie: [Cookie] X-Seraph-LoginReason: OK Set-Cookie: [Cookie] X-ASESSIONID: [ID] X-AUSERNAME: [USERNAME] Cache-Control: no-cache, no-store, no-transform X-Content-Type-Options: nosniff Content-Type: application/json;charset=UTF-8 Connection: close Transfer-Encoding: chunked {"errorMessages":["Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apa che.catalina.connector.CoyoteInputStream@622d0806; line: 1, column: 2]"]}

Anna Maria March 31, 2015

I fixed the problems, first I used the version with the visibility type ROLE, and second as I am working with Windows I had to replace " with """ and ' with " in the json to post. All together I entered: curl -D- -k -u [USERNAME] -p -H "Content-Type: application/jso n" -X POST -d "{"""type""": {"""name""": "Relates"""},"""inwardIssue""": {"""key""": """[KEY-1]"""}, """outwardIssue""": {"""key""": """[KEY-2]"""},"""comment""": {"""body""": """Test""","""visibility""": {"""type""": """role""","""value""": "Users"""}}}" https://[JIRA-BASE]/rest/api/2/issueLink

0 votes
Andreas Ebert
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 27, 2015

Does the error response have any messages? According to the docu, status code 400 is returned if:

it can't create the supplied comment. The response will contain an error message indicating why it failed to create the comment. No issue link will be created if it failed to create the comment.

Sam Huawey May 25, 2015

I too get the same message: 400 and bad request. Seems there is a problem with JIRA REST parsing or the documentation for 6.4 is pretty much outdated. Perhaps we should post a bug.

TAGS
AUG Leaders

Atlassian Community Events