# Reflow API

Reflow has a simple public API that lets you fetch your store's products as JSON. It can be used both in the browser (from any origin), and in scripts when building static versions of your store with site generators or Next.js.

# Get all Products

https://api.reflowhq.com/v1/stores/<storeid>/products/

This endpoint will return the latest 20 products in your store. You can modify its behavior with query parameters (all are optional):

Parameter Possible Values Description
page number, defaults to 1 If set, will return the corresponding page number of products.
perpage number, min 1, max 100, defaults to 20 How many products to return per page.
category number, the id of the category If set, only returns products from the given category.
order name_asc, name_desc, price_asc, price_desc, date_asc, date_desc, custom_asc, custom_desc Choose the display order of the products. Defaults to date_desc - products will be shown newest to oldest.

You can also perform multiple sorts by separating order clauses with commas:

Example: ?order=custom_desc,name_asc

This sorts products by using the Custom Sort number (which you enter in the product edit page), and then by name from A to Z. The result is that products with Custom Sort > 0 show before the rest.

# Examples

// Print the 20 newest products
let products = await fetch('https://api.reflowhq.com/v1/stores/267418190/products/').then(r => r.json());
console.log(products.data);

// Print the 10 oldest products
let products = await fetch('https://api.reflowhq.com/v1/stores/267418190/products/?order=date_asc&perpage=10').then(r => r.json());
console.log(products.data);

// Print all the products from a category
let products = await fetch('https://api.reflowhq.com/v1/stores/267418190/products/?category=123456789').then(r => r.json());
console.log(products.data);

# Get a Specific Product

https://api.reflowhq.com/v1/stores/<storeid>/products/<productid>

This endpoint will return the product with the given id from a store.

# Examples

// Fetch the given product and print its name
let product = await fetch('https://api.reflowhq.com/v1/stores/267418190/products/366797633').then(r => r.json());
console.log(product.name);

# Get all Categories

https://api.reflowhq.com/v1/stores/<storeid>/categories/

This endpoint will return the id, name, and subcategories of all categories in your store, ordered alphabetically and nested recursively. To get the products associated with a specific category, we recommend using the category parameter of the Get all products endpoint.

# Examples


// 1. Fetch all categories and print their names
let categories = await fetch('https://api.reflowhq.com/v1/stores/267418190/categories').then(r => r.json());
console.log(categories.map(c => c.name));

// 2. If your store has subcategories, a bit more work is needed
let printCategoryNames = (categories) => {
  for (let c of categories) {
    console.log(c.name);
    printCategoryNames(c.subcategories);
  }
};

// 2.1 Fetch all categories and print their names recursively
let categories = await fetch('https://api.reflowhq.com/v1/stores/267418190/categories').then(r => r.json());
printCategoryNames(categories);

// 2.2 Fetch only a specific category and its subcategories, and print their names
let categories = await fetch('https://api.reflowhq.com/v1/stores/267418190/categories?root-category=177837305').then(r => r.json());
printCategoryNames(categories);

# Usage with the Reflow Library

If you have the Reflow JS file included in a web page, you can use a convenience wrapper that gives you direct access to the API, without having to pass the full API URL and store id:

// Fetch a product and print its name using the Reflow library.
// https://cdn.reflowhq.com/v1/toolkit.min.js has been included in the page.
let product = await Reflow.api('/products/366797633');
console.log(product.name);

// Print the 20 newest products
let product = await Reflow.api('/products/');
console.log(product.data);

This way you can retrieve your product data and build entirely custom store experiences, but still add an Add to Cart button and a Shopping Cart so that the Reflow toolkit does the heavy lifting.