How to get the existing labels using the JIRA Service Desk API?

On the customer Portal, the already existing labels get displayed as soon as the customer starts typing in the field.
image
But when I hit the API endpoint for Get request type fields The response is as follows:

{
    "requestTypeFields":[
        {
            "fieldId":"customfield_10088",
            "name":"Labels",
            "description":"",
            "required":false,
            "defaultValues":[],
            "validValues":[],
            "jiraSchema":{
                "type":"array",
                "items":"string",
                "custom":"com.atlassian.jira.plugin.system.customfieldtypes:labels",
                "customId":10088
            },
            "visible":true
        }
    ]
}

The validValues is an empty array. So I wanted to know is it possible to get the already existing labels inside a service desk using the API?

@DevdootMaji,

I’m not sure I understand all the constraints. Why do you need labels in the JSM/JSD API? I ask because it is possible to get all labels through the Jira Cloud platform APIs using GET /rest/api/3/label.

Since the field was being used in a JSM customer portal form, I had the impression that the existing labels should be returned by the JSM API.
Because of your answer now it is clear to me that labels are stored across JIRA and not only the Jira Service Desk.

I tried to hit the GET /rest/api/3/label as suggested by you, but I got values as empty.
API response:

{
    "maxResults": 1000,
    "startAt": 0,
    "total": 0,
    "isLast": true,
    "values": []
}

The endpoint was in this format: GET https://api.atlassian.com/ex/jira/{{cloudid}}/rest/api/3/label
Am I missing any point which is leading to the issue? And is this the correct format of the endpoint?

@DevdootMaji,

That same request works for me, so the URL seems to be correct. Judging from your screenshot, I can see 2 labels, so there should be something there, right? Could it be a permissions issue? Does the user (you?) who authorized the token have access to the labels in the UI? Can you tell us which scopes your OAuth app has?

For the questions:

  1. Yes, my expectation was also that the 2 labels that are there in the screenshot should have been returned in the response.
  2. If it would have been a permission issue then I should have got some error code saying unauthorized access.
  3. Yes, the labels are visible to me on the customer portal form. And I am using the same account to hit the API using Postman.
  4. Following are the set of scopes I have been using:
read:me
read:servicedesk:jira-service-management
read:requesttype:jira-service-management
read:request:jira-service-management
write:request:jira-service-management
read:user:jira
read:request.attachment:jira-service-management
write:request.attachment:jira-service-management
read:servicedesk.customer:jira-service-management
read:request.approval:jira-service-management
read:request.status:jira-service-management
read:request.comment:jira-service-management
write:request.comment:jira-service-management
write:request.status:jira-service-management
read:label:jira

And according to the documentation read:label:jira is the scope that is required to make the API call.
Here is an image of the authorization screen with all the things the OAuth is trying to access:

I meant permissions inside the product, not about the API. For example, it is possible to restrict other elements like projects and issues, such that I might see 2 projects or 2 issues in my UI, but you don’t see any. The API request for getting projects or issues won’t give you any clues that you and I have different permissions to see different things. That said, I looked a little closer just now and realized there are no such permissions that limit labels.

Given the other evidence you’ve provided, I can only think that maybe the cloudId is not the one you are expecting. In a browser, GET {base_url}/_edge/tenant_info. For my site, that is: https://devpartisan.atlassian.net/_edge/tenant_info

Does your tenant_info match what you are getting from accessible-resources? A common mistake is to assume the array of accessible resources does (or should) have only 1 site.

After trying the tenant_info endpoint you provided, for my site i.e. https://zeusdev.atlassian.net/_edge/tenant_info I got

{
    "cloudId": "b3ba8d83-45ad-46ce-80b2-342363abfaa0"
}

And this is the response I got after executing the accessible-resources endpoint

[
    {
        "id": "b3ba8d83-45ad-46ce-80b2-342363abfaa0",
        "url": "https://zeusdev.atlassian.net",
        "name": "zeusdev",
        "scopes": [
            "read:label:jira",
            "read:user:jira",
            "read:servicedesk:jira-service-management",
            "read:servicedesk.customer:jira-service-management",
            "read:requesttype:jira-service-management",
            "read:request:jira-service-management",
            "write:request:jira-service-management",
            "read:request.approval:jira-service-management",
            "read:request.comment:jira-service-management",
            "write:request.comment:jira-service-management",
            "read:request.attachment:jira-service-management",
            "write:request.attachment:jira-service-management",
            "read:request.status:jira-service-management",
            "write:request.status:jira-service-management"
        ],
        "avatarUrl": "https://site-admin-avatar-cdn.prod.public.atl-paas.net/avatars/240/cup.png"
    }
]

So the ids are matching and in the accessible-resources response, we can see that I have the read:label:jira scope.

The label endpoint I am hitting is https://api.atlassian.com/ex/jira/b3ba8d83-45ad-46ce-80b2-342363abfaa0/rest/api/3/label

Here’s an image of the API call:

@DevdootMaji,

Baffling! I’ve run out of theories to try. The labels endpoint works for me under OAuth 2.0. Further diagnosis will require someone to look into logs and your data. I recommend opening a develop support case.

Hello my friend,

I was facing this same challenge, and testing some possibilities I’ve found what we need.

All the custom type fields “com.atlassian.jira.plugin.system.customfieldtypes:labels” was a mystery because the options didn’t appear on labels or any other field option API.
Using this endpoint:"/rest/api/3/jql/autocompletedata/suggestions?fieldName={FieldName}" (https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-jql/#api-rest-api-3-jql-autocompletedata-suggestions-get) we got all data suggestions just the way it appears on screen.

Best regards.

1 Like

Hello @DevdootMaji ,

I believe this is the same behavior tracked in below bug ticket:

Indeed, the “Labels” field is in the list of the ones for which the values are not returned.

Another possible workaround, other than the one provided by @lucas.miranda, is mentioned in the bug ticket:

You can get the default value for all the custom fields by using the Get custom field contexts default values Jira Platform REST API endpoint instead.

However, since I am not sure whether above workaround is applicable to labels fields, I am going to add @lucas.miranda’s one to the bug ticket as well (thanks a lot for it!).

Cheers,
Dario

1 Like