Emergency

In urgent situations or outages, you can send a text message to our emergency line

Emergency line (text message only)

+45 29 70 15 95

Send a text message with the following information:

  • Your name and webshop
  • A description of the problem

Note: This service is only for critical situations where your webshop is down or has serious problems. For regular support, please use our normal support channels.

Build a custom storefront on the Shoporama headless API

Developer guide to building your own storefront on the store's /api with products, Page designer pages, cart, discount codes, checkout, payment, and customer accounts. The full reference is at shoporama.dk/headless.

Reading time: about 48 minutes
Developer

Every Shoporama store has a headless storefront API that you can build your own custom storefront on: products, pages from the Page designer, cart, discount codes, checkout, payment, and customer accounts. The API uses the store's own engine, so the store's rules for prices, stock, shipping, and payment apply all the way through. This guide walks through the flow from the first page view to the receipt, along with the pitfalls you need to know about. All endpoints and fields are listed in the headless API reference.

Headless API or REST API?

Shoporama has two APIs, and each one solves a different task.

  • The headless API lives at the store's own address, https://din-shop.dk/api. It requires no key and works with the customer's own permissions, exactly as when the customer shops in the store. Cart, checkout, and login follow the customer's cookies. This is the API for a storefront.
  • The REST API uses an API key from Integrations → API access or OAuth and can create and edit products, orders, customers, and much more. It is meant for integrations and your own systems, and the key must never be exposed in a browser. Read more in REST API and OAuth.

If you send a REST key to the headless API, it is ignored. Headless means that the store's look and feel is separated from the part that keeps track of products, carts, and orders. See headless commerce and REST API in the glossary.

Before you start: domain, cookies, and countries

Cart, checkout, and login only work when your storefront runs on the store's primary domain (or a country's own domain) and calls the API on the same domain. The primary domain is shown under Webshop → Domain.

  • The cart, the address, and the customer's login are stored in cookies (the session, basket, and customer_token), just like in the store. So call the API from the browser with credentials: 'include'. See Which cookies does Shoporama set?
  • The API only allows calls with cookies from the store's own domains. For all other domains, the API responds with Access-Control-Allow-Credentials: false, so the browser rejects a call with cookies.
  • Catalog and content (products, categories, search, pages, and menus) can be fetched from any domain. Make those calls without credentials: 'include'.
  • There is no token access to the cart. The API finds the cart from the customer's cookies, not from a header or a token in the URL. The token field in the cart response cannot be used to fetch the cart in another call.
  • The domains under "Multiple domains" forward all requests to the primary domain, including calls to /api. So run the storefront on the primary domain and not, for example, on the www version if that is not the primary one.
  • After payment, the customer always returns to the store's own /thanks on the store's (or the country's) address. This cannot be changed per call.

The simplest approach is therefore to build the storefront as a theme, like Washington. A theme consists of Smarty templates, see Themes: create and edit your own theme templates. In addition to the app itself, the theme needs the templates for the payment page (payment.html), the receipt (thanks.html), the customer pages (user-...html), and the withdrawal form, where customers cancel a purchase (withdrawal.html). That way, every page runs on the store's domain, including the payment page, the receipt, the customer pages, and the withdrawal form. If the store needs its own domain, see Connect your own domain to your store.

If the store sells in several countries, use the country's address, for example https://din-shop.dk/en/api or /api on the country's own domain. Language, currency, prices, delivery countries, and payment methods then follow the country. Use the same address throughout the session, otherwise the language and currency change along the way. For resolve, send the path without the country prefix, for example /en/api/resolve/coffee and not /en/api/resolve/en/coffee. The URLs in the menus include the prefix. See Sell in multiple countries and languages and Prepare your theme for multiple languages and countries.

Response format and error codes

All responses have the same shape. A successful call has its data in data. An error has the HTTP status code, a message, and a reason in error.details.reason:

{ "success": true, "data": { ... } }

{
  "success": false,
  "error": {
    "code": 400,
    "message": "Payment method not selected",
    "details": { "reason": "payment_missing" }
  }
}

Every error has a reason. Use it for your own messages to the customer, not message, which may be in Danish or English. The ones you typically need to handle:

  • Cart: requires_variant, sold_out, stock (with available, the quantity in stock), product_not_found, product_unavailable, not_added, customer_input (with attribute_errors for fields the customer fills in), amount_missing, and amount_invalid.
  • Discount codes: voucher_missing, voucher_not_found, and voucher_expired. The cart is in details.basket.
  • Points: points_invalid (with available, the number of points the cart allows) and loyalty_inactive. Without login, points return login_required.
  • Delivery and payment: shipping_invalid, payment_missing, and payment_not_available.
  • Completing the order: empty_basket, stock, basket_unavailable, min_order_value (with the amount excl. VAT), delivery_country, address_missing, blocked, order_in_progress, order_failed, and payment_link_failed.
  • Customer account and orders: login_missing, login_failed, login_required, order_not_found, and order_verification.
  • General: errors without a more specific reason get one based on the status code, for example not_found, bad_request, method_not_allowed, request_too_large, rate_limited, and internal_error. A server error never shows an internal error message.

The API has a limit of 300 calls per minute per session. After that, it responds with HTTP 429 and rate_limited until the next minute begins. The store also has a per-IP-address limit for all requests, including those without cookies. If that limit is exceeded, the IP address is blocked for one hour with HTTP 429 as plain text, not JSON.

The API has no version in the URL. New fields may be added, so write your code to ignore fields it does not recognize.

Fetch products, categories, and search

  • GET /api/products returns the products that are online and whose brand the customer is allowed to see. Use limit (at most 250, otherwise the store's page size), offset, and category_id. The response has pagination with the total and the number of pages. ?gtin= looks up a barcode.
  • GET /api/products/{id} returns a single product. You can also use the product's rewrite_url instead of the ID.
  • GET /api/frontpage returns the products in the store's front page category.
  • GET /api/categories returns the store's online categories, and GET /api/categories/{id} returns a single category.
  • GET /api/search?q= uses the same search as the store and returns at most 250 products.

A product has, among other things, price (incl. VAT), old_price, buyable, images in five formats (original, large, medium, small, and thumbnail), attributes, variants, and meta with title and description. If the product has a deposit (such as a bottle deposit), it is in deposit with the name and the amount per item incl. VAT, otherwise the field is null. Names and texts follow the country's language.

variants only contains the product variants that can be bought. Each variant has attributes as attribute ID → value ID, and you send that object along when the product is added to the cart. A variant's price is null when the variant does not have its own price. Fields the customer fills in (for example an engraving text) are in attributes with input_mode: "customer".

Pages and URLs with resolve

With GET /api/resolve/{path}, your storefront can use the store's own URLs. You send the path the customer opened and find out what it is. The front page is GET /api/resolve/. The type field is one of these:

  • home: the front page. Fetch the products with /api/frontpage.
  • category and landing: the category or the landing page with products and pagination, which is null when there is only one page. The first page is ?p=0, the next is ?p=1, and the page size is the store's (on landing pages, the landing page's own).
  • product, page, and blog: the product, the static page, or the blog post. blog_list is the blog overview at /blog.
  • redirect: one of the store's redirects from Webshop → Redirects. Send the customer on to data.url so old links keep working.
  • not_found: the page does not exist. The response comes with HTTP 200, so your storefront must show a 404 page itself and respond with status 404 if it renders on the server.

The response also has blocks with the Page designer blocks for the page as ready-made HTML, split into top and bottom. The HTML is rendered with the templates of the store's active theme and uses its CSS classes. The field is null when the page has no blocks or the theme does not support the Page designer, and on categories and landing pages, the blocks are only included on the first page. If you already have the blocks from the server, add ?blocks=0. Read about the blocks in the article Page designer.

Build the navigation from GET /api/menus so the store owner can manage it under Content → Menus. Each menu has a location: top, bottom, left, or right, which correspond to Top, Bottom, Left side, and Right side in the "Menu Location" field. Only menus with a location are included, and if no menu has the location Top, you get the store's first menu as top. An item with type: "menu" is a heading for a submenu without a URL, and external tells you whether the link goes to another domain. See Menus and navigation.

Cart and discount codes

  • POST /api/basket with product_id, amount (1-100), and attributes adds a product to the cart and responds with the entire cart. The first call creates the cart and sets the cookie.
  • PUT /api/basket/{line_id} with amount (0 or more) changes the quantity, and 0 removes the line. DELETE /api/basket/{line_id} removes it.
  • POST /api/voucher/apply with code applies a discount code or a gift card, and POST /api/voucher/remove removes the code. The response has discount and the updated cart in basket.

Always use the line's line_id from the cart when you change or remove a line, for example 232156:4301+33385 for a variant. Treat it as a string you do not build yourself, and pass it through encodeURIComponent(). A plain product ID hits the first line with that product, and that may be the wrong variant. A line that does not exist returns the cart unchanged and no error.

Display the amounts exactly as the API returns them, and do not add up the lines yourself. The amounts are the store's own calculation with campaigns, discount code, quantity discounts, shipping, and the country's currency, and subtotal is the products after the discounts have been deducted. If the cart contains deposits, deposits and deposit_total are included. Deposits are included in total and vat but not in subtotal, so show a deposit line, otherwise the numbers will not add up. Before the shipping step, shipping is the store's default shipping, and shipping_chosen is false. If the cart has a campaign or a discount code, campaign and voucher are included, and the discount in them has already been deducted in subtotal.

A discount code that does not exist or cannot be used also removes a code that was already on the cart. A valid code can give discount: 0, for example when it only applies above a certain amount. It stays on the cart and gives a discount once the cart meets the condition. See Create a discount code.

Pay with points. If the store has a loyalty program, the cart has the points field: balance is the customer's balance, available is the number of points the cart allows under the store's rules, used and discount are the points used and their value, earns is the points the order earns, and rate is, for example, 10 points = DKK 1. For a guest, balance and available are null. POST /api/points/apply with points applies points to the order and requires login, and POST /api/points/remove removes them again. Too many points give 400 points_invalid and also remove the points that were already on the cart. A discount code can only be combined with points if the code allows it, otherwise available is 0.

The points discount is deducted from total and vat, so show it as a separate line. Before the order is created, the points are capped again at what the cart allows, and the order deducts them from the customer's balance. Points are earned on the order as in the store's own themes, when the order is approved or shipped. On the order, the points used are in points.used, the discount is in totals.point_discount, and points.earned is the points the order has earned so far.

Checkout step by step

GET /api/checkout returns the cart, the shipping methods, the payment methods, and the countries in one call, plus the addresses the customer has already filled in. Only the methods the customer can actually choose are included. The checkout itself is POST /api/checkout with a step:

  1. address: email, phone, name, address, zipcode, city, country_id, and optionally company fields, a comment, newsletter, and a different delivery address with the delivery_ fields. The response has missing_fields and delivers_to_country, so you can show errors right away. The order is only rejected when it is completed. A country_id that is not one of the store's countries gives no error, but the store's default country.
  2. shipping: shipping_id and, for parcel shop methods, delivery_shop_id (the parcel shop's number from delivery_shops). A method that is not on the list is rejected. If you do not send a parcel shop, the store chooses the first one on the list, just like the store's own checkout does.
  3. payment: payment_gateway_id. Only methods that are online and allowed in the customer's country.
  4. complete: completes the order, see the next section. You can also call POST /api/checkout/complete.

This is where most errors happen:

  • Always send step, and send the full address every time. The address step replaces all fields with what you send, including those you leave out, and a call without step is treated as the address step. If the customer is logged in, checkout always uses the account's address, and the address step only saves a new address to the account when missing_fields is empty.
  • Fetch checkout again after the address. Parcel shops are looked up from the delivery address and the postal code, and payment methods are filtered by the billing country. Before the address step, delivery_shops is empty for a guest, and for a logged-in customer the list matches the account's address. If the list is still empty afterward because the carrier's lookup fails, the method can be chosen without a parcel shop.
  • Do not skip the shipping step. Without it, the store's default shipping and the first parcel shop are used, not what the customer would have chosen. If the customer changes the delivery country in the address step, the chosen shipping and parcel shop are reset, so the customer has to choose again.
  • The types are not the same. shipping_methods[].id and the cart's product_id are strings, while payment_methods[].id and the product's id are numbers. The cart's shipping_id, on the other hand, is a number, so compare with String().
  • Terms and consent are your responsibility. The API does not check that the customer has accepted the terms and conditions. Fetch them with GET /api/settings (terms), and show them in your checkout. Products with withdrawal_exempt_reason: "digital_content" require the customer's explicit consent, which your checkout must also obtain itself.

Payment and receipt

Send step: "complete" with payment_flow: "storefront". The payment method is the one from the payment step, but you can also send it as payment_id. Before the order is created, the API checks the same things as the store's own checkout: stock, minimum order value, delivery country, address, shipping, and payment method. There are two kinds of responses:

  • Payment: payment_redirect: true and payment_url. With the storefront flow, this is the store's own payment page /payment, which forwards to the payment window. It works with all of the store's payment methods, and a free order goes the same way. The payment page uses the theme's payment.html template, so if you build your own theme, it must include that template.
  • The order is created: for payment methods without online payment, such as bank transfer and invoice. The response has redirect to the receipt, webshop_order_id (the order number the customer sees), chk, and payment_info with the store's text for the method, for example the account number.

Both URLs point to the store's domain, so send the customer on with payment_url or redirect. Without payment_flow, the API returns the payment window's URL directly for QuickPay, OnPay, Pensopay, Flatpay, Stripe, Mollie, and Nets Easy, while other methods still go through /payment. If the payment window cannot be started in that flow, the API responds with 502 and payment_link_failed, and no order is created. See How to accept online payments and payment window in the glossary.

If the store has turned off "Keep the cart open until the order has been paid" under Webshop → Orders and Invoices, the storefront flow creates the order before payment, just like the store's own checkout. In that case, payment_url is the order's payment page, and the order number is included in the response. See Open cart vs. closed cart: what is the difference?

A double click does not create two orders. If the cart has already become an order, a new complete returns the same response as the first time. If a call arrives while the order is being created, it waits up to about 6 seconds and then gets the same response. Only if the order is not ready by then does the API respond with 409 and order_in_progress. Still, lock the button while the call is running. For card payments with an open cart, the order is only created after payment, so a new complete just returns a new link.

The receipt. After payment, the customer lands on the store's /thanks with basket_id or order_id and chk in the URL. The page finds the order itself and passes it to the theme's thanks.html template, which Washington uses. If you want to fetch the order in your app, use GET /api/order with the same parameters. With demo payments and PayPal, the customer's email is in email instead of chk, so use the template there. chk is an MD5 hash of the order's email, so the order is only shown together with the correct email. The response has the prices the customer paid, and order_id is the order number here. If the order has a deposit, the amount is in totals.deposit. Unlike the cart, the deposit is already included in subtotal here, and the deposit lines are not in products. If the customer reaches the receipt before the payment provider has reported the payment, paid may be false for a moment. That does not mean the payment failed.

A complete purchase in one example

The example runs on the store's own domain. It adds a product to the cart, fills in the address, chooses delivery and payment, completes the order with the storefront flow, and sends the customer on. In a real storefront, the customer chooses the variant, shipping, parcel shop, and payment method.

// Runs on the store's own domain. In a country with its own path: '/en/api'
const API = '/api';

async function api(path, body) {
  const res = await fetch(API + path, {
    method: body ? 'POST' : 'GET',
    credentials: 'include',
    headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
    body: body ? JSON.stringify(body) : undefined
  });
  const text = await res.text();
  let json = null;
  try { json = JSON.parse(text); } catch (e) {}
  if (json && json.success) return json.data;
  const error = new Error(json ? json.error.message : 'HTTP ' + res.status);
  error.status = res.status;
  error.reason = json ? json.error.details?.reason : 'no_json';
  error.details = json ? json.error.details : null;
  throw error;
}

async function buy(productId) {
  // 1. The product and a variant that can be bought
  const product = await api('/products/' + productId);
  const variant = product.variants[0];
  await api('/basket', { product_id: product.id, amount: 1, attributes: variant ? variant.attributes : {} });
  // 2. The address. The country ID is the store's own, so look it up
  const { countries } = await api('/countries');
  const denmark = countries.find(function (c) { return c.code === 'DK'; });
  const address = await api('/checkout', {
    step: 'address', email: 'customer@example.com', phone: '12345678', name: 'Karen Holm',
    address: 'Vestergade 12', zipcode: '8000', city: 'Aarhus C', country_id: denmark.id, newsletter: 0
  });
  if (address.missing_fields.length || !address.delivers_to_country) return address;
  // 3. Fetch shipping and payment again AFTER the address (parcel shops for the postal code)
  const checkout = await api('/checkout');
  const shipping = checkout.shipping_methods[0];
  const shippingStep = { step: 'shipping', shipping_id: shipping.id };
  if (shipping.delivery_shops.length) shippingStep.delivery_shop_id = shipping.delivery_shops[0].number;
  await api('/checkout', shippingStep);
  // 4. The payment method
  await api('/checkout', { step: 'payment', payment_gateway_id: checkout.payment_methods[0].id });
  // 5. Complete the order. Lock the button while the call is running
  const result = await api('/checkout', { step: 'complete', payment_flow: 'storefront' });
  // Payment: the store's /payment. Bank transfer and invoice: the receipt
  window.location.href = result.payment_url || result.redirect;
}

If something goes wrong, api() throws an error with reason, so you can send the customer back to the right step: shipping_invalid to delivery, address_missing and delivery_country to the address, payment_missing and payment_not_available to payment, and stock, basket_unavailable, or min_order_value to the cart. On order_in_progress, wait a moment and call complete again.

Customer account and login

  • POST /api/auth with email and password logs the customer in and sets the same cookie as the store's own login. This means the customer is logged in to both your storefront and the store. A wrong login returns 401 and login_failed.
  • POST /api/auth/logout logs the customer out.
  • GET /api/customer returns the logged-in customer with name, address, customer group, points balance (points), and links to the customer pages, or customer: null.
  • GET /api/orders returns the customer's orders, and GET /api/orders/{order_number} returns a single order with the same fields as /api/order. Without login, they respond with 401 and login_required.

When logged in, the customer gets their customer group prices, their address filled in, and the payment methods that are only for logged-in customers. These are methods with "Automatically mark new orders as paid?", such as invoice for business customers. The address step saves a complete address to the customer's account, and a logged-in customer always shops with the account's email, even if you send a different one in the address step. See Customer groups and B2B prices.

Creating an account, resetting a forgotten password, and editing account details are not available in the API. Instead, link to the store's own pages /user-sign-up, /user-reset-password, and /user-edit. That way, the customer gets the spam check, the welcome email, points for signing up, and VAT number validation, as in the rest of the store. If you build a theme, those pages must exist as templates. Washington has them.

Washington as an example

Washington is one of Shoporama's themes, and it is built entirely on the headless API. The whole store is a single JavaScript program without frameworks, and the theme is a good starting point if you want to build your own storefront as a theme. You can download it from the Washington theme page, and the setup for the store owner is described in The Washington theme. You upload the theme files under Design → SFTP access or edit them under Design → Code editor. See Log in with SFTP and The code editor.

Washington also shows what a custom storefront has to take care of itself:

  • SEO: Washington renders the first page view on the server with the Page designer blocks, title, meta description, canonical, Open Graph, and product data (JSON-LD). Product lists and product pages are built in the browser. See Add structured data to your Shoporama theme and JSON-LD in the glossary.
  • Tracking: Washington sends the GA4 events (for example view_item, add_to_cart, begin_checkout, and purchase) to the dataLayer, and on every page change it sends virtual_page_view with page_location, page_path, and page_title. If your storefront needs to measure page views and purchases, it has to send them itself. See Implement ecommerce tracking in a Shoporama theme and dataLayer in the glossary.
  • Scripts from the store: In Washington, apps and custom scripts from the store's HTML fields only run on the first page load, because the page does not reload when the visitor moves to another page. The same applies to your own app if it changes pages the same way.
  • The store's own pages: Washington has templates for the payment page, the receipt, the customer pages, and the withdrawal form (/withdrawal), so they run on the store's domain with the same design.

Frequently asked questions

Do I need an API key to get started?

No. Open https://din-shop.dk/api/products?limit=5 in your browser, and you will see the store's products. The API can only do the same things as a customer in the store: view online products and pages and work with their own cart, account, and orders. It cannot change products, prices, or other customers' orders, and payment methods that mark the order as paid are only offered to logged-in customers. For everything else, use the REST API with a key.

Can the storefront be hosted on a different domain than the store, for example on Vercel?

Only for catalog and content. Cart, checkout, and login require the customer's cookies, and the browser only sends them when the page is served from the store's primary domain (Webshop → Domain) and calls the API on the same domain. If you route the calls through your own server, the session lives on your server and not with the customer, and then the store's payment page cannot find the cart. Payment and the receipt at /thanks always take place on the store's domain. The safe solution is to build the storefront as a theme.

Does the limit of 300 calls per minute apply when my server renders the pages?

There are two limits. The API's own limit of 300 calls per minute is counted per session (the session cookie) and per IP address, so calls without cookies get a new session each time and do not affect the customer's limit. The store's per-IP-address limit, on the other hand, counts all requests from your server, with and without cookies, and a server that fetches many pages can hit it. If it does, the server's IP address is blocked for one hour. So cache catalog and content on your server instead of fetching them on every page view, send a User-Agent, and let cart and checkout run from the customer's browser.

Can I route based on the store's URLs and use the Page designer blocks in my own components?

Yes. Send the path to /api/resolve, and you get the type, including redirect for the store's redirects. The blocks are plain HTML that you can insert into a component, but they are rendered with the store's active theme and use its CSS classes, so you need to include the theme's CSS or style the classes yourself. The images in the blocks have relative URLs (/cache/...), while the links are absolute URLs (https://din-shop.dk/...), so intercept the links yourself if your app changes pages without reloading. Scripts in the blocks do not run when the HTML is inserted with innerHTML. If the active theme does not support the Page designer, blocks is always null.

Can a double click on "Complete purchase" create two orders or an unpaid order?

Not two orders. A new complete for the same cart returns the same response as the first and creates no new order. An unpaid order only occurs with payment methods without online payment, such as bank transfer and invoice, and when the store uses a closed cart, just like in the store's own checkout. If the payment window cannot be started, no order is created. Still, lock the button while the call is running.

Can I test the whole purchase without creating real orders?

All calls before complete only change the cart and the session (and the customer's account if you are logged in), so you can run them as often as you like. It is complete that creates the order, and the order goes through the store's normal flow with order confirmation, webhooks, and accounting software, if any. So test with a payment method without online payment, such as bank transfer, and your own email, and afterward delete the test order with Delete Order on the order under Orders. If the store is still in demo mode, the payment page runs in test mode, so you can also try paying by card.

Will the store lose Google rankings with a custom storefront?

That depends on the storefront. Through resolve, the API gives you the store's own URLs and redirects, and it provides the title and description in meta on products, categories, and pages, so you can keep the same URLs and texts. But it is your storefront that has to set the title, meta description, canonical, and structured data in the HTML, preferably already on the server, as Washington does. Agree on this with whoever builds the storefront.

Can I still use my payment methods, parcel shops, discount codes, points, and customer accounts?

Yes. The storefront flow works with all of the store's payment methods, parcel shops are chosen in the shipping step, discount codes and gift cards are applied with /api/voucher/apply, and customers log in with their existing login. Customers can also pay with points from the loyalty program with /api/points/apply. The API does not support subscriptions, wish lists, product filters, reviews, add-ons, or file uploads in customer fields.

How do I get the order into my own system?

The headless API only shows customers their own orders. Instead, create a webhook under Integrations → Webhooks, for example on the order_created and paid events, and the store will call your server. If your system needs to fetch or edit orders, use the REST API from your server. See Webhooks and webhook in the glossary.

You can find all endpoints, fields, and example responses in the headless API reference. If you have questions, write to support@shoporama.dk.