How to define Index schema for content properties through REST API

Hello,

I’m trying to add a new content property to Confluence Cloud pages and later use it in CQL search.
If I understand correctly, this custom content property should be indexed in order to be searchable: https://developer.atlassian.com/server/confluence/content-properties-in-the-rest-api/#index-schema-definition

I’ve added following content property to a page using REST API(rest/api/content/{{id}}/property):

{
    "key": "ms-nav-product-id",
    "value": {
        "id": "123ABC"
    }
}

but I get an error when I try searching for it with REST API(rest/api/content/search?cql=content.property%5Bms-nav-product-id%5D.value.id=123-ABC).

"message": "com.atlassian.confluence.api.service.exceptions.BadRequestException: Could not parse cql : content.property[ms-nav-product-id].value.id=123-ABC"

I’ve tried different CQL searches (.value; .id; etc), but still get BadRequestException: Could not parse cql, so my guess is that I have to properly index the content property first.
How do you define Index schema for content properties through REST API?! :thinking:

Thanks,
Raimo

1 Like

You need to define CQL extractions in the descriptor of your app. You can’t do it through the REST API:
https://developer.atlassian.com/cloud/confluence/modules/content-property/

1 Like

@ernst.stefan Thanks for the reply, but I still can’t seem to get this thing working.
I’ve created a simple Atlassian Connect app where I’ve defined following in the atlassian-connect.json:

"confluenceContentProperties": [
        {
            "key": "msnav",
            "name": {
                "value": "MS NAV index"
            },
            "keyConfigurations": [
                {
                    "propertyKey": "msnavpropertykey",
                    "extractions": [
                        {
                            "objectName": "id",
                            "type": "string"
                        }
                    ]
                }
            ]
        }
    ]

The app is nicely showing up in Manage Apps section when running.
I then go ahead and create new Content Property by doing a POST request to
/wiki/rest/api/content/{{contentId}}/property/msnavpropertykey
with following body:

{
    "key": "msnavpropertykey",
    "value": {
        "id": "abc"
    }
}

I check the property by doing a GET request
/wiki/rest/api/content/{{contentId}}/property/msnavpropertykey
and get a correct result

{
    "id": "160759825",
    "key": "msnavpropertykey",
    "value": {
        "id": "abc"
    },
...

However when I try to search it with CQL
/wiki/rest/api/search?cql=content.property[msnavpropertykey].id=abc
I get
400 – Bad Request java.lang.IllegalArgumentException: Invalid character found in the request target [/wiki/rest/api/search?cql=content.property[msnavpropertykey].id=abc ]. The valid characters are defined in RFC 7230 and RFC 3986

After URL encoding square brackets
/wiki/rest/api/search?cql=content.property%5Bmsnavpropertykey%5D.id=abc
I get:

{
    "statusCode": 400,
    "data": {
        "authorized": false,
        "valid": true,
        "errors": [],
        "successful": false
    },
    "message": "com.atlassian.confluence.api.service.exceptions.BadRequestException: Content properties query is invalid, verification failed for tokens: key"
}

What am I doing wrong here? :confused:

Try adding an “alias” - e.g.:

{ "objectName": "id", "type": "string", "alias": "id" },

thanks for the input, but it was an error on my side. Whole “confluenceContentProperties” section was accidentally defined outside the “modules” part in my atlassian-connect.json.
Working correctly now.

Do you see the search results when searching from a Confluence search field?
I only see them when performing a search via rest API.

I’m trying to leverage content properties in my CQL queries to enhance search capabilities. However, I’m not keen on building a full-fledged Connect App just for this.

Is there a more straightforward method, perhaps through the REST API or Atlassian Forge, to achieve this without hosting a dedicated app? My goal is to utilize custom key-value pairs within my CQL searches.

Refer to this thread where the same question was asked a few months ago. It also contains a link to the corresponding feature request for Forge.