Multi Store Discount Code Generator
internalA TypeScript CLI tool for creating, topping up, and exporting unique Shopify discount codes across multiple stores for email marketing campaigns.
Local CLI Workflow
- Runs through npm scripts for setup, initial code creation, and campaign top-ups
- Loads store and discount configuration from local JSON files
- Validates required store admin configuration before attempting Shopify mutations
Shopify App Authentication
- Uses environment-provided Shopify app credentials during setup
- Exchanges app credentials for Shopify Admin access tokens per configured store
- Stores generated admin access configuration locally for later campaign runs
Discount Campaign Creation
- Generates unique prefixed coupon codes with Node crypto utilities
- Creates a parent Shopify discount configured with usage limits, customer rules, date windows, and collection targeting
- Applies the same generated code set across each configured Shopify store
Shopify Bulk Code Import
- Adds redeem codes through Shopify Admin GraphQL bulk discount mutations
- Processes codes in fixed-size batches to work within API-oriented bulk workflows
- Polls bulk creation status and reports imported, failed, and missing code counts
Top-Up Operations
- Adds more codes to existing Shopify discount nodes using saved discount identifiers
- Can import an existing coupon CSV or generate fresh codes against the local ledger
- Writes a timestamped coupon feed for marketing platform upload after each top-up run
Local Data Outputs
- Maintains a JSON ledger of issued codes to avoid accidental reuse
- Stores discount node identifiers locally so later top-ups target the correct Shopify discounts
- Exports coupon feeds as CSV files formatted for Klaviyo upload
- # Why use a local CLI?
- The CLI supports batch campaign operations without a hosted application layer, which keeps the architecture lightweight for admin-driven discount generation while making execution an intentional operator workflow.
- # Why keep Shopify as the source of truth?
- Discount definitions and redeem codes are created through Shopify Admin GraphQL, while local files only coordinate generated codes, target stores, and follow-up top-ups.
- # Why batch the code imports?
- Bulk GraphQL mutations and status polling let the tool create large coupon sets more reliably than one request per code, with failure counts and missing-code checks surfaced during execution.
- # How is code reuse controlled?
- A local issued-code ledger is loaded before generation and updated after create or top-up runs, giving the tool a simple persistence layer for avoiding duplicate coupon codes.
- # How are credentials handled?
- Shopify credentials are read from environment configuration during setup, and generated admin config files are ignored by git, keeping secrets out of normal source control workflows when configured correctly.