Shopify
How to xtract a product catalog from Shopify
When you’re building an application that needs Shopify product data, you typically face a few challenges:
- The Shopify API returns a complex data structure that might not match your needs
- You need to handle pagination, variants, and images
- You want to transform the data into your own format
Let’s see how superglue makes this easy.
Installation
Basic Product Extraction
Let’s get started by importing the client and defining the schema that you need the data in. Then you can use the `call` method to fetch the product data and transform it. `call` just needs a configuration object that describes the data source and the output schema you want.
What’s Happening Here?
-
Schema Definition: We define a simple schema that includes:
- Basic product info (id, title, url)
- Price information (lowest variant price)
- Variants with their prices
- Product images
-
Configuration: The `config` object tells Superglue:
- Where to get the data (`urlHost` and `urlPath`)
- What to do with it (`instruction`)
- What format we want (`responseSchema`)
Notice that superglue will automatically fill the missing parts of the configuration. For example, it will detect the required Http Method GET
and handle pagination for you if instructed or detected.
One quirk of the Shopify API is that it does not include a url field in the product object. It can be derived from the handle
and the shopdomain. As long as the instruction includes the shopdomain, superglue will be able to derive the url using implicit knowledge about the Shopify API.
- Execution: When you run this code:
- First run: Superglue fetches the data and transforms it (~10-20 seconds)
- Subsequent runs: superglue will fetch the data from the source, while the transformation instructions are cached.(typically <100ms)
Understanding the Response
The transformed data will look like this:
The response will also include the used configuration, the applied mapping, and some metadata. The generated JSONata mapping instruction will include the from_price which is derived from the lowest variant price. The url will be derived from the handle and the shopdomain. The complete JSONata mapping instruction will look something like this:
Handling Variants and Inventory
The next example shows how to focus on inventory:
This configuration transforms Shopify’s data into a flat inventory structure - perfect for stock management systems.
The corresponding mapping instruction will look something like this:
Working with Pagination
Shopify limits results to 250 products per page. Usually, superglue will automatically handle this for you. Since this specific part of the API is not well defined, you can also manually handle it by providing the pagination
configuration. You could also just write it in the instruction, particularly if you are unsure aboute the exact pagination parameters.
The pagination config automatically:
- Fetches all pages
- Combines the results
- Handles rate limiting
Next Steps
- Check the API Reference for detailed type information
- Join our Discord for support
Was this page helpful?