AJAX product filtering with the /ajax endpoint
Technical documentation for Shoporama's /ajax endpoint, which returns products as JSON for AJAX filtering, lazy loading, and infinite scroll. For developers and theme designers.
Every Shoporama store has a built-in /ajax endpoint that returns products as JSON. It lets you build dynamic AJAX product filtering, lazy loading, and infinite scroll without reloading the page, so customers get a fast, modern experience.
This article is mainly written for developers and anyone who builds or customizes their own theme. If you use the Delaware theme, AJAX filtering works out of the box, and you don't need to call the endpoint yourself.
How to call the endpoint
A simple call that fetches products from one or more categories:
fetch('/ajax?categories=123&limit=24')
.then(response => response.json())
.then(products => {
products.forEach(p => console.log(p.name, p.price));
});
By default, the endpoint returns a JSON array of products. If you also want metadata and pagination, add include_meta=1 and include_pagination=1. You then get an object with products, meta, and pagination instead.
Available parameters
Several parameters take pipe-separated values, so you can filter on several things at once. For example categories=12|34|56.
| Parameter | Description |
|---|---|
| categories | Category IDs, pipe-separated. With several IDs, you get products that are in at least one of the categories (OR). Add match=all to get only products that are in all the given categories (AND) |
| force_categories | Like categories, but enforces the categories without letting other filters narrow them further |
| price_range | Price range as min|max, for example 100|500 |
| attribute_values | IDs of attribute values (for example color or size), pipe-separated. Several values are matched as OR. Add match=all to require the product to have all the given values (AND), for example both a color and a size |
| attribute_tags | Filter attribute values by their tag instead of their ID, for example red|blue |
| attribute_tags_in_stock | Like attribute_tags, but only variants in stock |
| attribute_tag | Filter on a whole attribute (not a specific value) by its tag, for example only products that have the attribute "color" |
| shared_values | IDs of shared values, for example everything in Medium regardless of profile. | means or, and , means and, for example 2|3,5. See the section on shared values further down |
| shared_values_in_stock | Like shared_values, but only variants in stock with the value |
| extension.<id> | Filter on your theme's extended fields. id is the field's ID from the theme, and for fields with multiple choices, the value can be pipe-separated |
| brands | Brand IDs, pipe-separated |
| suppliers | Supplier IDs, pipe-separated |
| landing_pages | Landing page IDs, pipe-separated |
| product_ids | Specific product IDs, pipe-separated |
| atags | Filter by product tags |
| sort + sort_order | Sort the result. sort_order is asc or desc (default) |
| limit / offset | Pagination. limit can be at most 1000, and higher values are capped automatically |
| meta | A specific meta field to include on each product. Use _all for all meta fields, or pipe-separate several names |
| only_in_stock_variants | Return only variants that are in stock in the variant_stock field on each product |
| include_meta | Set to 1 to get attributes, categories, and brands in the result (useful for building a filter UI) |
| include_pagination | Set to 1 to get offset, limit, count, and total |
| include_similar | Set to 1 to include the product's similar products (for example the other colors) and the product's own attributes on each product. See the section on similar products below |
| pretty | Set to 1 for pretty-printed JSON (useful for debugging) |
| rebuild | Set to 1 to force the cache to be regenerated for that specific URL |
Filtering with AND (match=all)
When you send several categories or attribute_values, the endpoint matches with OR by default: a product is included if it matches at least one of the values. That works well for broad overviews, but for faceted filtering you often want the opposite, namely only the products that match all the selected values at once.
Add match=all to switch to AND logic. The product then has to have every single one of the given values to be included. That is exactly what you need when a customer selects both a color and a size in your filter:
// Only products that have BOTH value 401815 AND 401822
fetch('/ajax?attribute_values=401815|401822&match=all&limit=50')
.then(response => response.json())
.then(products => { /* ... */ });
match=all works on both categories and attribute_values. Without the parameter, OR is used as before.
Note: The older parameter exclude=1 does exactly the same as match=all and still works for backward compatibility. The name is misleading, because it doesn't exclude anything, so use match=all in new code.
Note: The parameters category_id, tag, extra_field[..], price_from, and price_to do not exist. Use categories, atags, extension.<id>, and price_range instead. The wrong names simply return 0 results or are ignored. You don't get an error message.
Filtering on shared values
If the store uses shared values, you can filter across profiles. A shared value such as Medium can be linked to a value in both the T-shirt profile and the pants profile, and shared_values finds products with all of them without you having to know the individual attribute value IDs. Both variants and regular attribute values in the product's current profile count.
The parameter uses the same structure as atags: | means or within a group, and , separates groups that must all match. If Medium is ID 2, Large is ID 3, and 400 bar is ID 5, shared_values=2|3,5 returns products that come in Medium or Large and also have 400 bar. An invalid ID returns no products, not the whole catalog.
// Everything in Medium or Large, across profiles
fetch('/ajax?shared_values=' + encodeURIComponent('2|3') + '&include_meta=1&limit=24')
.then(r => r.json())
.then(data => {
console.log(data.products);
console.log(data.meta.shared_values);
});
If you use shared_values_in_stock instead, only variants in stock with the value are included. For regular attribute values (not variants), the product itself must be in stock or allow negative stock. If you send both parameters, shared_values_in_stock is used.
With include_meta=1, the response also includes meta.shared_values: the shared values found on the products in the result, sorted in the same order as under Shared Values in the admin. Each entry has attribute_shared_value_id, value, num_value, weight, and attribute_value_ids (the profile values in the result that are linked to the shared value). In addition, each value in meta.attributes has the field attribute_shared_value_id, which is null for values that are not shared. This lets you build one filter option per shared value instead of one per profile value.
num_value is the number at the start of the value, for example 400 for "400 bar". The store's own filter doesn't use it, but you can use it in your theme, for example for sorting.
In your theme, you can also get the list of the store's shared values with $webshop->getSharedValues(), which returns id, value, and num_value for each one.
Example: category, price range, and color
Fetch red products between DKK 100 and 500 from two categories, sorted by price in ascending order:
const params = new URLSearchParams({
categories: '12|34',
price_range: '100|500',
attribute_tags: 'red',
sort: 'price',
sort_order: 'asc',
limit: 24
});
fetch('/ajax?' + params)
.then(r => r.json())
.then(products => renderProducts(products));
Example: filter by extended field and get metadata
Extended fields ("extension" in the parameter name) are the fields your theme adds to products in the Theme settings card. You specify them with extension. in front of the field's ID, for example extension.material. The ID is in the theme file extensions/product.json, so ask your theme developer if you don't have access to the theme files yourself. Here is an example where the field material (a field with multiple choices) must be either "cotton" or "linen":
// extension.material=cotton|linen
fetch('/ajax?categories=12&extension.material=' + encodeURIComponent('cotton|linen') + '&include_meta=1&include_pagination=1&limit=24')
.then(r => r.json())
.then(data => {
console.log(data.products);
console.log(data.meta.attributes);
console.log(data.pagination);
});
Similar products and color variants
If each color is its own product, and the colors are linked under Similar products, you can show the other colors directly on the product card, for example as small color swatches. Add include_similar=1, and each product gets two extra fields:
- similar_products: the similar products with product_id, name, url, thumbnail (200x200 fit), in_stock (true or false), and attributes. Only products that are online are included, at most 25 per product, in the order they appear on the product in the admin. The product itself is not included.
- attributes: the product's own attributes, so you also know the card's own color. Each attribute has attribute_id, attribute_name, attribute_tag, purpose, attribute_value_id, value, and value_tag.
The attributes are the ones set on the product. Variants (for example sizes) and fields the customer fills in are not included. purpose is the purpose the attribute has in the profile (for example color when Purpose is set to Color), and attribute_tag and value_tag are the tags you have given the attribute and the value. For example, add the hex code as the tag on each color value, and the theme can draw the swatch directly. A text attribute with the hex code also works. The code is then in value.
"attributes": [
{"attribute_id": 120, "attribute_name": "Color",
"attribute_tag": "color", "purpose": "color",
"attribute_value_id": 801, "value": "White",
"value_tag": "#ffffff"}
],
"similar_products": [
{
"product_id": 1043,
"name": "Original T-shirt | Black",
"url": "https://example.com/original-t-shirt-black",
"thumbnail": "https://example.com/cache/.../fit-200x200x90.png",
"in_stock": true,
"attributes": [
{"attribute_id": 120, "attribute_name": "Color",
"attribute_tag": "color", "purpose": "color",
"attribute_value_id": 802, "value": "Black",
"value_tag": "#000000"}
]
}
]
// Color swatches on the product cards: the card's own color first, then the others
const color = attributes => attributes.find(a => a.purpose === 'color');
fetch('/ajax?categories=12&include_similar=1&limit=24')
.then(r => r.json())
.then(products => {
products.forEach(product => {
const own = color(product.attributes);
const others = product.similar_products
.map(similar => ({ url: similar.url, color: color(similar.attributes) }))
.filter(similar => similar.color);
console.log(product.name, own ? own.value_tag : null, others);
});
});
Without include_similar, the two fields are not included, and the response is the same as before. Similar products can also be other products than colors, for example accessories. So only show the ones that have a color attribute.
Fields on each product in the response
Each product in the products array has these fields, among others:

- product_id, own_id, name, description, list_description
- price, real_price, sale_price, price_dk (Danish number format)
- stock, attr_stock, variant_stock, stock_string_da
- brand_name, supplier_id, supplier_name, profile_name
- category_ids, category_names
- thumbnail (200x200 fit), thumbnails (array of all images in 200x200), url
- avg_rating, online_since, delivery_time, delivery_time_not_in_stock, approx_shipping
- has_campaigns, campaign_info
- meta_values (only filled in if you send meta=...)
- attributes, similar_products (only included if you send include_similar=1)
If the store has turned on "Hide stock status in AJAX feeds", stock, attr_stock, and the stock quantities in variant_stock are null, so stock levels are not exposed publicly.
Caching
The endpoint is cached on the server for 12 hours per unique URL. The response is also sent with correct Last-Modified and Expires headers, so browsers and intermediate caches can return a fast 304 Not Modified if the content hasn't changed. This keeps response times fast, but it also means that changes to a product only take effect once the cache expires. You can force the cache to rebuild for a specific URL by adding rebuild=1.
Read more in the article Caching in Shoporama, which covers the cache layers in general.
Implementing it in your theme
To build a complete AJAX-filtered product list, the developer typically needs to:
- Build a filter UI with checkboxes or dropdowns based on meta.attributes, meta.brands, and meta.categories
- Listen for changes to the filters and combine them into a query string
- Call /ajax with the selected parameters
- Update the product list dynamically and show pagination based on pagination.total
Tip: Read more about filtering in general in Product filtering in your store. If you use the Delaware theme, AJAX filtering works out of the box.
Frequently asked questions
Where do I find the ID of an extended field or an attribute value?
An extended field's ID is the ID the theme gives the field in the file extensions/product.json. Ask your theme developer if you don't have access to the theme files yourself. Attribute values are under Webshop → Product profiles, and their IDs are included in the response from /ajax when you add include_meta=1.
Where do I find the ID of a shared value?
The IDs are not shown on the Shared Values page in the admin. Instead, get them in the theme with $webshop->getSharedValues(), from meta.shared_values in an /ajax call with include_meta=1, or from the REST endpoint GET /attribute-shared-value.
Why do I get no results when I use category_id=123?
Because that parameter doesn't exist. Change it to categories=123 (plural). It is one of the most common mistakes when building AJAX filtering for the first time. Also check that you aren't using price_from/price_to or extra_field[..], which don't exist either.
My changes to a product don't show up in /ajax. What do I do?
The endpoint is cached for 12 hours. Wait, or load the URL with &rebuild=1 to force that exact URL to be regenerated.
Do many AJAX calls affect my site speed? (Mikkel, developer)
The cache makes sure repeated calls are fast. Still, avoid making a new call for every single keystroke in a search field. Use "debounce" so you only call once the user pauses for 200-300 ms. The browser also uses If-Modified-Since, so unchanged responses come back as 304 and use almost no bandwidth.
Do I get the same result as on the category page?
Almost. /ajax follows the same rules that ProductFactory uses on category pages, so filtering, sorting, and visibility (for example hidden products) behave the same way.
Can I build search on top of /ajax? (Sofie, new hire)
/ajax doesn't take a free-text search parameter. For search, use Shoporama's dedicated search endpoint in the theme (typically /search), or filter on product_ids if you handle the search yourself and just want to fetch data for a known list of products.
How many products can I fetch in one call? (Jonas, scaling)
You can fetch up to 1000 products in one call. If you ask for more, the response is automatically capped at 1000, and the store also gets a notice in the admin under Messages, so you can spot it. In practice, you should stay well below that. A few hundred per call keeps the JSON payload small and the response fast, which matters especially for customers on mobile. Use limit and offset to paginate, or fetch only the next batch when the user scrolls.
Are my stock levels exposed publicly? (Malene, marketing)
By default, the response includes stock quantities. If you want to hide them (so competitors or bots can't see how much you have in stock), your developer can turn on "Hide stock status in AJAX feeds" for the store, and the stock fields are then sent as null.
Can I use /ajax as a "real" REST API? (Mikkel, developer)
No, it is a public, cache-friendly product endpoint for frontend use. If you need to create, update, or integrate at a deeper level, use the actual REST API instead, which requires an API key.
Can I show the other colors on the product card? (Line, theme developer)
Yes, if the colors are linked under Similar products. Send include_similar=1, and find the color in attributes on the product and on each product in similar_products, for example where purpose is color. The hex code can be stored as the tag on the color value. It doesn't cost an extra call per product, because the similar products are fetched together for the whole list.
Should I worry that filtering works differently for customers in different languages?
The endpoint runs in the same store context as the front page, so prices, currency, and visibility follow the store the call hits. If you have several stores or languages, remember that each store has its own URL and therefore its own /ajax cache.
Would you like help building AJAX filtering into your theme, or do you have technical questions? Email support@shoporama.dk.
Related articles
Filtering in your online store
How to set up product filtering in your Shoporama store, so customers can filter products on category pages by profile attributes, product labels,...
Delaware theme: settings and customization
A complete guide to Delaware and DelawareDK in your Shoporama store: theme settings, footer menus, mega menu, colors, payment icons, Trustpilot,...
REST API: authentication, endpoints, and the API log
A complete guide to Shoporama's REST API: authentication, API keys and user roles, all endpoints, examples, the Swagger documentation, and the API...
Import extra fields on products via CSV
How to import product extra fields with a CSV import in Shoporama, using query string syntax (field=value separated by &) in the extra_fields column.
Cache in Shoporama: when do your changes show up?
How caching works in Shoporama: how often each cache layer is rebuilt, when your changes become visible, and how to force a cache reset.
Shared values: the same sizes across product profiles
Use shared values so that, for example, Medium is the same value in all your product profiles, and customers can filter on everything in Medium,...
Related features
Product filtering (faceted search)
Product filtering lets customers narrow down your range by price, color, size, and more. Learn about filter types, best practices, and SEO for...
Lightning-fast site search with Elastic Search
Lightning-fast product search with Elastic Search for your online store. Typo tolerance, synonyms, zero-result searches, and search analytics...
Speed is a feature: why we made Shoporama stores lightning fast
We love fast online stores, and so does everyone else. That's why we made Shoporama stores lightning fast. It's good for you, your customers, and...