ContentService is unable to update content / page position

Hey,

I am trying to programmatically update the position and title of an existing page. The idea was to use the ContentService to find and update the pages.

I managed to update the title of an existing page with the following code:

SingleContentFetcher pageFinder = contentService
        .find( new Expansion( "ancestors" ), new Expansion( "body" ), new Expansion( "children" ),
                new Expansion( "container" ), new Expansion( "descendants" ), new Expansion( "history" ),
                new Expansion( "metadata" ), new Expansion( "operations" ), new Expansion( "permissions" ),
                new Expansion( "space" ), new Expansion( "status" ), new Expansion( "version" ) )
        .withId( ContentId.of( pageID ) );

Content page = pageFinder.fetchOrNull();

ContentBuilder contentBuilder = Content.builder( page );
Version prefVersion = page.getVersion();

VersionBuilder newVersionBuilder = prefVersion.nextBuilder();

contentBuilder.title( title );
contentBuilder.version( newVersionBuilder.build() );
contentBuilder.extension( "position", Position.of( 3 ) );

Content updatedContent = contentBuilder.build();

contentService.update( updatedContent );

However the position attribute of the page is not updated at all and moreover the page gets automatically placed under the homepage as a direct childpage (ignoring the previous position in the page hierarchy).
Would be grateful for any help on this problem!

Best regards,
Fabian Ingenhorst

Hi Fabian,

It is true that I don’t see any place where Atlassian has documented the usage of the new code. It is pretty much up to guessing.

Here’s my code, which successfully creates a version, in case it helps.

Best regards,
Adrien

Version updatedVersion = page.getVersion()
    .nextBuilder()
    .message("Message to explain the change")
    .by(User.fromUserkey(user.getKey()))
    .when(new Date())
    .content(body.getContentRef())
    .minorEdit(false)
    .hidden(false)
    .build();

Content.ContentBuilder contentBuilder = Content.builder(page);
Content updatedContent = contentBuilder
        .version(updatedVersion)
        .body(result, ContentRepresentation.STORAGE)
        .build();

contentService.update(updatedContent);