Builder
Embed: design here, pay at your checkout
The shopper designs the card inside your own page. You take the payment in your own checkout. Then your server orders the card from us. Snapshot's checkout is not used at all.
How it works
- Your server starts a builder session with a secret key (Start a builder session). It names the template, the origin of the page that will show the frame, and any details you already know, such as the player’s name. It gets back a token that works for 60 minutes and makes one design.
- Your page opens our frame with the token. The shopper ticks that they may use their photo and adds it. They fill in the template’s details and see the card as it will print.
- The shopper presses “Use this design”. We save the card as a design on your account. The frame hands your page the design id and a preview picture. The token is then used up.
- Your store puts the design id on its cart line, and the shopper pays you in your checkout.
- Your server orders the design with Place an order, naming the design id. The order is charged to your account’s saved card and printed like any other partner order (Orders through the API).
Before you start
- A secret key for your server, and a publishable key that names your page’s origin. Make both on the Developers page of the partner portal. Both must be test keys, or both live keys (API keys). The frame shows only on an origin that one of your publishable keys names, in the same mode.
- A template the design frame offers. Your account’s templates are on the Templates page (Templates for your account). The portal’s Embed page lists the ones the design frame can use, and writes the session request with the template’s id. It leaves out a template when:
- It is a limited slab drop, sold only as a Slab from the builder.
- The template is switched off in Snapshot's template list.
- It is drawn with AI art, which the design frame does not make.
- The template has no design to build on.
- A live order is charged to the account’s saved card, so an owner saves one on the Billing page (Billing).
- Build with test keys first. A test key’s session saves a real design. A test key’s order for that design is priced, but never charged or printed (Test mode).
Start a session from your server
curl -X POST -H "Authorization: Bearer sn_live_sk_…" -H "Content-Type: application/json" \
-d '{"template_id":"<template id>","origin":"https://shop.example.com","fields":[{"key":"playerName","value":"Ada Lovelace"}],"reference":"CART-8812-1"}' \
https://partners.makesnapshots.com/api/v1/builder_sessionsoriginis the exact origin of the page that shows the frame: the scheme, the host, and the port if there is one. Only a page on that origin can show the frame, and the frame hands the design only to that origin.fieldsare values the shopper sees already filled in, up to 30. Name each one by the template’s own field name. The shopper can change them. A key that is not one of the template’s fields is refused, and the error names it.referenceis your own value, up to 48 characters. The frame hands it back with the design, and the portal names the design by it.- The answer is
201with thetoken, itsexpires_atand a readyframe_url. The token appears only in that answer. We keep only a fingerprint of it. Give it to that one shopper’s page and no one else.
Open the frame in your page
Use the embed line, and put the token your server got into data-session:
<script src="https://www.makesnapshots.com/embed.js" data-mode="design" data-session="<%= token %>" async></script>
<script>
document.addEventListener('snapshot:design', function (event) {
var design = event.detail // { designId, previewUrl, reference }
// Put design.designId on the cart line, and show design.previewUrl in the cart.
})
</script>- The frame fills the full width of the place you put it. It starts 900 pixels tall.
data-heightsets another starting height, from 360 to 1600. - With the embed line, the frame then grows or shrinks to fit what it shows, within those same limits. The frame sends a
snapshot:resizemessage with its height for this. - Under the frame, the line adds a “Cards by Snapshot” link to our site, outside the frame. You may remove it. For a white-label account, the line removes it for you.
- A token of the wrong shape draws nothing and writes one warning in the browser’s console.
- If the frame finds that its session has expired or its design is already saved, the line fires a
snapshot:expiredevent on its element, with the reason inevent.detail.reason. Your server can then start a new session.
Or make the frame yourself with the session’s frame_url, and listen for the design message:
<iframe src="https://www.makesnapshots.com/embed/s/<%= token %>" title="Design your card" style="width:100%;height:900px;border:0"></iframe>
<script>
window.addEventListener('message', function (event) {
if (event.origin !== 'https://www.makesnapshots.com') return
if (!event.data || event.data.type !== 'snapshot:design') return
// event.data.designId, event.data.previewUrl, event.data.reference
})
</script>If your page sends a Content-Security-Policy, allow it to show frames from https://www.makesnapshots.com and load the embed line from it. Also allow data: images, because the preview is one.
Receive the design
When the shopper saves the card, the frame posts one message to your page, and only to your session’s origin: { type: 'snapshot:design', designId, previewUrl, reference }.
The embed line checks that the message came from its own frame and from our site. Then it fires the snapshot:design event on its element, with the same values in event.detail. The event bubbles up to the document.
designIdis the design’s id, the one an order line names. You can read the design with Retrieve a design.previewUrlis adata:URL of the front, 360 by 504 pixels, with the word PREVIEW drawn across it. Show it in your cart. The print files never carry the word, and they never reach your page.- Treat the message as a hint. The order is the real check: your server can order only a design id from your own account. An order that names another account’s design is refused.
Order the design from your server
Once the shopper has paid you, place the order with the design id (Place an order). Send an Idempotency-Key header so a retry never orders twice. This is the whole server side, start to finish:
// Node 18 or later, on YOUR server. The secret key never reaches a browser.
const SNAPSHOT = 'https://partners.makesnapshots.com/api/v1'
const headers = { Authorization: `Bearer ${process.env.SNAPSHOT_SECRET_KEY}`, 'Content-Type': 'application/json' }
// 1. When a shopper opens your design page: one session for them.
export async function startDesign(cartLineId) {
const res = await fetch(`${SNAPSHOT}/builder_sessions`, {
method: 'POST',
headers,
body: JSON.stringify({
template_id: process.env.SNAPSHOT_TEMPLATE_ID,
origin: 'https://shop.example.com',
reference: cartLineId,
}),
})
if (!res.ok) throw new Error((await res.json()).error.code)
const session = await res.json()
return session.token // write it into the page, in data-session
}
// 5. Once the shopper has paid YOU: order the design they saved.
export async function orderDesign(order) {
const res = await fetch(`${SNAPSHOT}/orders`, {
method: 'POST',
headers: { ...headers, 'Idempotency-Key': `order-${order.id}` },
body: JSON.stringify({
partner_reference: order.id,
ship_to: order.shipTo, // name, street1, city, state, zip, phone
lines: [{ design_id: order.designId, finish: 'standard', quantity: 1 }],
rights_confirmed: true,
}),
})
if (!res.ok) throw new Error((await res.json()).error.code)
return res.json() // the order, with its status
}The shopper’s photo
- The frame takes a JPEG, PNG or WebP photo up to 10 MB, after the shopper ticks “I own this photo or have permission to use it.” The photo goes straight from their browser to a private store of ours, under your account and that session. It uses an upload address made for that one photo.
- Where the template shows the player cut out on their own, we remove the photo’s background. If that does not work, the shopper can try again, change the photo, or use the photo as it is. If they use it as it is, the background prints on the card.
- The card is drawn on our server. The frame shows a preview with the word PREVIEW across it. The template’s own design files never reach the browser.
- The photo is deleted as soon as the design is saved. The design keeps the finished card, not the photo. If a session never finishes, its photo is deleted once it is 3 hours old, by a sweep that runs every hour.
The limits
| Limit | Value |
|---|---|
| A session works for | 60 minutes, and makes one design |
| Sessions one secret key may start | 200 in any 24 hours |
| Photos one session may take | 5 |
| Background removals for one photo | 2: the first and one more try |
| Previews one session may draw | 40 |
| The largest photo | 10 MB |
When a session has expired, or its design is saved, the frame shows a short message instead. Your server starts a new session for the next design. A session also stops on its next request if you revoke the secret key that started it, or take its origin off your publishable key.