How to find out the user key?

Thank you, I was not aware of that and it was a very helpful hint for finding a solution.

By experimenting with ADF, I found out that I can also persist user mentions as <ac:link><ri:user ri:account-id=\"{account ID}\" /></ac:link>, even though I don’t think this is documented anywhere, and also Confluence itself does not do it like this. This makes my requirement to retrieve the user key obsolete.

Should the need to retrieve the user key ever come up nonetheless, the convert body REST endpoint can be used. It seems to support the atlas_doc_format body type as well, even though the documentation does not mention that. Making a request like this will convert one or more user mentions from ADF to storage format. The user key(s) can then be extracted from the ri:userkey attributes.

const accountId = '...';
AP.request('/rest/api/contentbody/convert/storage', {
    type: 'POST',
    contentType: 'application/json',
    data: JSON.stringify({
        representation: 'atlas_doc_format',
        value: JSON.stringify({
            type: 'doc',
            content: [
                { type: 'mention', 'attrs': { id: accountId } }
            ]
        })
    }),
    success: console.log,
    error: console.log
});
1 Like