Can't figure out API create issue problem Edited

Hi,

 

i need to be able to create issues on multiple projects when a specific transition is done in a project (multi-tenant environment). i though i could use the REST API with a CURL-based script  to do so, but i have some issue with it.

 

- i login to REST API just fine

 curl -s -c "cookies.txt" -H "X-Atlassian-Token: no-check" -d "os_username=$USERNAME" -d "os_password=$PASSWORD" -d "os_cookie=true" $JIRA_URL/login.jsp --output login.html

- i query the createmeta method and i get a response 

curl -u $USERNAME:$PASSWORD "$JIRA_URL/rest/api/2/issue/createmeta?projectKeys=$PROJECT_KEY&expand=projects.issuetypes.fields" -H "X-Atlassian-token: no-check" --output out/$PROJECT_KEY.INC_CREATE_INFO.out --silent

- i generate the JSON representation considering the fields i can see as mandatory in the "Create Issue" screen:

{
"fields": {
"project": {
"id": "11226"
},
"issuetype": {
"id": "10306"
},
"summary": "test from api",
"description": "test from api",
"assignee": {
"name": "level1"
},
"reporter": {
"name": "level1"
},
"priority": {
"id": "10001"
},
"security": {
"id": "10101"
},
"customfield_10701": "ITSEC-9087",
"customfield_10401": { "id": "12122"},
"customfield_11801": { "id": "12359"},
"customfield_10702": { "id": "10604"},
"customfield_10302": { "id": "11200"},
"customfield_11700": { "id": "12301"},
"customfield_10602": { "id": "10500"},
"customfield_10606": { "id": "10507"},
"customfield_10603": { "id": "10505"},
"customfield_10709": 100,
"customfield_10704": 100
}
}

- when i run the JSON in the REST API Browser, it works fine:

POST https://<removed>/rest/api/2/issue (201)

date: Thu, 11 Jan 2018 15:14:09 GMT
content-encoding: gzip
x-content-type-options: nosniff, nosniff
x-arequestid: 974x42645x1
status: 201
x-asen: SEN-L8621001
strict-transport-security: max-age=31536000; includeSubDomains
x-xss-protection: 1; mode=block
server: nginx
x-frame-options: SAMEORIGIN
x-seraph-loginreason: OK
vary: User-Agent
content-type: application/json;charset=UTF-8
access-control-allow-origin: https://<removed>, *
access-control-expose-headers: Origin
cache-control: no-cache, no-store, no-transform
access-control-allow-credentials: true
content-security-policy: upgrade-insecure-requests
x-asessionid: 9k65a5
x-ausername: g.moscalu%40<removed>
{
"id": "61112",
"key": "WIREFR-3009",
"self": "https://JIRA_URL/rest/api/2/issue/61112"
}

- when i run it in the script, it's not working and i have no error

HTTP/2 415 
server: nginx
date: Thu, 11 Jan 2018 15:32:24 GMT
content-type: text/html;charset=UTF-8
content-length: 0
x-arequestid: 992x43006x1
x-asen: SEN-L8621001
set-cookie: JSESSIONID=966CC9A7790CBBB998BFFECD61DFD3A0;path=/;Secure;HttpOnly
x-seraph-loginreason: OK
set-cookie: atlassian.xsrf.token=B4LU-HOEG-GX5M-JFFI|301ea3b3ff3c7157b4ff17d30a41b40c69adbdd2|lin;path=/;Secure
x-asessionid: 1emzhmh
x-ausername: g.moscalu%40<removed>
x-content-type-options: nosniff

 

Any hints/ideas?

 

I cannot see anything in the log...

1 answer

Hey Gabriel, did you got it solved. If yes what was the problem. I am facing the same issue.

Hi

 

yes, i got it working by:

* downloading the createmeta information

* parse the required fields, and build the JSONs 

* launch the issue creates

 

i cannot attach the whole scripts here, they're kind of huge...

Thanks for the reply.  Yeah I tried to do the same and just passed the required fields with one sub values.  Some thing like this.

curl -D- -u user:pass -X POST --data '{\"fields\":{\"project\":{\"id\":\"18690\"},\"issuetype\":{\"id\":\"12100\"},\"summary\":\"SampleusingAPI\",\"components\":{\"id\":\"26559\"},\"reporter\":{\"key\":\"username\"},\"duedate\":\"2018-10-31\"  }}'  -H \"Content-Type: application/json\"  https://localhost/rest/api/2/issue.

 

Although there are multiple fields in every category I chose the one i felt is the most relevant.         Did you add everything you got from createmeta?

No worries, got it working. Thanks Gabriel for all the help :)

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

22,603 views 2 7
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you