The below command requests my password and then succeeds.
curl -u MyUsername -p -X PUT -H "Content-Type: application/json" --data '{"update":{"labels":[{"add":"test"}]}}' MyURL:8080/rest/api/latest/issue/TicketID
Following the basic authentication example. I would expect this to work using a token but I receive an access denied message.
curl -u MyEMAIL:MyToken -p -X PUT -H "Content-Type: application/json" --data '{"update":{"labels":[{"add":"test"}]}}' MyURL:8080/rest/api/latest/issue/TicketID
.
- (I also tried with username instead of email)
- The token was generated from my profile on the server. The username and email are also taken as shown on my profile.
Can anyone help? Ive also tried it this way (https://community.atlassian.com/t5/Jira-questions/How-to-authenticate-to-Jira-REST-API-with-curl/qaq-p/1312165), so it seems like the token does not work. Considering there's no options when generating one, is there really anything else to it beyond 'generate, copy, paste' that could cause an issue?
Hey @romakarol
Welcome to Atlassian Community !!
Is your application hosted on cloud or on-premise. If it is cloud MyURL:8080 is not correct.
You have to use the cURL command like this:
curl --request GET \ --url 'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}' \ --user 'email@example.com:<api_token>' \ --header 'Accept: application/json'
Please check the Jira Cloud API doc here https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-get
In case of server you may have to try like this :
curl -u username:password -X POST --data @data.txt -H "Content-Type: application/json" http://localhost:8080/jira/rest/api/2/issue/{IssueKey}
Try with username and password you use to login to jira
Write data.txt file with label values like this:
{"update":{"labels":[{"add":"test"}]}}
Regards,
Vishwas
curl -u username:password -X POST --data @data.txt -H "Content-Type: application/json" http://localhost:8080/jira/rest/api/2/issue/{IssueKey}
The above works for me if that tells you anything about my deployment type. The 8080 port is necessary and works for our docker-deployed test JIRA environment - you can think of it as just part of the url but I'm providing the curl commands that actually worked for me.
username:password is ok, but I really would prefer to use a token for added security if possible. Is this really the only solution? According to the docs, as I mentioned, essentially this but username:token should have worked for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @romakarol
Got your point.
From your explanation looks like you are on server/dc hosted plaform.
In that case out of the box api token based authentication is not there yet, we may have to rely on other 2 methods of Authorization that is OAuth and Cookie based method.
Please check this link out to understand more on OAuth based authentication
https://community.atlassian.com/t5/Jira-questions/API-Tokens-for-self-hosted-Jira/qaq-p/820644
Regards,
Vishwas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @romakarol Welcome to the Atlassian Community!
Can you try adding below header to your curl request and see if that works ?
-H "Authorization: Basic TOKEN" \
Make sure to replace TOKEN above with Base64 encoded token from your email and api token. Refer Supply basic auth headers for details.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@romakarol Since you tagged Jira-Cloud in your question, I was assuming that you were looking for solution on Cloud.
Following this link I was able to construct and send basic authorization header as follows on my DC version -
curl -H "Authorization: Basic ZnJlZDpmcmVk" -X GET -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/createmeta
You can try and see if that works for you too.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Im assuming 'Zn....VK' is the base 64 encoding of "username:token"? Will try now I had taken Vishwas' answer at face value that this isnt possible.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Reading your link it says to encode username:password
This is essentially what Im already doing, the problem was authorizing specifically with a token
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@romakarol - base64 encoding string is of the form username:password not username:token. If you are trying the latter, then it won't work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @romakarol
Welcome to the Community!!
There's a difference between Server and Cloud API Authentication ways. I'm guessing your query is about Server
Just try with username and password and you should be able to authenticate to the API and let me know if works
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.