Page tree
Skip to end of metadata
Go to start of metadata

You can script Approvals for Confluence using Java/Groovy with a script-running tool.

This feature is currently in Beta and will be expanded based on demand.

Currently you can get Page and Macro Approvals using the Java API - but please let us know if you'd like us to provide more Java API's e.g. for Creating/Manipulating Approvals.

These are really basic examples and just show all methods on the ApprovalJson and ApprovalMemberJson being called.

In reality, you'd probably only call a method or two - but this example is exhaustive.


Page Approvals

Java API examples for Page Approvals.

Get Page Approval

Get the Page Approval as an ApprovalJson and members as ApprovalMemberJson's.

Get Page Approval by Page ID and Page Version
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule;
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal;
import com.atlassian.confluence.user.ConfluenceUser;
import co.uk.automationconsultants.approvals.api.ApprovalPluginComponent;
import co.uk.automationconsultants.approvals.json.ApprovalJson;
import co.uk.automationconsultants.approvals.json.ApprovalMemberJson;

@WithPlugin("co.uk.automationconsultants.approvals.approvals")

@PluginModule
ApprovalPluginComponent approvalPluginComponent;

// Get User
ConfluenceUser user = AuthenticatedUserThreadLocal.get()

// Get Page Approval for Page with ID '65547' and Version '10'
ApprovalJson approval = approvalPluginComponent.getPageApproval(user, 65547, 10);

if(approval != null) {
    // Does Exist, get some details
    String creatorUserKey = approval.getCreatorUsername(); // Ignore name - it's User Key
	Long pageId = approval.getPageId();
	String macroId = approval.getMacroId();
	String title = approval.getTitle();
	Boolean sendRequestNotifications = approval.isRequestNotifications();
	Boolean sendStatusNotifications = approval.isStatusNotifications();
	Boolean expireOnEdit = approval.getExpireOnEdit();
	Date expiryDate = approval.getExpiryDate();
	Integer quorumSize = approval.getQuorumSize();
	for(ApprovalMemberJson member : approval.getMembers()) {
		String userKey = member.getUserKey();
		String status = member.getStatus(); // "pending", "approved", "rejected" or "expired"
		Date date = member.getDate();
	}
	Integer version = approval.getVersion();
	String status = approval.getStatus();
	String pageTitle = approval.getPageTitle();
	Date createdDate = approval.getCreated();
	Date updatedDate = approval.getUpdated();
} else {
    // Doesn't Exist
}


Macro Approvals

Java API Examples for Macro Approvals.

Get Macro Approval

Get the Macro Approval Details and Status as an ApprovalJson with ApprovalMemberJson's contained in the 'members' property (getMembers());

Get Macro Approval by Page ID and Page Version
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule;
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal;
import com.atlassian.confluence.user.ConfluenceUser;
import co.uk.automationconsultants.approvals.api.ApprovalPluginComponent;
import co.uk.automationconsultants.approvals.json.ApprovalJson;
import co.uk.automationconsultants.approvals.json.ApprovalMemberJson;
import co.uk.automationconsultants.approvals.service.exception.*;

@WithPlugin("co.uk.automationconsultants.approvals.approvals")

@PluginModule
ApprovalPluginComponent approvalPluginComponent;

// Get User
ConfluenceUser user = AuthenticatedUserThreadLocal.get()

// Get Macro Approval for Macro with Page ID '65547', Page Version '4', UUID "afi8y-f2f2-..." and Macro ID "bfi8y-f2f2-..."
try {
    ApprovalJson approval = approvalPluginComponent.getMacroApproval(user, 65547L, "afi8y-f2f2-...", "bfi8y-f2f2-...", 4);

    if(approval != null) {
        // Does Exist, get some details
        String creatorUserKey = approval.getCreatorUsername(); // Ignore name - it's User Key
        Long pageId = approval.getPageId();
        String macroId = approval.getMacroId();
        String title = approval.getTitle();
        Boolean sendRequestNotifications = approval.isRequestNotifications();
        Boolean sendStatusNotifications = approval.isStatusNotifications();
        Boolean expireOnEdit = approval.getExpireOnEdit();
        Date expiryDate = approval.getExpiryDate();
        Integer quorumSize = approval.getQuorumSize();
        for(ApprovalMemberJson member : approval.getMembers()) {
            String userKey = member.getUserKey();
            String status = member.getStatus();
            Date date = member.getDate();
        }
        Integer version = approval.getVersion();
        String status = approval.getStatus();
        String pageTitle = approval.getPageTitle();
        Date createdDate = approval.getCreated();
        Date updatedDate = approval.getUpdated();
    } else {
        // Doesn't Exist
    }
} catch(NoPageException | NoSpacePermissionException | NoPagePermissionException | NoPageVersionException | NoApprovalException e) {
    // An error has occurred - see Message or Class of Exception for more information
    e.getMessage();
}
  • No labels