I’m using ScriptRunner to create some properties for a page, which works ok. What I can’t seem to do is use .find to return them as Groovy’s proxy class blocks .find unless I explicitly set an Expansion; however I can’t figure out the correct expansions to set.
but if I try getting the content from the service instead of the REST api, I get cannot call get() on collapsed object
def found = contentPropertyService.find(new Expansion(JsonContentProperty.Expansions.CONTENT), new Expansion('property'))
.withPropertyKey('my-key')
.withContentId(pageId)
.fetch()
log.warn "found: ${found.get()"
So what are the correct expansions to pass in? I can’t do contentPropertyService.find() because Groovy gets upset as it creates a proxy that doesn’t have access to the finder interface, so I believe I’ve got to use expansion
Thank you so much. Yes, it seems Atlassian didn’t document at all the use of ContentService or how to update the body of a page.
The thing to remember is, it works like in the REST API. Imagine you want to get the storage format of a page, and you would write the URL with ?expand=body.storage - You would get the same with:
contentService.find(
new Expansion("body", new Expansions(new Expansion("storage")))
)
.withId(ContentId.of(pageId))
.fetch()
.get().getBody()
@aragot , I’ve recently found that all these new API services can be easily loaded via the ScriptRunner @PluginModule annotation, making usage a little easier.
@PluginModule
ContentService contentService
for example, however you must using the Expansions on the find else Groovy’s proxy class loader goes haywire. Unfortunately the REST API documentation doesn’t give comprehensive information on expansion options; some Services contain a static default set, but it appears for the majority, it’s a voyage of discovery on the REST API version first…
Your note on how to use the compound Expansions is very useful - I’d not noted the Expansions class in the Javadoc.