When are user keys used in mentions and how to resolve them

When I create user mentions in the Confluence Cloud editor, the storage format looks like this:

<ac:link><ri:user ri:account-id="123456:12345678-90ab-cdef-1234-567890abcdef" /></ac:link>

But I have also encountered this (on Cloud not Server/DC):

<ac:link><ri:user ri:userkey="1234567890abcdef1234567890abcdef"/></ac:link>

I know I can get the corresponding account ID for the user key, either by looking at the ADF or converting the storage format snippet to, for example, export view via the conversion endpoint (/wiki/rest/api/contentbody/convert/export_view) and then parsing the account ID out of the link.

My questions are:

  1. Under what circumstances does Confluence produce user mentions that have a user key in the storage format instead of an account ID?
  2. What is the recommended way for apps processing storage format to look up the referenced user? The solution with the conversion endpoint is a bit of a hack, and loading the ADF in an app built around processing storage format and finding the part corresponding to the user mention is not trivial and not ideal for other reasons.

Hi @maximilian ,

Back in 2019/2020 we changed APIs to conform to GDPR and as part of this we switched from user keys to account IDs. I suspect userkey should only be in pages that haven’t been updated since the changes were made. With regard to parsing Confluence storage format, I’m not aware of storage format being formally documented as an schema/API for partners to rely on, however, I will contact the Confluence team to see if they can respond to both of your questions to get a more definitive answer.

Regards,
Dugald

2 Likes

Heya @maximilian :wave:

Like @dmorrow mentioned we’ve been transitioning away from the user key identifier to an account id identifier.

  1. New pages created in Cloud should all use the accountId, but old pages (ex: imported from Server/DC) may still have references to the userkey.

  2. There is a Get user endpoint apps can use if you have an accountId and want to retrieve more user info. However if you’re in a scenario where you only have the userkey then you’ll likely need to leverage the Search user endpoint.

Let me know if that answers your questions!

1 Like

Hi,

Thanks for the information.

Unfortunately the search user endpoint doesn’t let me search for users either by account ID or user key, even though both user.accountid and user.userkey are mentioned in the documentation.

GET /wiki/rest/api/search/user?cql=user%2Eaccountid%3D123456%3A12345678-90ab-cdef-1234-567890abcdef
{
    "statusCode": 400,
    "data": {
        "authorized": true,
        "valid": true,
        "errors": [],
        "successful": true
    },
    "message": "com.atlassian.confluence.api.service.exceptions.BadRequestException: Could not parse cql : "
}

GET /wiki/rest/api/search/user?cql=user%2Euserkey%3D1234567890abcdef1234567890abcdef
{
    "statusCode": 400,
    "data": {
        "authorized": true,
        "valid": true,
        "errors": [],
        "successful": true
    },
    "message": "com.atlassian.confluence.api.service.exceptions.BadRequestException: No field exists with the name: 'user.userkey' Did you mean one of : user.fullname, user.accountid, user"
}

Maybe I’m doing something wrong?

By the way, getting a user by account ID through the /wiki/rest/api/user endpoint works fine.

Regards,
Maximilian

Hey,

I’m able to search by user.accountId via wiki/rest/api/search/user?cql=user.accountId=%226166e28d2f6aed006822daf0%22

where 6166e28d2f6aed006822daf0 is the accountId the the %22 is the URL encoded double quotes.

I’ll check back with the team who’s worked on the search user endpoint regarding the userkey though

2 Likes

Hey,

Thank you. Quoting the account ID does the trick. That should have occurred to me, actually.

I’m looking forward to hearing how to make user.userkey work.

Regards,
Maximilian

Hey,

Regarding the userkey, I searched around and unfortunately don’t think we have an API anymore that takes that as input, likely due to this deprecation notice :slightly_frowning_face:

It seems like someone else as faced the same issue and resolution as you did in the past: How to find out the user key? - #3 by candid

After checking with the team it seems like that conversion and parsing may be the only workaround for now.

2 Likes