Developers
API keys
An API key lets your own systems use the partner API, from your server or from a page on your website. You create keys in the partner portal, under Developers.
Two kinds of key
| Kind | Starts with | Used from | Can call |
|---|---|---|---|
| Secret key | sn_test_sk_ or sn_live_sk_ | Your server | Every endpoint |
| Publishable key | sn_test_pk_ or sn_live_pk_ | A web page, on the origins the key names | Only the endpoints marked publishable: list prices and create a quote |
After its first letters, a key is 43 random letters and digits. Treat a secret key like a password. Keep it in your server’s secret settings. Never put it in code you share or in anything a browser loads.
Test and live
Every key is either a test key or a live key. Its first letters say which.
- An order placed with a live key is charged to the account’s saved card and printed.
- An order placed with a test key is checked and priced the same way. It is never charged or printed, and it moves through its statuses by itself (Test mode).
- A test key sees only test orders, events and webhook endpoints. A live key sees only live ones.
- Designs belong to the account, so test keys and live keys see the same designs.
Use test keys while you build.
Every answer has a mode field that says which mode the key is in. These answers have no mode field: Ask for upload addresses, Save a design, List designs, Retrieve a design, Archive a design, Send a test event, List granted templates. To check which key you are using, call Retrieve the account.
Creating a key
An owner or a manager creates keys on the Developers page of the partner portal. Choose the kind, the mode and a name that says what the key is for. A publishable key also needs its allowed origins.
- We show the whole key once, when you create it. We keep only a fingerprint of it (its SHA-256 hash), so we cannot show it again. Copy it then. If you lose a key, revoke it and create a new one.
- The list of keys shows each key’s name, kind and mode, its first letters (the start and 6 more), when it was created and when it was last used. Last use is updated at most once every 60 seconds. Viewers can see the list, but not the keys.
- An account can have up to 20 keys that are not revoked. It can create up to 50 keys in any 24 hours.
Sending a key
Send the key in the Authorization header of every request, as a bearer token. To check that a secret key works, read the account it belongs to:
curl -H "Authorization: Bearer sn_test_sk_…" https://partners.makesnapshots.com/api/v1/accountA request with no key, or with a value that is not a key, is refused with 401. Every answer, including a refusal, has an X-Request-Id header. Include it when you ask us about a request. The API reference lists every error.
Browsers and allowed origins
A secret key does not work from a browser. Every browser sends an Origin header. A request with a secret key and an Origin header is refused with 401 and the code secret_key_in_browser. The API checks this before it looks the key up. So a secret key pasted into a web page fails the first time it is used, and you find the mistake straight away.
A publishable key works only from its allowed origins. Each key lists between one and 10 origins. Write each one exactly as a browser sends Origin: the scheme, the host and the port if there is one, with no path. For example: https://shop.example.com. A test key may also list http://localhost:3000 (or another port), so you can build on your own computer. A request from any other origin, or with no Origin, is refused with 403 and the code origin_not_allowed.
Anyone who opens your page can read a publishable key. That is why it can do so little: list prices and create a quote, and only from its own origins. Its answers carry the CORS headers for the origin that asked. A secret key’s answers carry none.
Revoking a key
An owner or a manager revokes a key on the Developers page, and confirms it. The API checks the key on every request, so the next request made with a revoked key is refused with the code api_key_revoked. A revoked key cannot be turned back on. It stays in the list, marked revoked.
To replace a key without stopping your integration: create the new key, move your server to it, then revoke the old one.
A key belongs to the person who made it.
- The Developers page shows who made each key. An owner or a manager can revoke all the keys one person made at once.
- When that person leaves the account, is removed from it or is made a viewer, every key they made is revoked at the same time.
- If a key’s maker is no longer an owner or a manager, every request with that key is refused, reads included, with the code
key_creator_not_permitted.
So have someone who will stay in the account make the keys your integration runs on. If someone who made keys is leaving, make new keys first.
Rate limits
| Limit | Requests | In |
|---|---|---|
| Per key | 120 | 60 seconds |
| Per account, for each mode, secret keys | 300 | 60 seconds |
| Per account, for each mode, publishable keys (counted apart from secret keys) | 300 | 60 seconds |
| Per visitor address, for each account and mode, publishable keys | 60 | 60 seconds |
How requests are counted:
- Every request counts against its own key.
- A secret key’s requests also count against all of the account’s secret keys of the same mode. Test requests never use up the live allowance.
- A publishable key’s requests are counted separately: against the account’s publishable keys of the same mode, and per visitor (the address each request comes from). A busy web page cannot use up the allowance your server places orders with.
- A request over a limit gets
429with the coderate_limitedand aRetry-Afterheader: the number of seconds to wait. A refused request is not counted. - An answer to a request that passed the key check also carries
X-RateLimit-Limit,X-RateLimit-RemainingandX-RateLimit-Reset. They describe the limit closest to running out: its size, the requests left, and when it resets, in Unix seconds.
Retrying a request safely
Most POST endpoints accept an Idempotency-Key header, and Place an order requires one. Each endpoint in the API reference says which. You choose the value: 1 to 255 printable characters with no spaces (a random UUID works well). Send the same value again when you retry the same request, and the API runs it only once:
- We keep the first answer for 24 hours. The same value with the same body gets that answer again, with the header
Idempotent-Replayed: true. - The same value with a different body is refused:
409,idempotency_key_reused. Use a new value for a new request. - While the first request is still running, a second one with the same value is refused:
409,idempotency_in_progress. Retry once it has finished. - An error on our side (a
5xx) is not kept, so a retry runs the request again. - Values are separate for each account and each mode. A test request never gets the answer to a live one.