Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create an Issue with Jira API REST

When I try to create an Issue via the Jira API REST, I get a 500 Internal server error, I succeeded to get an issue from a project with a get-request but when I try the post-request to create a new issue it doesn't work I get the error.

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
}
like image 852
Alaa-GI Avatar asked Apr 14 '15 11:04

Alaa-GI


People also ask

Does Jira rest api?

The Jira Software and Jira Service Management applications have REST APIs for their application-specific features, like sprints (Jira Software) or customer requests (Jira Service Management). If you haven't used the Jira REST APIs before, make sure you read the Atlassian REST API policy.

Can developer create an issue in Jira?

Team-managed projects have a redesigned, and simplified Jira experience. If you are working on a Scrum project in team-managed, you can create new issues on the backlog screen by selecting the Create issue link or by pressing c.

Is Jira rest api free?

Some of them are free, other ones need to be purchased. Jira is available in two versions, a Cloud version and a Server (on-premise) version.


1 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");
    },
  });
}

Reference

like image 177
Aditya Singh Avatar answered Sep 28 '22 01:09

Aditya Singh