Forge Macro Export: Unable to Export Specific Page Versions

I’m developing a Confluence macro using Atlassian Forge and need to export macro content based on a specific page version, not the latest version. However, I’ve discovered that Forge export functions don’t receive version information in their context, making it impossible to export content from historical page versions.

Consider a scenario where:

  • A user views page version 5 (historical version)
  • The page contains a macro that processes content
  • The user wants to export the macro’s output based on version 5’s content
  • Currently, the export always uses the latest version (e.g., version 9)

This is problematic when the macro’s output depends on the specific content state at that version.

Technical Details

Manifest Configuration

modules:
  macro:
    - key: my-macro
      title: My Macro
      description: Processes page content
      resource: my-macro
      render: 'native'
      config: true
      layout: 'bodied'
      resolver:
        function: resolver
      adfExport:
        function: export-my-macro
      parameters:
        - identifier: my_param
          name:
            value: Parameter
          type: string
          required: false

Export Function Implementation

import { doc, p } from '@atlaskit/adf-utils/builders';

export async function exportMyMacro(payload) {
  const { context } = payload;
  
  // Extract version information from context
  let pageVersion = context.contentVersion || 
                   context.version || 
                   context.extensionData?.content?.version?.number;
  
  console.log('Available version info:');
  console.log('context.contentVersion:', context.contentVersion);
  console.log('context.version:', context.version);
  console.log('context.extensionData?.content?.version?.number:', 
              context.extensionData?.content?.version?.number);
  
  // This will always be undefined/null in export context
  console.log('Extracted pageVersion:', pageVersion);
  
  // Fetch page content
  const pageContent = await getPageContent(context.contentId, pageVersion);
  
  // Process content and generate ADF
  return doc(p('Processed content from version: ' + (pageVersion || 'latest')));
}

Export Function Payload
The payload received by export functions contains:

{
  "context": {
    "accountId": "5db7e82693536d0c3579a125",
    "cloudId": "51252072-0218-4117-8afd-0f217fece564",
    "contentId": "79953921",
    "extensionContext": {
      "type": "macro"
    },
    "extensionData": {
      "content": {
        "id": "79953921"
      },
      "isConfig": false,
      "space": {
        "key": "SD"
      },
      "type": "macro"
    },
    "isConfig": false,
    "localId": "ce704f5f-8c88-40c7-b92a-895c551e6858",
    "moduleKey": "my-macro",
    "spaceKey": "SD",
    "content": {
      "id": "79953921"
    },
    "space": {
      "key": "SD",
      "id": "262148"
    },
    "type": "macro",
    "config": {
      "my_param": "value"
    },
    "siteUrl": "https://my-site.atlassian.net",
    "macro": {},
    "userAccess": {
      "enabled": false,
      "hasAccess": true
    }
  },
  "exportType": "other",
  "config": {
    "my_param": "value"
  },
  "contextToken": "eyJhbGciOiJSUzI1NiIs..."
}

The Issue

The export function only receives the contentId but no version information, making it impossible to determine which version of the page the user was viewing when they triggered the export.

Is there a way to access the current page version in Forge export functions?

1 Like

In case that anyone needs more information about this, @LeonardoGrzybowski raised an internal issue https://jira.atlassian.com/browse/ECO-1142 feel free to vote for it if you feel that you need it as well , Many thanks @LeonardoGrzybowski for the guidance !!!