Get Started

API Reference

Data Mode

Data Mode adds client-side encryption to your published pages. When enabled, page content is encrypted with AES-256-GCM before being stored on CDN. Only clients with the content key can decrypt and display the content.

This is useful for protecting premium content, gated documentation, or any pages you want to keep private even though they're hosted on a public CDN.


How Data Mode Works

  1. Enable Data Mode → PageGun generates a unique content encryption key
  2. Publish pages → Content is encrypted before upload to CDN
  3. Client decrypts → Your frontend uses the content key to decrypt pages at runtime
  4. Key never stored on CDN → The encryption key is only returned once when enabling Data Mode
Text
Your Content → AES-256-GCM Encryption → CDN (encrypted)
                                           ↓
Client + Content Key → Decrypted Content → Rendered Page

Get Data Mode Status

HTTP
GET /v1/projects/:id/data-mode

Returns the current Data Mode status for a project.

Path Parameters

NameTypeRequiredDescription
idstringYesProject ID

Request

Terminal
curl https://api.pagegun.com/v1/projects/MgdGoare/data-mode \
  -H "Authorization: Bearer pgk_live_xxxxx"
TypeScript
const response = await fetch(
  "https://api.pagegun.com/v1/projects/MgdGoare/data-mode",
  { headers: { Authorization: "Bearer pgk_live_xxxxx" } }
);

const { data } = await response.json();

Response

JSON
{
  "success": true,
  "data": {
    "enabled": true,
    "enabled_at": "2024-02-01T12:00:00Z"
  }
}

Enable Data Mode

HTTP
POST /v1/projects/:id/data-mode

Enables Data Mode and returns the content encryption key.

Path Parameters

NameTypeRequiredDescription
idstringYesProject ID

Request Body

NameTypeRequiredDescription
actionstringYesMust be "enable"

Request

Terminal
curl -X POST https://api.pagegun.com/v1/projects/MgdGoare/data-mode \
  -H "Authorization: Bearer pgk_live_xxxxx" \
  -H "Content-Type: application/json" \
  -d '{"action": "enable"}'
TypeScript
const response = await fetch(
  "https://api.pagegun.com/v1/projects/MgdGoare/data-mode",
  {
    method: "POST",
    headers: {
      Authorization: "Bearer pgk_live_xxxxx",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ action: "enable" }),
  }
);

const { data } = await response.json();
// ⚠️ Save data.contentKey securely — it won't be shown again!
console.log("Content Key:", data.contentKey);

Response

JSON
{
  "success": true,
  "data": {
    "enabled": true,
    "contentKey": "a1b2c3d4e5f6..."
  }
}

Disable Data Mode

HTTP
POST /v1/projects/:id/data-mode

Disables Data Mode. Published pages will no longer be encrypted on CDN.

Request Body

NameTypeRequiredDescription
actionstringYesMust be "disable"

Request

Terminal
curl -X POST https://api.pagegun.com/v1/projects/MgdGoare/data-mode \
  -H "Authorization: Bearer pgk_live_xxxxx" \
  -H "Content-Type: application/json" \
  -d '{"action": "disable"}'

Response

JSON
{
  "success": true,
  "data": {
    "enabled": false
  }
}

Regenerate Key

HTTP
POST /v1/projects/:id/data-mode

Generates a new encryption key and re-encrypts all published content. Use this if you've lost the original key or want to rotate keys.

Request Body

NameTypeRequiredDescription
actionstringYesMust be "regenerate-key"

Request

Terminal
curl -X POST https://api.pagegun.com/v1/projects/MgdGoare/data-mode \
  -H "Authorization: Bearer pgk_live_xxxxx" \
  -H "Content-Type: application/json" \
  -d '{"action": "regenerate-key"}'

Response

JSON
{
  "success": true,
  "data": {
    "enabled": true,
    "contentKey": "f6e5d4c3b2a1..."
  }
}

CDN Content Structure

When Data Mode is enabled, published content on CDN follows this structure:

Text
/{project_id}/
  _index.json          # Page manifest (always unencrypted)
  {page_slug}.json     # Encrypted page content

Each encrypted page file contains:

JSON
{
  "iv": "base64-encoded-iv",
  "ciphertext": "base64-encoded-encrypted-content",
  "tag": "base64-encoded-auth-tag"
}

Content Key Security

  • Store the content key in environment variables or a secrets manager
  • Never expose the key in client-side source code directly
  • Use a server-side proxy or edge function to inject the key at runtime
  • Rotate keys periodically using the regenerate-key action
© 2026 PageGun. All rights reserved.