Skip to content

Preview. The API is shared with design partners and may change before launch. Register interest for sandbox access.

Quickstart

This walks through the core flow with curl: get an offer for a cart, create a policy for the paid order, then cancel it as if the item were returned. You only send what’s in the cart; Phew classifies each item and decides whether it can be covered.

If you’d rather not build the offer UI yourself, the drop-in SDK and iframe embed render it for you, and you only need the policy step below.

  1. Set your key. Sandbox keys start with sk_test_. Keep them on your server; they must never reach a browser or an app.

    Terminal window
    export PHEW_KEY=sk_test_...
  2. Create an offer. Send the items in the cart. Amounts are integers in minor units, so 4 990 kr is 499000.

    Terminal window
    curl https://api.getphew.com/v1/offers \
    -H "Authorization: Bearer $PHEW_KEY" \
    -H "Content-Type: application/json" \
    -H "Idempotency-Key: 7f9d6c1e-cart-81723" \
    -d '{
    "currency": "NOK",
    "market": "NO",
    "items": [
    {
    "reference": "SKU-CBX-48",
    "name": "City Bike Explorer",
    "price": 499000,
    "quantity": 1
    }
    ]
    }'

    The response lists the plans the customer can choose from, with the price and the documents to link to:

    {
    "id": "off_01JD7Q8S4M5W2X3Y4Z6A7B8C9D",
    "object": "offer",
    "currency": "NOK",
    "expires_at": "2026-10-23T14:12:09Z",
    "items": [
    {
    "reference": "SKU-CBX-48",
    "eligible": true,
    "plans": [
    { "id": "plan_12m", "term_months": 12, "premium": 8900, "label": "1 year" },
    { "id": "plan_36m", "term_months": 36, "premium": 29900, "label": "3 years" }
    ]
    }
    ],
    "documents": {
    "terms_url": "https://getphew.com/legal/terms/no-2026-10",
    "ipid_url": "https://getphew.com/legal/ipid/no-2026-10"
    }
    }
  3. Show the offer. Display the plan, the price and links to the terms and the IPID. The customer must actively choose it; never pre-select it. See Display requirements.

  4. Create the policy once the order is paid:

    Terminal window
    curl https://api.getphew.com/v1/policies \
    -H "Authorization: Bearer $PHEW_KEY" \
    -H "Content-Type: application/json" \
    -H "Idempotency-Key: order-100482-policy" \
    -d '{
    "offer": "off_01JD7Q8S4M5W2X3Y4Z6A7B8C9D",
    "order_reference": "100482",
    "items": [{ "reference": "SKU-CBX-48", "plan": "plan_36m" }],
    "customer": {
    "name": "Ingrid Hansen",
    "email": "ingrid@example.com",
    "locale": "nb-NO"
    }
    }'

    You get back one policy per covered item, with "status": "active".

  5. Cancel it to simulate a return:

    Terminal window
    curl https://api.getphew.com/v1/policies/pol_01JD7QB2.../cancel \
    -H "Authorization: Bearer $PHEW_KEY" \
    -H "Content-Type: application/json" \
    -d '{ "reason": "item_returned" }'
const phew = async (path: string, body: unknown, idempotencyKey?: string) => {
const response = await fetch(`https://api.getphew.com/v1${path}`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.PHEW_KEY}`,
"Content-Type": "application/json",
...(idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {}),
},
body: JSON.stringify(body),
});
if (!response.ok) throw new Error(`Phew ${response.status}: ${await response.text()}`);
return response.json();
};
const offer = await phew("/offers", {
currency: "NOK",
market: "NO",
items: [{ reference: "SKU-CBX-48", name: "City Bike Explorer", price: 499000, quantity: 1 }],
});
const policies = await phew(
"/policies",
{
offer: offer.id,
order_reference: "100482",
items: [{ reference: "SKU-CBX-48", plan: "plan_36m" }],
customer: { name: "Ingrid Hansen", email: "ingrid@example.com", locale: "nb-NO" },
},
"order-100482-policy",
);