Skip to content

Space48/coupon-code-importer

Repository files navigation

Coupon Code Importer

This is a handy script that can be used to bulk generate a given number of codes for any coupon promotion set up in BigCommerce.

Requirements

Node >= 18

Configure @space48 npm scope

coupon-code-importer is distributed as a private npm package in the @space48 scope. To install coupon-code-importer and other private Space 48 npm packages, you must first configure the @space48 scope in npm.

  1. Create a github access token with read packages and repo privileges

  2. Configure npm so that you can install coupon-code-importer and other private Space 48 packages. When running the below command and prompted for a username, enter your github username. When prompted for your password, enter the token you created in step 1. Do not use your github password

npm login --registry=https://npm.pkg.github.com --scope=@space48

Installation

npm i -g @space48/coupon-code-importer

Usage

The coupon code Importer creates codes in BigCommerce using the BigCommerce Management API. So you will need to configure the importer to connect to your BigCommerce store by setting up the credentials for it like so

coupon-code-importer init --store-hash <store-hash> --access-token <access-token>

This will write your credentials to a local file called importer-config.json in your working directory. The coupon code importer will read and use the credentials configured in that file

To invoke the importer there are a couple of arguments you will need to pass


coupon-code-importer run --amount <amount> --length <length> --prefix <prefix> --promotion-id <promotion-id>

--amount - Number of codes you want to generate
--prefix - Prefix to put in each code
--length - Character length of each code (including prefix)
--promotion-id - ID of promotion you want to tie the codes to

Once the run command completes, the coupon codes will be saved to a file called coupon-codes.csv in your working directory

Import From File

If tasked with importing already-determined codes from a input file. They can be imported like so:

(Please note: just like the run command, the init command should be ran first to configure the credentials for the store you want to import the coupon codes to.)

coupon-code-importer import --promotion-id <promotion-id> --file-path <path/to/input/file>

When complete, the codes will be written back to the coupon-codes.csv file. This can be used to determine the codes that may have failed to import successfully.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published