Get store data with the API
What this article helps you do
Fetch active Mapstore locations from storefront JavaScript for a custom list or map. Do not use this procedure for the standard Mapstore block.
Before you start
- Mapstore is installed and has active stores.
- You can edit your Shopify theme’s JavaScript.
- Your code runs in a shopper’s browser on an HTTPS storefront.
Make a request
The endpoint is:
https://app.usemapstore.com/api/public/entities
Pass your permanent *.myshopify.com domain in the required shop query
parameter. Shopify exposes it as window.Shopify.shop in storefront pages.
const url = new URL('https://app.usemapstore.com/api/public/entities')
url.searchParams.set('shop', window.Shopify.shop)
url.searchParams.set('sort', 'name-a-z')
const response = await fetch(url)
if (!response.ok) {
throw new Error(`Mapstore request failed: ${response.status}`)
}
const data = await response.json()
console.log(data.entities)
The browser sets the Origin header. Do not set the header in your code.
Available query parameters
| Parameter | Use |
|---|---|
shop |
Required permanent *.myshopify.com domain |
strategy |
paginated (default) or view |
search |
Match a store name or address. A postal-code search can also find nearby stores |
filter |
Match any listed store filter; repeat the parameter or separate values with commas |
country |
Match any listed two-letter country code; repeat the parameter or separate values with commas |
includeCountries |
Use true to include available country codes in the response |
sort |
updated-newest, updated-oldest, name-a-z, name-z-a, or row-order |
cursor |
Continue a paginated response with the previous nextCursor |
zipRadiusKm |
Postal-code search radius from 1 to 500 kilometres |
north, south, east, west |
Map bounds used with the view strategy |
Only send map bounds when all four values are available.
Read the response
The response contains:
entitiescontains the current batch of active storeshasNextPageandnextCursorcontain the pagination statepageSize,loadingStrategy, andsortBycontain the request settings- Mapstore includes
countrieswhenincludeCountries=true - Mapstore includes
zipSearchContextwhen it finds a postal code
Store records can include name, address, coordinates, contact details, filters,
images, country code, and Google rating and hours data. They can also include
marker settings, directions settings, and distance for postal-code searches.
Mapstore omits optional values that are null or empty arrays.
To load the next page, send the returned cursor:
if (data.hasNextPage && data.nextCursor) {
url.searchParams.set('cursor', data.nextCursor)
const nextPage = await fetch(url).then(result => result.json())
}
Mapstore applies the plan limit for the shop before it returns locations.
Troubleshooting
| Issue | Fix |
|---|---|
400 response |
Add the correct permanent *.myshopify.com domain in shop. |
403 response or CORS error |
Run the request from an HTTPS storefront page. Server-side scripts and tools such as cURL do not send the required origin by default. |
| No stores returned | Make sure that stores are Active and have coordinates with view. Make sure that the request filters include the stores. |
| More stores are available | Follow nextCursor while hasNextPage is true. |