# Cannot retrieve content using the Java API

**URL:** <https://community.developer.atlassian.com/t/cannot-retrieve-content-using-the-java-api/50200>\
**Category:** Confluence Data Center\
**Tags:** contentservice, java\
**Created:** [July 23, 2021, 2:53pm UTC](https://community.developer.atlassian.com/t/cannot-retrieve-content-using-the-java-api/50200 "2021-07-23T14:53:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RobertEgan](https://avatars.discourse-cdn.com/v4/letter/r/13edae/32.png) [@RobertEgan](https://community.developer.atlassian.com/u/RobertEgan)\
**Post date:** [July 23, 2021, 2:53pm UTC](https://community.developer.atlassian.com/t/cannot-retrieve-content-using-the-java-api/50200/1 "2021-07-23T14:53:42Z")

</div>

I have created a page, and found the page using

`Content content = contentService.find(expandAll()).withId(id).fetch().get();`

where `id` is the ContentId and `expandAll()` returns an array of all Content.Expansions. I am not concerned about performance because I am only finding one content, and I know the content exists because I am the one who created it. Just to get that out of the way.

So, I have three problems that are almost certainly related, and I simply cannot get around. First, `content.getBody()` returns an empty Map. It is not supposed to be empty, because there is content. Second, when I try to pass in a new ContentBody, ‘ContentService.update()’ throws an IllegalStateException “Request-local WebResourceAssembler has already been initialised”. And third, even when I simply omit the body altogether so that the update succeeds, when I visit the page it tells me there are unpublished changes.

Long story short - why is it so hard to update content using the ContentService ???

Addendum #1 - The REST API helped me past the first issue. It is not enough to expand “body”. You must actually expand “body.storage”.

---

<div class="post-metadata">

**Author:** ![RobertEgan](https://avatars.discourse-cdn.com/v4/letter/r/13edae/32.png) [@RobertEgan](https://community.developer.atlassian.com/u/RobertEgan)\
**Post date:** [July 24, 2021, 10:44pm UTC](https://community.developer.atlassian.com/t/cannot-retrieve-content-using-the-java-api/50200/2 "2021-07-24T22:44:48Z")

</div>

Addendum #1A - Apparently, “body.storage” only works for the REST API. ContentService is still returning an empty Map.

---

<div class="post-metadata">

**Author:** ![RobertEgan](https://avatars.discourse-cdn.com/v4/letter/r/13edae/32.png) [@RobertEgan](https://community.developer.atlassian.com/u/RobertEgan)\
**Post date:** [August 20, 2021, 12:23pm UTC](https://community.developer.atlassian.com/t/cannot-retrieve-content-using-the-java-api/50200/3 "2021-08-20T12:23:14Z")

</div>

So I have a question for the Atlassian developers

WHY did you mark the find methods deprecated, when the new methods do not return the same object as the original methods?

Are there ANY plans to document this new API, other than with javadoc?

---

<div class="post-metadata">

**Author:** ![viqueen-hasnae](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/viqueen-hasnae/32/46039_2.png) [@viqueen-hasnae](https://community.developer.atlassian.com/u/viqueen-hasnae)\
**Post date:** [September 14, 2021, 2:57pm UTC](https://community.developer.atlassian.com/t/cannot-retrieve-content-using-the-java-api/50200/4 "2021-09-14T14:57:51Z")

</div>

Under the hood the REST API uses the ContentService

Have you tried with the following syntax ?

```auto
 return contentService.find(ExpansionsParser.parse("body.storage")).withId(ContentId.of(contentId)).fetch()
                .map(content -> Response.ok(content).build())
                .orElseThrow(notFound("content not found for id : " + contentId));

```

Now onto your questions:

> WHY did you mark the find methods deprecated, when the new methods do not return the same object as the original methods?

I suspect you are talking about `PageManager#get, CommentManager#get ...` methods right ?  
Those indeed do not return the same objects as the ContentService.  
The purpose of that was to decouple our API layer from the data layer and abstract away the concept of Content, and also apply the permission checks by default so app developers won’t have to bother with that when accessing content through the API.

As far as plans to document our APIs other than with javadoc , we have set up this plugin here [Bitbucket](https://bitbucket.org/atlassian/confluence-devrel-plugin/src/main/) to showcase some of the API usages , the team should be adding more examples when time permits.

Cheers  
Hasnae (former Confluence person)

---

<div class="post-metadata">

**Author:** ![JasmineMller](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/jasminemller/32/43231_2.png) [@JasmineMller](https://community.developer.atlassian.com/u/JasmineMller)\
**Post date:** [January 13, 2022, 3:38pm UTC](https://community.developer.atlassian.com/t/cannot-retrieve-content-using-the-java-api/50200/5 "2022-01-13T15:38:06Z")

</div>

Hi Robert,

we are running into the same problem - did you ever figure out a solution?

---

<div class="post-metadata">

**Author:** ![RobertEgan](https://avatars.discourse-cdn.com/v4/letter/r/13edae/32.png) [@RobertEgan](https://community.developer.atlassian.com/u/RobertEgan)\
**Post date:** [January 14, 2022, 1:11pm UTC](https://community.developer.atlassian.com/t/cannot-retrieve-content-using-the-java-api/50200/6 "2022-01-14T13:11:48Z")

</div>

No. It was a prototype, and the project was never funded, so I never pursued it.
