post an issue to JIRA from confluence using REST API
Asked by Behzad Abdollahi:

I have a form on a confluence page that gets some information from a user and creates an issue on a JIRA server using REST API . I tried all of the things I could find online and still I cant get what I want. Here is all the things I've tried so far:

FYI:

* Confluence and JIRA are linked together.
* I am not in a position to change any server configurations on any of the servers.
* I use Jquery.ajax

1. Directly submitting data as JSON using a POST request using simple Authentication:

```
[jira-domain]/rest/api/2/issue
```

* Outcome: ONLY works on Internet explorer because both of the domains are in the intranet. for other browsers, failing because of CORS (Cross-Origin Resource Sharing)

2. Using Confluence's API and JIRA's application ID to post requests: (this only works for GET requests)  

```
[confluence-domain]/plugins/servlet/applinks/proxy?appId=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&path=[jira-domain]/rest/api/2/issue
```

* Outcome: I always get an HTTP 400 Bad request.

3. Using ANOTHER Confluence's API and JIRA's application ID to post requests:

```
[confluence-domain]/rest/jira-integration/1.0/issues?applicationId=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
```

Note: Json must be an array of issues.

* Outcome: my JSON contains 2 fields "duedate" and "assignee". I get the following errors:

```
"Field 'duedate' cannot be set. It is not on the appropriate screen, or unknown."
"Field 'assignee' cannot be set. It is not on the appropriate screen, or unknown."
```

I deleted these 2 fields from my JSON and I could sucessfully create an issue. BUT these 2 fields are very important and I need them,

after some investigation, I realized that a normal JIRA user cannot set these 2 fields on the jira web interface. (eventhough the same user could set them using the 1st solution from above). I do not want to and cannot get users higher rights.

------------

So can anyone please help me with this problem?


Answers:
author: Nic Brough -Adaptavist-
body: REST respects the issue setup for the users, so you're not going to get anywhere unless you either stop sending due date and assignee, or you enable the users to set them in the UI.

On point 1, where you could set them, it wasn't using the same user.

comments: author: Behzad Abdollahi
body: you are right! assuming the user has the permissions, solution 1 and 3 are working correctly.


author: csolyom
body: What about option 2? For me option 1 and 3 are giving HTTP 500, but options 2 seems to be working with 'GET' calls at least:

```
$.ajax({
 url: '<CONFLUENCE URL>/plugins/servlet/applinks/proxy?appId=<APP_ID>&path=<JIRA_URL_ENCODED>%2Frest%2Fapi%2F2%2Fissue%2FISSUE-123',
 type: 'get',
 contentType: 'application/json',
 success: function (resp) { },
 });
```

but the 'POST' requests always fail with HTTP 400 Bad request: "The request sent by the client was syntactically incorrect"

```
var jiraData = {"fields": {"project": { "key": "PRJ" },"summary": "dummy","description": "test","issuetype": { "name": "Task" }}}

$.ajax({
 url: '<CONFLUENCE URL>/plugins/servlet/applinks/proxy?appId=<APP_ID>&path=<JIRA_URL_ENCODED>%2Frest%2Fapi%2F2%2Fissue',
 type: 'post',
 contentType: 'application/json',
 data: JSON.stringify( jiraData ),
 success: function (resp) { },
 });
```

I am thinking that the JSON should be formatted/escaped somehow.. any clue?

I use: JIRA v7.2.7, Confluence 6.4.3


author: Asai
body: I am having the same problem. Perhaps the Applink doesn't allow POST??


author: Timothy Padgett
body: I'm facing the same problem. A simple JQL works, e.g.

* [https://confluence.mycompany.com/plugins/servlet/applinks/proxy?appId=APP_ID\&path=https://jira.mycompany.com/rest/api/latest/search?jql=project=PROJECT](https://confluence.mycompany.com/plugins/servlet/applinks/proxy?appId=APP_ID&path=https://jira.mycompany.com/rest/api/latest/search?jql=project=PROJECT)

but anything with whitespace fails, even when encoded:

* [https://confluence.mycompany.com/plugins/servlet/applinks/proxy?appId=APP_ID\&path=https://jira.mycompany.com/rest/api/latest/search?jql=project%20=%20MR](https://confluence.mycompany.com/plugins/servlet/applinks/proxy?appId=APP_ID&path=https://jira.mycompany.com/rest/api/latest/search?jql=project%20=%20MR)

The error is :

* *java.net.URISyntaxException: Illegal character in query at index 88: <https://jira.mycompany.com/https://jira.mycompany.com/rest/api/latest/search?jql=project> = MR*

The error is bizarre in that I'm not sure why the first part is repeated?


author: Timothy Padgett
body: actually, I just found this posted solution, which is basically to use "*escape* (*escape* (**myquery** ))" around the JQL.

* [Eduard_Laur](https://community.atlassian.com/t5/user/viewprofilepage/user-id/721431) [Nov 16, 2016](https://community.atlassian.com/t5/Answers-Developer-Questions/Re-Illegal-character-error-when-using-applink-to-retrieve-issues/qaq-p/471075/comment-id/8730#M8730)


Tags: api

jira