Creating a problem with the JRE REST API

When I try to create a problem through the JRE API REST, I get a 500 Internal server error , I managed to get the problem from the project using the get request, but when I try the post request to create a new problem it does not work, I get an error message.

Here is my JavaScript code:

 createIssue: function(req, res) { var Http = require('machinepack-http'); process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; Http.sendHttpRequest({ url: '/rest/api/2/issue/', baseUrl: 'https://jira.mydomain.com', method: 'post', data: { "fields": { "project": { "key": "TEST" }, "summary": "REST ye merry gentlemen.", "description": "Creating of an issue using project keys and issue type names using the REST API", "issuetype": { "name": "Bug" } } }, headers: { "Authorization": "Basic YWxbG9wMS4zp0bWFuzeThYS5l1TIqaXoxOTg5554Jh" }, }).exec({ serverError: function(result) { res.send("server error" + JSON.stringify(result)) }, success: function(result) { res.send("issue has been created succefly"); }, }); } 

Error Content:

 { "body": "{\"errorMessages\":[\"Internal server error\"],\"errors\":{}}", "headers": "{\"server\":\"nginx/1.6.0\",\"date\":\"Tue, 14 Apr 2015 13:45:38 GMT\",\"content-type\":\"application/json;charset=UTF-8\",\"transfer-encoding\":\"chunked\",\"connection\":\"close\",\"x-arequestid\":\"945x246734x1\",\"set-cookie\":[\"JSESSIONID=838923A79DA31F77BDD62510399065CF; Path=/; HttpOnly\",\"atlassian.xsrf.token=BQIV-TVLW-FGBG-OTYU|63c1b4a7b87a9367fff6185f0101c415f757e85b|lin; Path=/\"],\"x-seraph-loginreason\":\"OK\",\"x-asessionid\":\"ughpoh\",\"x-ausername\":\"alaa\",\"cache-control\":\"no-cache, no-store, no-transform\",\"x-content-type-options\":\"nosniff\"}", "status": 500 } 
+5
source share
2 answers

Use params instead of data

JS: -

 createIssue: function(req, res) { var Http = require('machinepack-http'); process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; Http.sendHttpRequest({ url: '/rest/api/2/issue/', baseUrl: 'https://jira.mydomain.com', method: 'post', params: { "fields": { "project": { "key": "TASC" }, "summary": "REST ye merry gentlemen.", "description": "Creating of an issue using project keys and issue type names using the REST API", "issuetype": { "name": "Bug" } } }, headers: { "Authorization": "Basic YWxbG9wMS4zp0bWFuzeThYS5l1TIqaXoxOTg5554Jh" }, }).exec({ serverError: function(result) { res.send("server error" + JSON.stringify(result)) }, success: function(result) { res.send("issue has been created succefly"); }, }); } 

Link

+3
source

It appears to be expecting some non-zero value when trying to issuetype project or issuetype , although without a full stacktrace this is hard to do.

You can try adding the id property to the project and issuetype :

 params: { "fields": { "project": { "key": "TASC", "id": "10001" }, "summary": "REST ye merry gentlemen.", "description": "Creating of an issue using project keys and issue type names using the REST API", "issuetype": { "id": "1", "name": "Bug" } } } 

Obviously, you will want to use the appropriate value in both cases.

0
source

All Articles