CQL search for space labels

im using confluence cloud and i wanna select multiple labels for auiselect2 using ajax request.

I can get all spaceLabels from wiki/rest/api/space/FS?expand=metadata.labels
here is my function code

function select2_labels(input) {
      width: 'value',
      minimumInputLength: 1,
      multiple: true,
      tags: true,
      tokenSeparators: [',', ' '],
      createTag: function (params) {
        var term = $.trim(params.term);
        if (term === '') {
          return null;
        return {
          id: term,
          text: term,
          newTag: true // add additional parameters
      //REST end-point // make the control a multi-select
      ajax: {
        url: function (params) {
          return (
            'rest/api/space/FS?expand=metadata.labels?name~"' +
            params +
        type: "GET",
        dataType: "json",
        cache: true,
        transport: function (params, success, failure) {
            url: params.url,
            type: "GET",
            contentType: "application/json",
            success: function (data) {
              params.data = JSON.parse(data);
        // parse data from the server into form select2 expects
        data: function data(term) {
          return {
            cql: "name~'" + term + "*'",
        // parse data from the server into form select2 expects
        results: function (data) {
          const results = [];
          data.results.forEach(function makeResults(element, index) {
              label: element.label,
          return {
            results: results,
      initSelection: function (element, callback, label_list) {
      id: function id(user) {
        if (label.label == undefined) {
          return label.id;
        } else {
          return label.label.id;
      // define how selected element should look like
      formatSelection: function formatSelection(label) {
        if (input != "") {
          input.parent().find('.list-creators').css("border-bottom", "1px solid lightgray");
          input.append('<li creator_id="' + label.label.id + '" class="aui-dropdown2-checkbox interactive status-check list-creator-filter aui-dropdown2-interactive" resolved="" aria-checked="false" tabindex="0"><div class="search-creator-option-timeline"><div class="search-creator-option"><div class="search-creators"><div class="search-creator-name"><span class="search-profil-creator"><a href="#" target="_blank" class="confluence-userlink">' + label.label.name + '</a></span></div></div></div></div></li>');
        return (
          '<span style="display: flex;align-items: center" class="sp-dropdown-user-selector-li" id=' +
          label.label.id +
          ">" +
          Select2.util.escapeMarkup(label.label.name) +

Hi @mehdi ,

Can you please provide a bit more context around your request?

When you say “label”, do you mean Confluence labels?

If so, have you seen the https://developer.atlassian.com/cloud/confluence/advanced-searching-using-cql/ page and the example about how to filter for labels (first condition in the example below):
label = "performance" and type = "blogpost"

To restrict that to a specific space, you can then add the space condition (there are a few examples about how to use it on the page I’ve shared above).

Please note that you’ll need to change the endpoint to the equivalent to the following to search using CQL via the app:

Let us know,

1 Like

Hi @ccurti thank u for ur reply
Im searching for space labels and not content ( page or blogspot) labels
i wanna filter results by ajax request
/wiki/rest/api/content?&expand=metadata.labels ==> that what im searching for