Kastomise · For developers
Send shoppers back to your own cart with their code
For a Kastomise Hosted shop that sells on its own website and has a developer. Shoppers design on the shop’s hosted page and save it as a design code; this page shows how your store can take that code into its own cart, check it, and record the order on the design.
Before you start
A shopper saves their design on the hosted page and gets a code such as KD-7F3K9Q2M. Your store takes it from there in up to three steps. Each builds on the one before, and you can stop after any of them:
- Fill in the code. The hosted page’s button sends the shopper back to your product with the code in the address, and your page puts it in the Design code box.
- Check it on your server. Before the product goes in the cart, ask the API for the design. Refuse a code that doesn’t exist, is another shop’s or is already on an order, and check the product, its options and the price.
- Mark it ordered. Once the order is paid, record its number on the design, so the shop sees it as Ordered and the design is kept.
Steps 2 and 3 use the API with a key that a shop admin makes in Settings → API keys: Read designs (designs:read) for step 2, Update design status (designs:write-status) for step 3, and Download print files (files:read) to show the design’s preview. A new key for a Kastomise Hosted shop starts with Read designs and Download print files ticked: tick Update design status too for step 3. Every endpoint is in the API reference.
1. Fill in the code
In the product setup’s Kastomise Hosted tab, the After a shopper saves card has a Button link. Put {code} in its path, its query or after a #, such as https://yourshop.com/products/photo-mug?design={code}. When the shopper clicks the button, the hosted page puts their code in its place and opens the link in the same tab. A link without {code} opens in a new tab instead, and an email or phone link can’t carry the code.
Your product page then reads the code from its address and fills in the box:
// On your product page: fill the Design code box from ?design=…
const DESIGN_CODE = /^KD-[23456789ABCDEFGHJKMNPQRSTUVWXYZ]{8}$/;
// As the dashboard reads a typed code: any case, spaces dropped, KD- optional.
function readDesignCode(raw) {
const code = String(raw).toUpperCase().replace(/\s/g, '').replace(/^KD-?/, '');
return code ? 'KD-' + code : '';
}
const fromLink = readDesignCode(new URLSearchParams(location.search).get('design') ?? '');
const box = document.querySelector('input[name="design_code"]'); // your field
if (box && !box.value && DESIGN_CODE.test(fromLink)) box.value = fromLink;A code is KD- and 8 of 23456789ABCDEFGHJKMNPQRSTUVWXYZ: no 0, O, 1, I or L. Fill the box where the shopper can see it, and let them change or remove the code: anyone can send a link with a code in it. The shopper has left the hosted page by now, so your page is where they see their code.
On its own, this step only saves the shopper a paste: the shop still checks each order against its design in the dashboard. Step 2 does that check for you.
2. Check it on your server
When the shopper adds the product to their cart, and again when they place the order if your platform lets you, your server asks for the design, with Read designs (designs:read):
curl https://app.kastomise.com/api/v1/designs/KD-7F3K9Q2M \
-H "Authorization: Bearer ksk_…"
{
"code": "KD-7F3K9Q2M",
"status": "saved",
"saved_at": "2026-10-28T09:00:00.123+00:00",
"expires_at": "2027-01-26T09:00:00.123Z",
"config_slug": "framed-print",
"product": "Framed print",
"price": {"currency": "AUD", "quantity": 1, "unit_cents": 6400, "total_cents": 6400,
"lines": [{"kind": "base", "label": "Base price", "cents": 3900},
{"kind": "type", "label": "Text & pictures", "cents": 2500}]},
"choices": [{"kind": "type", "label": "Customisation", "value": "Text & pictures",
"key": "text and pictures"},
{"kind": "option", "label": "Frame colour", "value": "Beige",
"key": "beige", "field": "frame"}],
"customer": {"name": null, "email": null},
…
}| Check | Refuse the code when |
|---|---|
| The answer | It’s a 404: no design with that code in this shop. A made-up code and another shop’s code both read as 404, since a key sees only its own shop’s designs. |
status | It isn’t saved. ordered and printed are on an order already; cancelled is one the shop cancelled. |
config_slug | It isn’t this product’s. Keep a list of which product setup’s slug each of your products takes. |
choices | They don’t match the variation in the cart, or pick the variation from them. Each choice’s key, and an option’s field, are its ids in the product setup and stay the same if the shop rewords a label. On a page that sells sizes, the size is personalisation.size. |
price | price.unit_cents or price.currency isn’t your price for that variation, or price is null (see Who sets the price). |
// Your server, when a shopper adds a product with a design code.
// KASTOMISE_API_KEY is a secret: it never reaches the browser.
async function checkDesign(code, product) {
const res = await fetch('https://app.kastomise.com/api/v1/designs/' + encodeURIComponent(code), {
headers: {Authorization: 'Bearer ' + process.env.KASTOMISE_API_KEY},
});
if (res.status === 404) return {ok: false, reason: 'not_found'};
if (!res.ok) return {ok: false, reason: 'try_again'}; // 429: wait Retry-After seconds
const design = await res.json();
if (design.status !== 'saved') return {ok: false, reason: 'already_ordered'};
if (design.config_slug !== product.kastomiseSlug) return {ok: false, reason: 'other_product'};
const variant = product.variantFor(design.choices); // yours: by each choice's key and field
if (!variant) return {ok: false, reason: 'options'};
const price = design.price;
if (!price || price.currency !== variant.currency || price.unit_cents !== variant.priceCents) {
return {ok: false, reason: 'price'};
}
return {ok: true, code: design.code, variant};
}Then show the shopper what was added: the product, the code and the design’s preview, with a way to remove it. With Download print files (files:read), GET /api/v1/designs/{code}/files?kind=preview gives a preview image for each print area. Its links last about an hour, so fetch the image on your server or ask again, rather than storing a link.
Pass the browser only what it shows. A design’s answer can hold the customer’s name, email and note, when the hosted page asks for them, and anyone can type a code.
3. Mark it ordered
When your store says an order is paid (its paid-order webhook or event), mark each design code on it ordered, with Update design status (designs:write-status). Send the order’s number, where it came from, how many to make and the buyer’s name:
curl -X POST https://app.kastomise.com/api/v1/designs/KD-7F3K9Q2M/ordered \
-H "Authorization: Bearer ksk_…" \
-H "Content-Type: application/json" \
-d '{"order_reference": "#1042", "order_platform": "Own website",
"order_quantity": 2, "order_customer_name": "Ada Lovelace"}'
{
"design_id": "3c9e…",
"code": "KD-7F3K9Q2M",
"status": "ordered",
"changed": true,
"ordered_at": "2026-10-29T10:00:00.456+00:00",
"printed_at": null,
"updated_at": "2026-10-29T10:00:00.458+00:00",
"order_reference": "#1042",
"order_platform": "Own website"
}The design shows as Ordered on its page in the dashboard at once, with your order number, and is kept: a design left as Saved is deleted with its print files 90 days after it was saved. Sending the same order_reference again is a safe retry while the design is Ordered (changed is false).
| Answer | What it means |
|---|---|
409 design_already_ordered | The code is on another order already. Don’t print this one: flag the order for a person. |
409 conflict | The design changed while your request ran, such as another order marking it at the same moment. Read the design: if it holds another order’s reference, treat it as above. |
409 design_cancelled | The shop cancelled the design’s order in the dashboard, where it can be reinstated. |
404 not_found | No such design in this shop any more, such as a Saved design deleted after 90 days. |
The shop then prints as it always does, from the dashboard, or from its own system with the design’s files and POST …/printed (API reference).
Who sets the price
Shoppers see a price on the hosted page and another in your cart. Decide which one counts:
- Your store’s prices. Keep each variation’s price equal to the product setup’s (its base price, customisation type, options and extras), and refuse a design whose
price.unit_centsisn’t the variation’s. Your store stays the price list. Change a price in both places at once: a design keeps the price its page showed when it was saved. - The design’s price. Charge
price.unit_centsfor the line, if your platform lets your server set a line’s price. It isn’t the shopper’s word: Kastomise keeps a design’s price only when it matches the product setup’s prices for what was chosen and printed, andpriceisnullwhen it doesn’t.
Either way, compare the price of one, unit_cents. total_cents is that times the quantity asked for on the hosted page, which is 1 unless the page asks for a quantity.
Things to get right
- Server only, with the key kept secret. The API sends no CORS headers, and a key with
designs:readreads every design the shop has, with its customers’ names and emails. Keep the key in your server’s secrets, never in a theme, a page’s JavaScript or a tool whose settings others can see. If it leaks, revoke it in Settings → API keys: it stops working at once. - Anyone can send a link with a code in it. Show the shopper what was added and let them remove it, and check every code that arrives, however it arrives.
- Match by
config_slug. Never byproduct, the setup’s name, which the shop can rename, or byconfig_id, which is different on another shop or account. The slug is set once, when the setup is made, and never changes. It isnullonce the setup is deleted. - One code is one order. The check doesn’t hold a code: two carts can hold the same one until an order is paid. The first order to mark it wins, and the other gets a
409. Send the order reference the same way every time, such as always#1042, never sometimes1042. - Mark ordered once. On a design the shop has since marked printed,
orderedundoes the print. If your store sends the paid event again later, skip a design that is already Printed under the same order. - Rate limits. Each key can make 120 requests a minute, and a shop 300 across all its keys. Check a code when it is added and when the order is placed, not on every page view. Over the limit is a
429with aRetry-Afterheader in seconds. - Saving again makes a new code. A shopper who goes back and changes their design saves it under a new code, and the old one stays Saved until it’s deleted. Let shoppers replace the code in their cart.
- A Saved design is deleted after 90 days.
expires_atsays when. A cart kept longer finds a404, so mark each design ordered as soon as its order is paid. - The price and the choices can be missing.
priceisnullfor a design saved before prices were kept, or whose price didn’t match;choicesis[]for an older design or a page that offers none. Decide what your check does then, such as sending the order to a person.
Help with your setup
We can build your product setups, set up your Kastomise Hosted page and add the Design code box to your products on your store, as a paid service, and you get a fixed price before anything is charged. The code on your store, the three steps above, is your developer’s to write.