Pottr/Docs
Topic:Connecting Apps
Build & Integrate
.md

Connecting Apps

Let an external app request a connection and get API keys after one click of admin approval, with no manual setup.

The Handshake

  1. The app calls POST /connect/request with its app slug, a display name and the collections it needs. No API key is required. The response is 202 with a request_id and a single-use polling_token.
  2. WordPress shows a notice to administrators. Opening the Pottr dashboard shows the app and the collections it wants, and the admin clicks Approve or Reject.
  3. The app polls GET /connect/status?request_id=... with the header X-Pottr-Connect-Token. While waiting it receives { "status": "pending" }. After approval it receives approved, the public key and the created collections.

Requests expire after 15 minutes and are limited to 5 per 10 minutes per IP address.

connect.js
const base = 'https://example.com/wp-json/pottr/v1';

const req = await fetch(`${base}/connect/request`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    app: 'task-manager',
    name: 'Task Manager',
    collections: [
      { slug: 'tasks', name: 'Tasks', fields: [{ key: 'title', type: 'text', required: true }] }
    ]
  })
}).then(r => r.json());

// Poll until the admin approves
const status = await fetch(`${base}/connect/status?request_id=${req.request_id}`, {
  headers: { 'X-Pottr-Connect-Token': req.polling_token }
}).then(r => r.json());
// { status: 'approved', public_key: 'pk_live_...', collections: {...} }

From Another WordPress Plugin

Code running on the same site can skip HTTP. See PHP Helpers for pottr_connect_app().

Keyless First Writes

Pottr can also catch a first POST to a collection that does not exist yet. The admin sees the inferred fields and can create the collection with one click, which suits quick prototypes and webhook sources.