API Reference

Pebble provides PHP endpoints for content management and a JavaScript API for frontend integration.

PHP Endpoints

All endpoints are located in your pebble/ directory. POST endpoints require CSRF token validation.

Authentication

POST pebble/auth.php

ActionParametersDescription
check_auth None Check if current session is authenticated
authenticate authKey OR username + password Login with credentials
logout None Destroy session and logout

Content Loading

GET pebble/load.php (Public - no auth required)

ParameterTypeDescription
id string Pebble ID to load
shared boolean Whether to load from shared content directory

Content Saving

POST pebble/save.php (Auth required)

ParameterTypeDescription
id string Pebble ID (alphanumeric, hyphens, underscores)
html string Content to save
shared boolean Save to shared directory
csrf_token string CSRF token from session

Image Upload

POST pebble/upload.php (Auth required)

Accepts multipart form data with an image file. Automatically:

  • Validates file type (JPEG, PNG, GIF, WebP)
  • Resizes to max 2000x2000px while maintaining aspect ratio
  • Compresses for web (JPEG 75%, PNG level 9)
  • Returns the new image path

Content Deletion

POST pebble/delete.php (Auth required)

ParameterTypeDescription
id string Pebble ID to delete
shared boolean Delete from shared directory

Deleted content is moved to trash, not permanently removed.

Control Panel

POST pebble/admin.php (Auth required)

ActionDescription
get_statsContent/storage/trash counts
get_system_infoPHP version, GD, Zip, disk space
check_updatesCheck for new Pebble versions
list_contentList all content items
list_trashList deleted items
restore_trashRestore deleted item
delete_trash_itemPermanently delete
empty_trashClear all trash
get_activity_logGet activity log entries
clear_logsClear activity log
update_authChange password/auth key
list_usersList all users (Admin only, Pro)
add_userCreate new user (Admin only, Pro)
update_userUpdate user role/password (Admin only, Pro)
delete_userRemove user (Admin only, Pro)
get_settingsGet activity log settings
save_settingsSave activity log settings

Backup Management

POST pebble/backup.php (Auth required)

ActionDescription
listList available backups
createCreate new backup ZIP
downloadDownload backup file
restoreRestore from backup
deleteDelete backup file
get_retentionGet auto-delete days setting
set_retentionSet auto-delete days

Pro Endpoints

Zone Content

GET pebble/pro/zone-load.php (Public)

Load zone blocks as JSON with Quill Delta format.

POST pebble/pro/zone-save.php (Auth + License required)

Save zone blocks. Requires valid Pro license.

Repeatable Content

GET pebble/pro/repeatable.php?action=load&id=:id

Load repeatable items array.

POST pebble/pro/repeatable.php (Auth + License required)

Save repeatable items. Requires valid Pro license.

JavaScript API

The global window.Pebble object provides access to core functionality:

// Check authentication status
Pebble.isAuthenticated()  // Returns boolean

// Get CSRF token for custom requests
Pebble.getCSRFToken()     // Returns token string

// Show notification toast
Pebble.showNotification(message, type)  // type: 'success', 'error', 'info'

// Save content programmatically
Pebble.save(id, html, shared)  // Returns Promise

// Load content programmatically
Pebble.load(id, shared)  // Returns Promise

Data Attributes

Core Pebbles

AttributeValueDescription
data-pebblestringUnique pebble ID (required)
data-pebble-type"text" | "image" | "link"Content type (default: text)
data-pebble-shared"true" | "false"Shared across pages

Zones (Pro)

AttributeValueDescription
data-pebble-zonestringZone ID (required)
data-zone-toolbarstringCustom toolbar (e.g., "bold,italic,link,h3")

Available toolbar options: bold, italic, underline, h2, h3, list, link

Repeatables (Pro)

AttributeValueDescription
data-pebble-repeatstringRepeatable container ID
data-pebble-repeat-item-Marks existing items
data-pebble-repeat-template-Hidden template for new items
data-pebble-repeat-minnumberMinimum items (default: 1)
data-pebble-repeat-maxnumberMaximum items (default: 10)
data-pebble-repeat-clone"true" | "false"Show clone button (default: true)

Supported Pebble Types in Repeatables

Inside repeatable items, you can use any pebble type:

  • data-pebble="id" - Plain text (default)
  • data-pebble-type="rich" - Rich text with bold/italic/link
  • data-pebble-type="image" - Uploadable images
  • data-pebble-type="link" - Editable link (text + URL)

Configuration Reference

All settings are defined in config.php. Key settings:

Authentication

ConstantDefaultDescription
PEBBLE_AUTH_KEY-32-char auth key for login
PEBBLE_AUTH_USERNAME-Optional username (requires password)
PEBBLE_AUTH_PASSWORD-Optional password (requires username)
PEBBLE_AUTO_LOGOUT_MINUTES30Inactivity timeout (0 to disable)

Pro Features

ConstantDefaultDescription
PEBBLE_WHITE_LABELfalseHide Pebble branding
PEBBLE_CP_SHOW_MEDIAtrueShow Media tab in CP
PEBBLE_CP_SHOW_USERStrueShow Users tab in CP
PEBBLE_CP_SHOW_BACKUPStrueShow Backups tab in CP
PEBBLE_CP_SHOW_ACTIVITYtrueShow Activity tab in CP
PEBBLE_CP_SHOW_SETTINGStrueShow Settings tab in CP

Other Settings

ConstantDefaultDescription
PEBBLE_TIMEZONE'auto'Timezone for timestamps
PEBBLE_MAX_UPLOAD_SIZE10MBMax upload file size
PEBBLE_MAX_IMAGE_WIDTH1920Max image width (px)
PEBBLE_JPEG_QUALITY85JPEG compression (1-100)
PEBBLE_BACKUP_RETENTION_DAYS30Auto-delete old backups
PEBBLE_ACTIVITY_LOG_MAX_ENTRIES500Max log entries (0=unlimited)
PEBBLE_DISABLE_UPDATE_CHECKfalseDisable version check telemetry

Storage Structure

Pebble stores content in flat files under pebble/data/:

pebble/data/
  content/     # Page-specific content (id.html)
  shared/      # Site-wide content (id.html)
  zones/       # Zone blocks (id.json)
  repeatable/  # Repeatable arrays (id.json)
  uploads/     # Optimized images
  trash/       # Deleted items with timestamps
  backups/     # ZIP backup files

CSRF Protection

All POST requests that modify data require a CSRF token. The token is:

  • Generated per session (32 bytes, cryptographically random)
  • Validated with timing-safe comparison
  • Required on: save, delete, backup, and admin operations

Get the token from your session or via JavaScript:

const token = Pebble.getCSRFToken();

// Include in your requests
fetch('/pebble/save.php', {
  method: 'POST',
  body: JSON.stringify({
    id: 'my-pebble',
    html: 'New content',
    csrf_token: token
  })
});

Next Steps