Skip to content

Repository files navigation

SetSale Contractor Price Import

A small CLI script for bulk-importing contractor-specific equipment prices into SetSale from a CSV file, via POST /distributor/prices/import.

How it works

The script reads a CSV of model numbers and per-contractor prices, then syncs each price to SetSale. It runs in dry-run mode by default so you can preview exactly what would be sent before making any live changes.

Setup

  1. Install dependencies:
npm install
  1. Create a local .env file from the template:
cp .env.example .env
  1. Set your SetSale distributor API key in .env:
SETSALE_API_KEY=your_setsale_api_key_here

.env is gitignored. Never commit it — it holds a live secret.

CSV format

By default the script reads data.csv from this directory. Use --file to point at another CSV.

Model Number,CONTRACTOR_EXTERNAL_ID_1,CONTRACTOR_EXTERNAL_ID_2
,Contractor Name 1,Contractor Name 2
SKU-001,100,125
SKU-002,#N/A,150
  • Row 1Model Number in column A, then one contractor external ID per column.
  • Row 2 (optional) — a blank column A followed by contractor display names. This row is only used for friendlier log output and can be omitted. If column A of row 2 contains a model number instead of a blank, the script automatically treats it as the first data row.
  • Data rows — a model number in column A, then the price for each contractor.

Cell rules

  • Numeric cells create or update a price (upsert).
  • Blank, #N/A, #NA, and N/A cells are treated as intentional removals when pruning is enabled (the default). Use --no-prune for additive-only updates.
  • Non-numeric or negative prices are skipped, not turned into deletes.
  • Duplicate rows for the same model number are merged. If a duplicate has conflicting prices for the same contractor, that cell is skipped (not deleted).
  • Model numbers not present in the CSV are never touched.

Usage

Preview the import (dry run, no API calls — this is the default):

npm run populate-prices

Send the import to SetSale:

npm run populate-prices:execute

Common options

Pass extra flags after --.

Import only a single contractor by external ID:

npm run populate-prices -- --contractor CONTRACTOR_EXTERNAL_ID
npm run populate-prices:execute -- --contractor CONTRACTOR_EXTERNAL_ID

Use a different CSV file:

npm run populate-prices -- --file ./other.csv

Additive-only sync (don't send deletes for blank cells):

npm run populate-prices:execute -- --no-prune

Write detailed per-batch API results to a JSON file:

npm run populate-prices:execute -- --log-file import-results.json

Contributors

Languages