Page tree generated via API not showned
Asked by aperrone:

Hi,

we develop a custom macro that create pages into a workspace.

When we save the new page and call the API to add the new page to the page tree, it's not showned also is we invoke the reindex methods.

Here below our code:

```
Page parentPage = createRequirementPage(usr, sp, requirementTitle, sg, type, idReq, pdm);
List<Page> contribList = createContributePages(usr, sp, requirementTitle, sg, type, parentPage, idReq);
pageManager.saveContentEntity(parentPage, null);
indexer.index(parentPage);
for (Page contrib: contribList){
? pageManager.saveContentEntity(contrib, null);
? parentPage.addChild(contrib);
? pageManager.saveContentEntity(parentPage, null);
? indexer.index(contrib);
}
indexer.reIndex(parentPage);
indexer.reIndex(sp);
```

where createRequirementPage is:

```
Page page = createBasePage(usr, sp);
page.setTitle(sg+": "+requirementTitle);
page.setParentPage(sp.getHomePage());
page.setAncestors(new ArrayList<>(Arrays.asList(sp.getHomePage())));
```

and createContributePages is:

```
Page contrib = createBasePage(usr, sp);
contrib.setTitle(String.format("Contribute %s %s %s", idReq, sg, system));
contrib.setParentPage(reqPage);
contrib.setAncestors(new ArrayList<>(Arrays.asList(sp.getHomePage(), reqPage)));


private Page createBasePage(ConfluenceUser usr, Space sp){
? Page page = new Page();
? page.setVersion(1);
? page.setCreator(usr);
? page.setSpace(sp);
? return page;
}
```

what happens is that not is shown on lateral page tree![pic1.png](/t5/image/serverpage/image-id/78057i9548C13BE9DAEABE/image-size/large?v=v2&px=999 "pic1.png")but is present when the move into the home.![pic2.png](/t5/image/serverpage/image-id/78056i2AEAD698615D5CE8/image-size/large?v=v2&px=999 "pic2.png")

Could you please assist with issue?

thank you and regards


Answers:
author: Diego
body: Hello [@aperrone](/t5/user/viewprofilepage/user-id/2985529) !

This could be caused by a few reasons. However, we are not really sure what each class means in your code. I would like to ask you a few questions, here we go:
> * Are we talking about User Macros?
>
> [\[Confluence Server\] Writing User Macros](https://confluence.atlassian.com/doc/writing-user-macros-4485.html)
>
> * What is the parent page of the newly created page? (You can check it in the breadcrumb path at the top of your page when you visit it)
> * Has this code worked at some point in the past?

I was not able to readily wrap my head around the code snippets you sent, but you need to be sure to ++*set a parent page for your newly created page*++. If this does not happen, your page will be an orphan and have no place in your Page Tree.
> * ++**[\[Confluence Server\] Orphaned Pages](https://confluence.atlassian.com/doc/orphaned-pages-139542.html)**++

You might be able to set the parent with ++*updatePageInAncestorCollections from the PageManager class.*++ I see you are using methods such as getHomePage and setAncestors. However, ++*I am not sure how or if the values are being passed correctly to the methods.*++

You can reference our classes for Confluence 7.1.x here:
> * ++**[\[Confluence Server\] All Classes](https://docs.atlassian.com/ConfluenceServer/javadoc/7.1.0/allclasses-noframe.html)**++

There is also the chance that you are affected by this bug:
> * ++**[\[Confluence Server\]\[CONFSERVER-58536\] Pages not visible to groups in PageTree when permission is set via ContentPermissionManager class after an update](https://jira.atlassian.com/browse/CONFSERVER-58536)**++

++*Since this a technical development question, I believe you will have better results looking at our development community:*++
> * ++**[\[Atlassian\] Developer Community](https://community.developer.atlassian.com/)**++

I hope this sheds some light on your issue! Looking forward to your reply.


Tags: atl-adm

atl-dev

confluence-server

server