Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing REST API using a macro

Bob Childs July 2, 2018

Hello,

I am using REST API to find all pages that are drafts.

Is there a way I can parse this information using a user macro? I understand that this can be parsed as JSON using JQuery, but I am not proficient in this language. All I simply want is the content in a string form.

Thanks for the he help.

 

 

1 answer

0 votes
Zak Laughton
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 23, 2018

Hi Bob!

I'm not sure how to do this with the Rest API, but I found a way to use methods from the PageManager interface to show the drafts, which may be more direct than using the API. PageManager has two methods that count drafts:

  • countDraftPages() – counts drafts for pages that have not been published.
  • countPagesWithUnpublishedChanges() – counts published pages that have unpublished changes.

The user macro below shows both these methods to show the total number of drafts:

## Macro title: Show number of drafts
## Macro has a body: N
## Body processing: No macro body
## @noparams

#set ($pageManager=$action.getPageManager())
#set ($totalDrafts=$pageManager.countDraftPages() + $pageManager.countPagesWithUnpublishedChanges())

<strong>New page drafts:</strong> $pageManager.countDraftPages()<br>
<strong>Unpublished changes:</strong> $pageManager.countPagesWithUnpublishedChanges()<br>
<strong>Total drafts:</strong> $totalDrafts

(For more information on these methods, see the PageManager Interface docs)

Hope this helps!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events