JAVA UniRest client Jira Cloud API

Hi everyone
i am trying to creat a Jira Cloud issue on my project kanban board, via Restful API.
I am calling the API in a Java backend, and i’m using UniRest for sending request, and Jackson for building my JSON.

This is my code so far:

whenver i run this code i get:
“specify a valid key or project id”

How can i solve this? if i run the same POST request via POstman everything is good. Maybe Basic Auth is the problem?

Thanks in advance for your time

@RaffaeleMessina welcome to the Atlassian developer community.

I followed your code to create a raw HTTP request and I’m getting the same result that you get with Postman. Given the error, I’m suspicious of the payload that is getting put into the body. Maybe using an HTTP proxy like Beeceptor, you could inspect the request “on the wire” to see if the body would really make sense to Jira?

Although Jira (and Confluence too) don’t always report auth errors correctly, I can’t get the error that you do by changing auth. I doubt the problem is related to Basic Auth.

Hi @ibuchanan , thanks for your reply
I checked my payload and i think it is ok

{
  "fields": {
    "summary": "Le password non possono essere uguali",
    "project": {
      "id": "10000"
    },
    "issuetype": {
      "id": "10001"
    },
    "description": {
      "type": "doc",
      "version": "1",
      "content": [
        {
          "type": "paragraph",
          "content": [
            {
              "text": "Error: Le password non possono essere uguali\n    at updateUserCredentials (http://localhost:3000/static/js/main.chunk.js:2769:15)\n    at onClick (http://localhost:3000/static/js/main.chunk.js:3149:23)\n    at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/vendors~main.chunk.js:172221:18)\n    at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/vendors~main.chunk.js:172270:20)\n    at invokeGuardedCallback (http://localhost:3000/static/js/vendors~main.chunk.js:172330:35)\n    at invokeGuardedCallbackAndCatchFirstError (http://localhost:3000/static/js/vendors~main.chunk.js:172345:29)\n    at executeDispatch (http://localhost:3000/static/js/vendors~main.chunk.js:176580:7)\n    at processDispatchQueueItemsInOrder (http://localhost:3000/static/js/vendors~main.chunk.js:176612:11)\n    at processDispatchQueue (http://localhost:3000/static/js/vendors~main.chunk.js:176625:9)\n    at dispatchEventsForPlugins (http://localhost:3000/static/js/vendors~main.chunk.js:176636:7)\n    at http://localhost:3000/static/js/vendors~main.chunk.js:176847:16\n    at batchedEventUpdates$1 (http://localhost:3000/static/js/vendors~main.chunk.js:190532:16)\n    at batchedEventUpdates (http://localhost:3000/static/js/vendors~main.chunk.js:172019:16)\n    at dispatchEventForPluginEventSystem (http://localhost:3000/static/js/vendors~main.chunk.js:176846:7)\n    at attemptToDispatchEvent (http://localhost:3000/static/js/vendors~main.chunk.js:174329:7)\n    at dispatchEvent (http://localhost:3000/static/js/vendors~main.chunk.js:174247:23)\n    at unstable_runWithPriority (http://localhost:3000/static/js/vendors~main.chunk.js:221280:16)\n    at runWithPriority$1 (http://localhost:3000/static/js/vendors~main.chunk.js:179627:14)\n    at discreteUpdates$1 (http://localhost:3000/static/js/vendors~main.chunk.js:190549:18)\n    at discreteUpdates (http://localhost:3000/static/js/vendors~main.chunk.js:172031:16)\n    at dispatchDiscreteEvent (http://localhost:3000/static/js/vendors~main.chunk.js:174213:7)",
              "type": "text"
            }
          ]
        }
      ]
    }
  }
}

basically it’s an error i get from the front and i want it to create a ticket with the error description

Is there an encoding problem? I copy-pasted your payload and I get a different 400 error message:

We can’t create this issue for you right now, it could be due to unsupported content you’ve entered into one or more of the issue fields. If this situation persists, contact your administrator as they’ll be able to access more specific information in the log file.

I wonder if this is somehow affecting your project or issuetype fields, either as keys or as values?

@ibuchanan Right now i’ve found a problem, in “version” field i have “1” and instead is 1 as number, fixed this, but still getting error (invalid project id or key) ; honestly my payload looks identical to the one on the documentation.
Anyway i’ll look closer to see if there are any other errors.

EDIT: if i use postman with the same payload and the correction of the value “1” to 1 it creates me the tocket

Guys i made it; it was Jackson: i was System.out.println my payload before sending it via POST request. The problem is with sys out you are default calling a toString(), but when i passed the payload i didn’t call the to string method, so it was returning me something like this:

it was adding me key value pairs that i didn’t want.

Thanks for the support to all of you :slight_smile:

3 Likes