Skip to content

REST API Reference

Richard Kent Gates edited this page Mar 6, 2026 · 1 revision

REST API Reference (Pro)

Pro feature. The REST API requires an active Scriptomatic Pro licence. A 3-day free trial is available — visit Scriptomatic → Account.

Namespace: scriptomatic/v1
Base URL: /wp-json/scriptomatic/v1/
All endpoints use: POST
Authentication: WordPress Application Passwords — Authorization: Basic base64(username:app-password)


Access Controls

Three independent controls are available in Scriptomatic → Preferences:

Control Behaviour when active
API Enable / Disable Uncheck to disable all REST endpoints site-wide. Returns 503 rest_api_disabled.
API Allowed IPs Newline-separated IPv4, IPv6, or CIDR ranges. Requests from unlisted IPs return 403 rest_ip_forbidden. Empty = allow all.
API Allowed Users Restrict access to specific administrator accounts. Requests from unlisted users return 403 rest_user_forbidden. Empty = allow any admin.

Endpoints

Inline Scripts

Endpoint Required params Optional params Description
POST /script location Get current inline script
POST /script/set location, content conditions (JSON) Save inline script
POST /script/rollback location, id (DB row ID) Restore script snapshot
POST /history location List inline script history

External URLs

Endpoint Required params Optional params Description
POST /urls location Get current external URL list
POST /urls/set location, urls (JSON array) Replace external URL list
POST /urls/rollback location, id (DB row ID) Restore URL snapshot
POST /urls/history location List URL history

Preferences

Endpoint Required params Optional params Description
POST /prefs/history limit (1–100, default 20), offset List Preferences Action History (read-only)

Preferences reads and writes are intentionally absent from the REST API — use the Dashboard or WP-CLI.

Managed JS Files

Endpoint Required params Optional params Description
POST /files List all managed JS files
POST /files/get file_id Get file content + metadata
POST /files/set label, content file_id, filename, location, conditions Create or update a file
POST /files/delete file_id Delete a managed JS file
POST /files/upload multipart file field label, file_id, location, conditions Upload a .js file

Parameter Notes

  • location"head" or "footer"
  • id — DB row primary key of the snapshot to restore; obtain IDs from history endpoints
  • conditions — JSON string in {"logic":"and","rules":[...]} format (see Conditional Loading)
  • urls — JSON array of [{"url":"https://...","conditions":{...}},...] objects
  • All write operations use the same service layer as the admin UI — identical validation and activity logging

Example Requests

Get current head script

curl -X POST https://example.com/wp-json/scriptomatic/v1/script \
  -H "Authorization: Basic $(echo -n 'admin:xxxx xxxx xxxx xxxx xxxx xxxx' | base64)" \
  -H "Content-Type: application/json" \
  -d '{"location":"head"}'

Save head script with conditions

curl -X POST https://example.com/wp-json/scriptomatic/v1/script/set \
  -H "Authorization: Basic $(echo -n 'admin:xxxx xxxx xxxx xxxx xxxx xxxx' | base64)" \
  -H "Content-Type: application/json" \
  -d '{
    "location": "head",
    "content": "console.log(\"hello\");",
    "conditions": "{\"logic\":\"and\",\"rules\":[{\"type\":\"front_page\",\"values\":[]}]}"
  }'

Upload a JS file

curl -X POST https://example.com/wp-json/scriptomatic/v1/files/upload \
  -H "Authorization: Basic $(echo -n 'admin:xxxx xxxx xxxx xxxx xxxx xxxx' | base64)" \
  -F "file=@/path/to/tracker.js" \
  -F "label=My Tracker" \
  -F "location=head"

Rollback inline script

# 1. Get history to find the snapshot ID
curl -X POST https://example.com/wp-json/scriptomatic/v1/history \
  -H "Authorization: Basic $(echo -n 'admin:xxxx xxxx xxxx xxxx xxxx xxxx' | base64)" \
  -H "Content-Type: application/json" \
  -d '{"location":"head"}'

# 2. Rollback to a specific snapshot
curl -X POST https://example.com/wp-json/scriptomatic/v1/script/rollback \
  -H "Authorization: Basic $(echo -n 'admin:xxxx xxxx xxxx xxxx xxxx xxxx' | base64)" \
  -H "Content-Type: application/json" \
  -d '{"location":"head","id":42}'

Home

Clone this wiki locally