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

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.