# Shopify Collection Product & Variant Exporter (`practical_ai_lab_jp/pal-shopify-product-collection-export`) Actor

Shopify product exporter for public Shopify collections: extract product and variant SKUs, listed prices, availability and product details to CSV/JSON. Use for merchandising audits, supplier catalog reconciliation and storefront migration. No login or private inventory access.

- **URL**: https://apify.com/practical_ai_lab_jp/pal-shopify-product-collection-export.md
- **Developed by:** [Practical AI Lab](https://apify.com/practical_ai_lab_jp) (community)
- **Categories:** E-commerce, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 export rows

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Shopify Collection Product & Variant Exporter

Export products and variants from **publicly accessible Shopify collection handles**. The Actor reads only the public `/collections/<handle>/products.json` feed, checks `robots.txt` first, and enforces hard limits on pages, products and rows.

> **Published on Apify Store.** This Actor is priced per output event. Check the current Pricing tab and run limits before starting. Start with the [small collection-variant Example](https://apify.com/practical_ai_lab_jp/pal-shopify-product-collection-export/examples/shopify-collection-variant-export-sample).

### What makes it different from a general Shopify scraper

- **Collection-scoped.** You name the collections you need (for example `new-arrivals`, `sale`). It does not crawl a whole store.
- **Variant-level rows.** One row per variant with SKU, option values, price, compare-at price, a computed `discount_percent` and availability. Or switch to one summary row per product (price range, available variant count, best discount).
- **Cross-collection de-duplication.** A product listed in several collections of the same store is exported once.
- **Bounded by design.** Caps on products per collection, pages per collection, rows per run, response size, and a minimum delay between requests.
- **Run summary.** A `SUMMARY` record in the key-value store lists, per collection, the status (`ok`, `empty`, `not_found`, `blocked_by_robots`, `error`), pages fetched, duplicates skipped and whether the export was `truncated` by your limits.

### Sample input

Run this small prefilled public-store sample, or replace it with a store and collection you are authorized to access.

```json
{
    "shopDomain": "www.allbirds.com",
    "collectionHandles": ["all"],
    "exportMode": "variants",
    "maxProductsPerCollection": 2,
    "maxPagesPerCollection": 1,
    "maxTotalRows": 500,
    "pageSize": 2,
    "onlyAvailable": false,
    "dedupeAcrossCollections": true,
    "includeDescription": false,
    "requestDelaySeconds": 1
}
```

You can also pass full URLs (several stores allowed, 25 collections maximum per run):

```json
{
    "collectionUrls": [
        "https://store-one.com/collections/summer",
        "https://store-two.com/collections/best-sellers"
    ]
}
```

### Input reference

| Field | Default | Meaning |
| --- | --- | --- |
| `shopDomain` + `collectionHandles` | - | One store and its collection handles. |
| `collectionUrls` | - | Alternative: full https collection URLs. |
| `exportMode` | `variants` | `variants` or `products`. |
| `maxProductsPerCollection` | 50 | 1-1000. |
| `maxPagesPerCollection` | 4 | 1-10 feed requests per collection. |
| `pageSize` | 50 | 1-250 products per feed page. |
| `maxTotalRows` | 500 | 1-10000 rows for the whole run. |
| `onlyAvailable` | false | Skip unavailable variants/products. |
| `dedupeAcrossCollections` | true | Export each product once per store. |
| `includeDescription` / `descriptionMaxChars` | false / 500 | Plain-text description, truncated. |
| `requestDelaySeconds` | 1 | 0.5-30 seconds between requests to one store. |

### Output

Variant mode row (illustrative structure with placeholder values, not a real result):

```json
{
    "row_type": "variant",
    "shop_domain": "your-store.com",
    "collection_handle": "sale",
    "product_id": 1001,
    "product_title": "Sample Jacket",
    "product_url": "https://your-store.com/products/sample-jacket",
    "variant_id": 2001,
    "variant_title": "M / Blue",
    "sku": "JKT-M-BLU",
    "option_values": {"Size": "M", "Color": "Blue"},
    "price": 80.0,
    "compare_at_price": 100.0,
    "discount_percent": 20.0,
    "available": true
}
```

Product mode adds `variant_count`, `available_variant_count`, `min_price`, `max_price`, `min_compare_at_price`, `max_discount_percent` and `skus` instead of variant fields.

### Safety and compliance

- Only `https` URLs on standard port 443; credentials, IP addresses, local/reserved names and non-public DNS results are rejected.
- Redirects are never followed.
- `robots.txt` is fetched per store and applied, including wildcard rules. If it cannot be read (other than 404/410), the store is skipped (fail closed).
- Responses are size-capped; retries are limited to two, for HTTP 429/5xx only.
- No proxies, no login, no personal customer data. Only public catalog fields are read.
- You are responsible for complying with each store's terms and applicable law.

### Billing note

The code emits one `export-row` event per row actually written to the dataset. Failed collections, robots blocks, empty results, skipped duplicates and errors write no rows and are therefore never charged. No payable pricing plan is configured in this project; any price must be set separately after real cost measurement.

### Limitations and sample-size caveats

- Stores can disable or restrict the public feed; those collections return an error or empty status.
- The feed has **no currency field**; prices are the store's raw numbers (you must know the store currency). Prices shown are what the feed exposes, which may differ from checkout prices (taxes, markets, discounts).
- Output is a **bounded snapshot**. With default limits (50 products, 4 pages) a large collection is truncated; check `truncated` in `SUMMARY`. A single run is not evidence of full-catalog coverage or of price trends.
- Collection ordering and contents change over time; repeated runs may differ.
- A domain is checked against DNS before connecting, but a hostile DNS rebinding race cannot be fully excluded.
- Some feeds omit fields (for example barcodes, inventory counts); those are not exported.
- Product-type and tag values depend on how each merchant fills them in.
- Tests in this project run offline against synthetic fixtures. They do not prove behavior against any live store.

### Local development

```
python -m unittest discover -s tests
```

(The tests need no network and do not import the Apify SDK.)

# Actor input Schema

## `shopDomain` (type: `string`):

Public domain of the Shopify store, for example your-store.com. Replace the sample with a store you are allowed to read. Used together with Collection handles.

## `collectionHandles` (type: `array`):

Handles from URLs like https://your-store.com/collections/<handle>. Use 'all' only if the store exposes it.

## `collectionUrls` (type: `array`):

Alternative to the fields above: full https collection URLs, which may span several stores. Maximum 25 collections in total.

## `exportMode` (type: `string`):

'variants' writes one row per variant (SKU, price, availability). 'products' writes one summary row per product.

## `maxProductsPerCollection` (type: `integer`):

Hard cap on products read from each collection.

## `maxPagesPerCollection` (type: `integer`):

Hard cap on feed requests per collection.

## `pageSize` (type: `integer`):

Products requested per feed page (the store may cap this at 250).

## `maxTotalRows` (type: `integer`):

Hard cap on dataset rows for the whole run. Each exported row is one billable event if pricing is enabled later.

## `onlyAvailable` (type: `boolean`):

Skip variants (or products) that are not currently available.

## `dedupeAcrossCollections` (type: `boolean`):

A product listed in several collections of the same store is exported once.

## `includeDescription` (type: `boolean`):

Add plain-text product description (HTML removed).

## `descriptionMaxChars` (type: `integer`):

Truncation length for description text.

## `requestDelaySeconds` (type: `number`):

Pause between requests to the same store. Minimum 0.5.

## Actor input object example

```json
{
  "shopDomain": "www.allbirds.com",
  "collectionHandles": [
    "all"
  ],
  "exportMode": "variants",
  "maxProductsPerCollection": 2,
  "maxPagesPerCollection": 1,
  "pageSize": 2,
  "maxTotalRows": 500,
  "onlyAvailable": false,
  "dedupeAcrossCollections": true,
  "includeDescription": false,
  "descriptionMaxChars": 500,
  "requestDelaySeconds": 1
}
```

# Actor output Schema

## `results` (type: `string`):

Download rows from the latest run in JSON/CSV.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "shopDomain": "www.allbirds.com",
    "collectionHandles": [
        "all"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("practical_ai_lab_jp/pal-shopify-product-collection-export").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "shopDomain": "www.allbirds.com",
    "collectionHandles": ["all"],
}

# Run the Actor and wait for it to finish
run = client.actor("practical_ai_lab_jp/pal-shopify-product-collection-export").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "shopDomain": "www.allbirds.com",
  "collectionHandles": [
    "all"
  ]
}' |
apify call practical_ai_lab_jp/pal-shopify-product-collection-export --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,practical_ai_lab_jp/pal-shopify-product-collection-export"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/EeftrkJxmFL3I4ehr/builds/tU6mizeV3EVYVworp/openapi.json
