How may i search a content property via REST CQL search?

Hi all,
I want to search for content properties - which I have posted via REST - via REST. I followed this guide: https://developer.atlassian.com/confdev/confluence-server-rest-api/content-properties-in-the-rest-api.

What I have managed to do so far

  • Post an arbitrary content property (key: “doclang”, value: “de”) to a page.
  • Access it via {baseurl}/{contextpath}/rest/api/content/{pageid}/property/doclang and receive a result:

{
  "id": "154173446",
  "key": "doclang",
  "value": "de",
  "version": {
    "when": "2017-09-07T11:56:04.000+02:00",
    "message": "",
    "number": 1,
    "minorEdit": false,
    "hidden": false
  },
  "_links": {
    "base": "{baseurl}",
    "context": "",
    "self": "{baseurl}/{contextpath}/rest/api/content/{id}/property/doclang"
  },
  "_expandable": {
    "content": "/rest/api/content/{id}"
  }
}
  • Set up a P2 add-on index schema definition in an “empty” plugin (no Java classes). The atlassian-plugin.xml looks like this:
<atlassian-plugin key="${atlassian.plugin.key}" name="${project.name}" plugins-version="2">
    <plugin-info>
        <description>${project.description}</description>
        <version>${project.version}</version>
        <vendor name="${project.organization.name}" url="${project.organization.url}" />
        <param name="plugin-icon">images/pluginIcon.png</param>
        <param name="plugin-logo">images/pluginLogo.png</param>
    </plugin-info>

    <content-property-index-schema key="doclang-confluence-index-schema">
        <key property-key="doclang">
                <extract path="value" type="string" />
        </key>
    </content-property-index-schema>

</atlassian-plugin>
  • The index schema definition gets recognized (I know this, because if it was not working, then I would get a status code 400 when looking for the content property).

Problem

But if I search for the property ({baseurl}/{contextpath}/rest/api/content/search?cql=content.property[doclang].value=%22de%22), then I will get no results:

{
  "results": [],
  "start": 0,
  "limit": 25,
  "size": 0,
  "_links": {
    "self": "{baseurl}/{contextpath}/rest/api/content/search?cql=content.property%5Bdoclang%5D.value=%22de%22",
    "base": "{baseurl}",
    "context": ""
  }
}

What am I missing? Please help. :slight_smile:

Best regards
Alex

Edit:
I have already tried to reindex all contents, restarted the instance and I have posted the content property to a newly created page after installing the index schema definition.

1 Like

I have solved my issue. These are the two things I was not aware of:

  1. The json object should not be {key: "doclang", value: "de}", but: key: "doclang", value: {value: "de"}
    The “outer” value is a reserved word, while the “inner” value is an arbitrary property name.
  2. This finds the content property: {baseurl}/{contextpath}/rest/api/content/search?cql=content.property[doclang].value=de
    My prior cql query contained double quotes, which - even if escaped - are not accepted. Further, hyphens are not accepted in any manor.

I hope this thread will help someone else.

Best regards
Alex

1 Like

I am facing the same issue, but your solution doesn’t seem to work. Maybe I am missing something.

I set the property to one page (below is what I obtained on querying the page property using {baseurl}/{contextpath}/rest/api/content/819201/property/visperPageStatus

{
    "id":"819203",
    "key":"visperPageStatus",
    "value":{"name":"Stat 2"},
    "version":{"when":"2018-01-28T14:15:43.808+02:00","message":"","number":2,"minorEdit":false,"hidden":false},
    "_links":{"base":"http://mint-dev:1990/confluence","context":"/confluence","self":"http://mint-dev:1990/confluence/rest/api/content/819201/property/visperPageStatus"},
    "_expandable":{"content":"/rest/api/content/819201"}
}

The indexer was defined as:

<content-property-index-schema key="page-status-index-schema">
    <key property-key="visperPageStatus">
        <extract path="name" type="string"/>
    </key>
</content-property-index-schema>

However, when querying from browser using {baseurl}/{contextpath}/rest/api/content/search?cql=content.property[visperPageStatus].name=%22Stat%202%22

I receive empty result:

{
    "results":[],
    "start":0,"limit":25,"size":0,
    "_links":{
        "self":"http://mint-dev:1990/confluence/rest/api/content/search?cql=content.property%5BvisperPageStatus%5D.name=%22Stat%202%22",
        "base":"http://mint-dev:1990/confluence","context":"/confluence"
    }
}

Please note that in my case, if I don’t set the quotes, I get a CQL parsing error.

I am working with Confluence 6.4.0.

Hi @cpitis,

try searching without the quotation marks:
{baseurl}/{contextpath}/rest/api/content/search?cql=content.property[visperPageStatus].name=Stat%202

Best regards
Alex

Hi @alexander.botor

Without quotation marks it gives me an error (CQL parsing error).

Best,
Cătălin

Hi @catalin.pitis,

have you tried to search for a value that does not contain a space? Just to exclude other errors. And then search without quotation marks and any other URL encoding.

Best regards
Alex

Hi @alexander.botor

It seems that if I exclude spaces from searches, it works. And without quotation marks.

The conclusion - I am confused:

  1. Search with no spaces in names, it works as you mentioned, no quotation marks.
  2. Search with spaces in names: it gives me parsing error if no quotation marks are used. If I add the quotation marks… it returns empty search.

Hi @catalin.pitis,

I suppose that this has something to do with the multiple encodings and escapings that these CQL requests via REST contain and entail. Maybe we have just to wait how this feature will develop in the future.

Best regards
Alex

In case anyone runs into this… I had an issue with equals sign so I encoded it to be %3D. Once I did that, the value after %3D began with a number (e.g. 12somevalue) which also caused an error. I simply prepended the number with a letter which fixed the error (e.g. a12somevalue).

Thank you Alex for your help and I hope my comment helps someone too!