From a Shell using CURL I would like to be able to create a issue in JIRA SM

Hello,

From a Shell using CURL I would like to be able to create a issue in JIRA SM.

I have searched the different REST API documentations, but I can’t find the right method to use for authentication (if possible, I would like to use “Basic Auth”).

Thank you, in advance, for your help.

@MichalMonserrat, welcome to the Atlassian developer community.

You can use basic auth for REST APIs. And specifically, here’s instructions to manage API tokens for your Atlassian account. Then you have a choice about how to create the issue. You can use the platform-level POST /rest/api/3/issue to create an issue. This will act like what an agent can do inside of the Jira UI. Alternatively, you can use the service desk/management level APIs to POST /rest/servicedeskapi/request to create a customer request. This acts more like what a customer can do through the portal.

@ibuchanan : Thank you for your help.

I generated an API Token on a user account (not associated with JSM or JSW) and then followed the documentation to encode it in base 64.

When I try to use it in Postman in “Basic Auth” I get the following response returned by the server :

Basic authentication with passwords is deprecated. For more information, see: https://confluence.atlassian.com/cloud/deprecation-of-basic-authentication-with-passwords-for-jira-and-confluence-apis-972355348.html

@MichalMonserrat, try as I might, I cannot reproduce your problem. Here’s what I get with various scenarios. In every case, I was using basic auth using the appropriate email address and API token.

  • My user account, with full admin access to Jira & JSM, effectively an agent POST /rest/api/3/issue -> 200
  • A user account, with no product access, (effectively a customer) POST /rest/api/3/issue -> 403
  • My user account, with full admin access to Jira & JSM, effectively an agent POST /rest/servicedeskapi/request -> 201
  • A user account, with no product access, (effectively a customer) POST /rest/servicedeskapi/request -> 201

In short, “works for me”. Maybe I’m missing something about what you mean by “not associated with JSM or JSW”. Could you explain?

@ibuchanan , Thank you for your tests.

I generated a token for my account which is full admin JIRA SW & JSM.

As before, I did an encoding (under Linux) in base 64 by combining the email address of my Jira account with the token :

echo -n michael.monserrat@xxx.com:qsdlfjusdlfjsdfiuhsdfkjh | base64

I performed a test with Postmal software and Insomnia software. With, the same request in GET and POST. I always get a 401 error.

Thank you, in advance, for your help.

@MichalMonserrat,

Thanks for explaining. I see the problem now. You are “double encoding”. When you use the basic auth options for HTTP clients like Insomnia, Postman, and even curl, they will do the base64 encoding of your credentials for you. If you use the API token directly as the “password” in these tools (do not encode), then I think you will authenticate as expected.

To confirm the difference (not just using Jira’s API), you can usually get a “debug” output in each of these tools. For example, I have Insomnia handy and in the results on the panel, there is a “timeline” tab. When I click mine, I can see the headers that were sent, including the authorization header. And, since basic auth is just base64 encoding (it’s encoded but not encrypted), it’s trivial to reverse to do the decoding and set what got sent. In short, the header should be base64, but the tools do the encoding for you.

Hello @ibuchanan,

When I read the documentation, I thought that it was necessary and I didn’t know that the software did this operation.

I had to do the test without the encoding, but sometimes you don’t think about the simplest things…

I confirm that with CURL that it is necessary to use base 64 encoding at the level of the Header “Authorization”.

Example:

curl --location --request POST 'https://xxxxxx.atlassian.net/rest/servicedeskapi/request' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic qDPbDFjdlshxepoURrtgqgrRGsdgrgsrgqdHTCbosqhthTRrnztZERZERsq' \
--data-raw '{
  "requestParticipants": [
    "gd4hdce6e3ee5ecn2517459"
  ],
  "serviceDeskId": "3",
  "requestTypeId": "43",
  "requestFieldValues": {
    "summary": "Request JSD help via REST",
    "components": [{"name" : "Hello"}],
    "customfield_10218" : [{"value" : "Strong"}],
    "customfield_10222": {"value": "Great"},
    "description": "I need a new *mouse* for my Mac"
  }
}'

Thanks again for your valuable help. :+1:

1 Like

@MichalMonserrat, I’m glad you’re off and running.

Here’s a curl trick to save you the base64 step:

curl -u michael.monserrat@xxx.com:qsdlfjusdlfjsdfiuhsdfkjh ...

That will add the authorization header and do the base64 encoding.