How to create index schema and use CQL?

I’ve been wrestling with CQL for a while now, time to ask for help.
Whatever I do (see below) I always get the same 400 response

com.atlassian.confluence.api.service.exceptions.BadRequestException: Could not parse cql

These are the docs I’ve read (due to the limit on 2 links for new users I’m cutting the urls)

  • modules/content-property
  • modules/content-property-index-key-configuration
  • connect-app-descriptor
  • confluence-entity-properties/#cql-search-extension
  • advanced-searching-using-cql

plus this How to define Index schema for content properties through REST API thread

I added the confluenceContentProperties module to my descriptor

    "confluenceContentProperties": [
      {
        "name": {
          "value": "My props"
        },
        "key": "myaddon-my-props",  <- this is not in any of the docs, but installation fails without it
        "keyConfigurations": [
          {
            "propertyKey": "all-my-addon-props",
            "extractions": [
              {
                "objectName": "prop1",
                "alias": "my-addon-prop1",
                "type": "string"
              },
               {
                "objectName": "prop2",
                "alias": "my-addon-prop2",
                "type": "string"
              },
              {
                "objectName": "prop3",
                "alias": "my-addon-prop3",
                "type": "string"
              }
            ]
          }
        ]
      }
    ]

I’m adding the properties at the same as I create a page with the /rest/api/content endpoint

"metadata": {"properties": {"all-my-addon-props": {"prop1": "foo", "prop2": "bar", "prop3": "baz"}}}

and I can verify it worked correctly by querying the properties endpoint

https://<MY DOMAIN>.atlassian.net/wiki/rest/api/content/<PAGE ID>/property

Additionally, I can issue simple CQL queries and expand the metadata to prove it’s there e.g.

https://<MY DOMAIN>.atlassian.net/wiki/rest/api/content/search?cql=space=<MY SPACE>&expand=metadata.properties.all-my-addon-props

Now the stuff that does not work:
According to developer.atlassian.com/cloud/confluence/advanced-searching-using-cql/
I should be able to get the pages containing prop1 = foo with

https://<MY DOMAIN>.atlassian.net/wiki/rest/api/content/search?cql=content.properties%5Ball-my-addon-props%5D.prop1%3Dfoo

But this returns status 400 com.atlassian.confluence.api.service.exceptions.BadRequestException: Could not parse cql.

So I notice that content is not in the expandable list when doing the simple space=.. query, and that properties is actually inside metadata so I try that instead

https://<MY DOMAIN>.atlassian.net/wiki/rest/api/content/search?cql=metadata.properties%5Ball-my-addon-props%5D.prop1%3Dfoo

But I get the same 400 error as above.

The docs also mention the use of aliases, so I try that

https://<MY DOMAIN>.atlassian.net/wiki/rest/api/content/search?cql=my-addon-prop1%3Dfoo

But again I get the same 400 error.

So what is going on? AFAIK the descriptor is correct and matches the docs I linked above.

Have you tried replacing dashes with underscores? I believe there is some kind of conflict with using dashes in the propertyKey.

"propertyKey": "all_my_addon_props",

I personally went with camel case for my keys and search pages like this:

`${confApiBaseUrl}/content/search?cql=content.property%5BmsNavProperty%5D.navId=${productId}`

Another thing that I noticed that you have also URL encoded the equal sign. Have you tried without encoding it?

https://<MY DOMAIN>.atlassian.net/wiki/rest/api/content/search?cql=content.properties%5Ball-my-addon-props%5D.prop1=foo

Also double check if your confluenceContentProperties section is in the correct location (that was my issue)

 "modules": {
        "generalPages": [
            {
                 ... 
            }
        ],
        "confluenceContentProperties": [
            {
                "key": "msNavIndex",
                "name": {
                    "value": "MS NAV index"
                },
                "keyConfigurations": [
                    {
                        "propertyKey": "msNavProperty",
                        "extractions": [
                            {
                                "objectName": "navId",
                                "type": "string",
                                "alias": "MS Nav ID"
                            }
                        ]
                    }
                ]
            }
        ]
    }
1 Like

Thank you very much @Raimo it worked with underscores as property keys so

           "extractions": [
              {
                "objectName": "prop1",
                "alias": "my_addon_prop1",
                "type": "string"
              },
...

I never saw any warning about this in any of the docs. It seems the key for the whole module cannot have underscores though… that only worked in either camelCase or in kebab-case.
What a mess…

Hello,

I read the process you followed for adding content properties and searching via CQL but I have some basic questions, if you or someone else can help me with:

  • Where/How to add/define a descriptor?

  • Where/How did you add the properties (foo, bar, baz)?

Thanks in advance!