ContentService not finding a page that exists by id

I’m trying to use ConcentService to find a page with ID. I’m 100% sure that the page exists with the given ID-value.

Here is my call (pageId is a long-value that has an existing page numberl:

Optional<Content> page = apiContentService.find()

The return value is always just empty optional.

And this is how I get the apiContentService reference through a constructor injection:

public MyComponent(@ConfluenceImport("apiContentService") ContentService apiContentService) {

I noticed that without specifying the name for the parameter Spring refuses to start as it seems that there are two different ContentService-instances registered, “contentService” and “apiContentService”. I tried the contentService earlier but it didn’t seem to work either.

I’m trying this with Confluence Server 7.7.4 if that matters.

Any ideas how can I get the page by knowing its ID number? As far as I understand from the documentation, the above method should be the currently recommended method of doing it, right?

Hi @PetriJuhaniRiipinen,

assuming the code is correct: Please run a reindex. Most often no/wrong results are returned of the index is not up-to-date.

Hi @dennis.fischer

Just to confirm, you mean the Rebuild-button on the “Content Indexing”-page under Administration?

I did that and retried but it didn’t help, ContentService won’t still find the page.

Hi @PetriJuhaniRiipinen,

yes, I was referring to this button.

The ContentService checks the permissions of the calling user. Is the user (AuthenticatedUserThreadLocal.get()) which is executing the code permitted to view the page?


Hi @dennis.fischer

Well, who is the calling user, that’s a good question. This call is actually executed from a callback from the Confluence Server when executing migration. After the migration is finished (as triggered by Admin user), Confluence calls the onStartAppMigration-method on my CloudMigrationListenerV1-interface implementation and in that method I get a list of all pageId-values from server that were migrated to Cloud to some other pageId. At that moment I need to go through all the server pages whose IDs were given to my code and check our macros to see which of them need fixing on the Cloud-side.

I am investigating an alternative strategy for the fixing where I don’t need to do this call at all, but still feels a bit odd that it doesn’t work. But I guess permissions are a probably cause here, just not sure what to do about it, if there is anything to be done.