Customer API quickstart
Before you start
Section titled “Before you start”- A Plunk Commerce plan (or Studio Storefront). See which plans include the API.
- A workspace owner or admin to create the key. See API keys.
- Decide where the key will run. Browser code gets a publishable key (
pk_live_…), locked to your site’s origins. Server code gets a secret key (sk_live_…). See authentication and keys.
1. Read your capabilities document
Section titled “1. Read your capabilities document”Every integration starts here. It lists the resource families and endpoints your key can reach.
curl https://api.plunk.io/cx/v1/capabilities \ -H "Authorization: Bearer sk_test_••••"// Server-side (Node 18+). Never put a secret key in browser code.const res = await fetch('https://api.plunk.io/cx/v1/capabilities', { headers: { Authorization: `Bearer ${process.env.PLUNK_SECRET_KEY}` },});const caps = await res.json();console.log(caps.tenantType, caps.families.map((f) => f.name));import os, requests
res = requests.get( "https://api.plunk.io/cx/v1/capabilities", headers={"Authorization": f"Bearer {os.environ['PLUNK_SECRET_KEY']}"},)caps = res.json()print(caps["tenantType"], [f["name"] for f in caps["families"]]){ "tenant": "youraccount", "tenantType": "retailer", "mode": "test", "aggregationFloor": 5, "labels": { "location": "Showroom" }, "families": [ { "name": "products", "key": "publishable", "scopes": ["products:read", "recommendations:read"], "label": null, "endpoints": ["GET /cx/v1/products/top/{range}", "GET /cx/v1/products/{id}", "…"] } ]}2. Pull this month’s bestsellers
Section titled “2. Pull this month’s bestsellers”curl "https://api.plunk.io/cx/v1/products/top/this_month?limit=3" \ -H "Authorization: Bearer sk_test_••••"const res = await fetch( 'https://api.plunk.io/cx/v1/products/top/this_month?limit=3', { headers: { Authorization: `Bearer ${process.env.PLUNK_SECRET_KEY}` } },);const { items } = await res.json();for (const p of items) console.log(p.rank, p.id, p.title, p.units);res = requests.get( "https://api.plunk.io/cx/v1/products/top/this_month", params={"limit": 3}, headers={"Authorization": f"Bearer {os.environ['PLUNK_SECRET_KEY']}"},)for p in res.json()["items"]: print(p["rank"], p["id"], p["title"], p["units"])A secret key also gets revenue and aov on each row. A publishable key gets rank, units and orders only, and rows under 5 orders are left out.
3. Send an event from your storefront
Section titled “3. Send an event from your storefront”Publishable keys can write events. Register your site’s origins on the key first, or the call is refused with 401.
curl -X POST https://api.plunk.io/cx/v1/ingest/event \ -H "Authorization: Bearer pk_test_••••" \ -H "Content-Type: application/json" \ -d '{ "type": "product_view", "visitorRef": "v_84af", "productId": "SF-1042" }'await fetch('https://api.plunk.io/cx/v1/ingest/event', { method: 'POST', headers: { Authorization: 'Bearer pk_test_••••', // publishable keys are safe in the browser 'Content-Type': 'application/json', }, body: JSON.stringify({ type: 'product_view', visitorRef: 'v_84af', productId: 'SF-1042' }),});requests.post( "https://api.plunk.io/cx/v1/ingest/event", headers={"Authorization": "Bearer pk_test_••••"}, json={"type": "product_view", "visitorRef": "v_84af", "productId": "SF-1042"},){ "accepted": true, "eventId": "9d1c…", "type": "product_view" }4. Record a sale from your server
Section titled “4. Record a sale from your server”Sales need a secret key. Posting the same orderId again replaces that order’s lines, so webhook retries are safe.
curl -X POST https://api.plunk.io/cx/v1/ingest/sale \ -H "Authorization: Bearer sk_test_••••" \ -H "Content-Type: application/json" \ -d '{ "orderId": "cs_a1B2c3", "customerRef": "cus_R8xT2m", "email": "buyer@example.com", "lines": [ { "productId": "SF-1042", "description": "Harbor Sofa", "quantity": 2, "price": 2398.00 } ] }'await fetch('https://api.plunk.io/cx/v1/ingest/sale', { method: 'POST', headers: { Authorization: `Bearer ${process.env.PLUNK_SECRET_KEY}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ orderId: 'cs_a1B2c3', customerRef: 'cus_R8xT2m', email: 'buyer@example.com', lines: [{ productId: 'SF-1042', description: 'Harbor Sofa', quantity: 2, price: 2398.0 }], }),});requests.post( "https://api.plunk.io/cx/v1/ingest/sale", headers={"Authorization": f"Bearer {os.environ['PLUNK_SECRET_KEY']}"}, json={ "orderId": "cs_a1B2c3", "customerRef": "cus_R8xT2m", "email": "buyer@example.com", "lines": [{"productId": "SF-1042", "description": "Harbor Sofa", "quantity": 2, "price": 2398.00}], },)If something looks off
Section titled “If something looks off”- 401 means the key is missing or wrong, a publishable key came from an origin that isn’t registered on it, or a secret key came from a browser. See API returns 401 or 403.
- 403
secret_key_requiredmeans you sent a sale, order status or reorder request with a publishable key. Move the call to your server. - 403
scope_not_permittedmeans the key’s class or scopes don’t cover that family, or the family isn’t enabled for your account yet. Check your capabilities document.
Related
Section titled “Related”Was this helpful?
Still stuck? Contact support and include the job or page you were on.