6
votes

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
}
2
You get a 500 error from the Jira api or from your sails service? And was is the actual error content? - Meeker
Well, you found a weaknes, now you can hack it ;-) seriously though, check your server logs to see what the error is or turn error reporting to weboutput on. Error 500 is pretty non descript. It's saying we had a critical erro but we're not telling what. The message will be hidden in your server logs what is actually wrong. - Tschallacka
I tried the same thing with a cURL-request, I've got the same 500 server error, I have the admin previleges I can create an issue directly via the Jira App but impossible via its REST API, I do not have access to the server logs. - Alaa-GI
@Alaa-GI - if you're hosting jira on your own you'll find the logs in your $JIRA_HOME/log-directory. If you're using the hosted jira, you might need to open a support-ticket: answers.atlassian.com/questions/112862/… - Florian Neumann
Thank you, Here is the error in the Jira log file: Java.lang.reflect.InvocationTargetException at sun.reflect.GeneratedMethodAccessor3962.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.atlassian.plugins.rest.common.interceptor.impl.DispatchProviderHelper$ResponseOutInvoker$1.invoke(DispatchProviderHelper.java:234... well it's a very long error - Alaa-GI

2 Answers

5
votes

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

0
votes

It looks like it's expecting some non-null value when it's trying to parse the project or issuetype fields, though without the full stacktrace, it's hard to be sure.

You might try adding an id property to both the project and issuetype fields:

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'll want to make sure to use an appropriate value in both cases.