Error message: Client must be authenticated to access this resource.,status-code:401

I used the python sample code provided in the link for get labels

(https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-labels/#api-rest-api-3-label-get)

it is showing error as “Client must be authenticated to access this resource”

Hi @RamachandranGunaseka,

Thanks for your message and welcome to Atlassian Developer Community! :partying_face:

You need to provide an API token in the sample code to authenticate your request. You need to change line 9 in the sample:

auth = HTTPBasicAuth("email@example.com", "<api_token>")

Please read the following documentation if you wish to know more about basic HTTP authentication and API tokens:


Pawel

@PawelCegla ,

I changed that before posting the query here. eventhough it shows the same error.

@RamachandranGunaseka,

I’ve copied & pasted the code sample, changed lines 7 & 9 (url of the Jira Cloud site, user email & API token) and the sample worked fine:

{
    "isLast": true,
    "maxResults": 1000,
    "startAt": 0,
    "total": 3,
    "values": [
        "some-label",
        "some-other-label",
        "yet-another-label"
    ]
}

Please make sure that you changed http://your-domain.atlassian.net, email@example.com & <api_token> to correct values in the sample. Also can you check that the token you created at https://id.atlassian.com/manage-profile/security/api-tokens shows a recent “Last accessed” time after running the code sample?


Thanks!
Pawel

Yes, I did the same but still showing the same error.

when i checked the token accessed, it shows last 4 mins ahgo.

@PawelCegla its working now. its my mistake, username typo error

Great news! :partying_face:

Happy coding!


Pawel

Thanks @PawelCegla

Now i am facing when am using the JQL as below

{“errorMessages”:[“Field ‘labels’ does not exist or this field cannot be viewed by anonymous users.”],“warningMessages”:}

JQL query: query = {
‘jql’: ‘summary ~ ”CVE-2021-46143” AND status != Closed AND status != Done’
}

endpoint: url = “https://your-domain.atlassian.net/rest/api/3/search

@RamachandranGunaseka,

I’ve been able to run the sample Python code from Search for issues using JQL (GET) without any issues.

This error message:

Field ‘labels’ does not exist or this field cannot be viewed by anonymous users.

suggests that this is again an authentication issue.

Are you sure you replaced https://your-domain.atlassian.net, email@example.com & <api_token> (lines 7 & 9 in the sample code) with proper Jira Cloud site URL, user email and API token values?


Thanks!
Pawel

@PawelCegla thanks working fine.