Reference
Store API
Use the store API to build a custom storefront, and to manage its products, stock, delivery and orders.
Before you start
Use an API v2 key from your server. Set prices in US dollars. They are text in answers, such as "24.00". The online store guide has complete samples.
Use two keys
store:read and store:write to set up the store. Give your website another with only store:read, orders:read and orders:write.The lists of products, orders and customers use page and limit (up to 100; the default is 20).
Store
published), and what to fix (checks).Permission: store:read
Permission: store:write
| Field | Required | What it is |
|---|---|---|
settings | No | Your store's details. See the list below |
categories | No | Up to 100 |
products | No | Up to 200 |
shipping_methods | No | Up to 20 |
Switro finds existing categories and products by slug, and delivery options by name. Anything you leave out of the lists is kept.
Permission: store:write
You can set name, slug, description, contact_email, contact_phone, address, theme_color, logo, banner_image, banner_link, footer_text, terms_of_service, privacy_policy, website, x_url, instagram_url, facebook_url, telegram_url, discord_url and whatsapp_url.
Permission: store:write
published itself.Permission: store:write
Files to sell
Permission: store:write
Send it as form data, in a field called file. Add the id from the answer to a product's files.
curl https://www.switro.com/api/v2/store/files \
-H "Authorization: Bearer $SWITRO_API_KEY" \
-F "file=@guide.pdf"Permission: store:write
kind: image (public) or file (private).Permission: store:write
Give a person page_url. A tool can send the file to upload_url, as form data in a field called file. Neither needs an API key, so keep both private.
status is complete, result has the image path or the file's id.Permission: store:write
Images
Permission: store:write
Send the file as form data, in a field called image. With curl, set SWITRO_API_KEY in your terminal first:
curl https://www.switro.com/api/v2/store/images \
-H "Authorization: Bearer $SWITRO_API_KEY" \
-F "image=@mug.webp"Use the image path from the answer for a product, category, option, logo or banner. Pictures on other websites are not accepted.
Uploaded images are public
Products and stock
search, category (its slug) and status (active, hidden or archived).Permission: store:read
Permission: store:read
slug.Permission: store:write
| Field | Required | What it is |
|---|---|---|
slug | Yes | Small letters, numbers and hyphens. It identifies the product |
name | Yes | Up to 200 characters |
price | Yes | From 0.01 to 1,000,000 |
sale_price | No | Less than the price. Use 0 to end a sale |
description, details | No | Plain text, not HTML. Up to 1,000 and 20,000 characters |
kind | No | physical (the default), digital or service. Only physical products are delivered. The others never run out, unless you set track_stock to true |
files | No | A list of private file IDs, up to 20. Replaces the current files, and past customers lose any you remove. Leave it out to keep them |
delivery_note | No | Up to 5,000 characters, only for customers who have paid. Every customer sees the same note |
stock | No | How many you have, including those in open orders |
track_stock | No | Use false if it never runs out, such as a service |
image, sku | No | An uploaded image's path, and your own product code |
is_active, sort_order | No | Whether customers can see it, and its place in the list |
seo_title, seo_description | No | For search engines |
categories | No | A list of category slugs. Replaces the current list. Leave it out to keep it |
variants | No | A list of options. Replaces all the current ones. Leave it out to keep them |
variants[].options | Yes | For example, { "Size": "L" } |
variants[].price, stock, sku, image | No | Details for this option only |
Keep what you sell out of public fields
files or a delivery_note. Never put a paid link or licence in description or details, because anyone can see those.Products in answers also have:
file_countandhas_delivery_note: what customers will get. Product requests never show the files or the note.current_price: the price now. It is null if there are options, so use the price of the chosen option.available: how many can be sold. It is null if the product never runs out or has options. Each option has its own.
Permission: store:write
Permission: store:write
Permission: store:write
{
"items": [
{ "product_id": "PRODUCT_ID", "variant_id": "VARIANT_ID", "stock": 20 }
]
}Leave out variant_id if there are no options. stock includes items in open orders.
Categories and delivery
is_active.Permission: store:read
slug and name. You can also send description, image, sort_order, is_active, show_in_menu and show_products_on_homepage.Permission: store:write
Permission: store:write
is_active.Permission: store:read
name and price, which can be 0. You can also send delivery_time, description and is_active.Permission: store:write
Create an order
Permission: orders:write
| Field | Required | What it is |
|---|---|---|
idempotency_key | Yes | 8 to 100 letters, numbers, _ or -. Use a new one for each order |
items | Yes | 1 to 100 items |
items[].product_id | Yes | The product's ID |
items[].variant_id | No | Required if the product has options |
items[].quantity | Yes | A whole number, from 1 to 10,000 |
shipping_method_id | No | The delivery option's ID. Required if anything is physical |
delivery | Yes | Always needs name and email. If anything is physical, it also needs address_1, city and country_code (such as GB). You can also send phone, address_2 and state |
shown_total | No | The total the customer saw. Always send it, so the order is refused if it would now cost more |
success_url, cancel_url | No | Where the customer goes next. localhost only works on devnet |
The answer has order_id, checkout_id, url, total, currency and expires_at. Save order_id, then send the customer to url. It works for 10 minutes.
| Answer | What to do |
|---|---|
400 | Something in the request is wrong. Fix it and try again |
409 | Something has sold out, changed price or is no longer for sale. Show the message and the latest products. Do not keep trying |
Timeout or 5xx | Send the same request with the same idempotency_key |
Orders and customers
status.Permission: orders:read
paid.Permission: orders:read
Only paid: true means an order is paid
status (pending, processing, completed or cancelled) does not show if it is paid. Never deliver an order based on it.For a paid order with downloads or services, downloads_url opens what the customer bought. Otherwise, it is null. It works for 30 days after payment, and stops if the order is cancelled or refunded. Switro also emails it to them.
downloads_url is private
status, shipping_company, tracking_number or cancellation_reason. Cancelling cannot be undone, and does not refund the customer.Permission: orders:write
Permission: customers:read