Headless TradeGecko interaction CLI for those without API access or for automating calls not yet published in the TradeGecko API Reference.
npm install --global tradegecko-headless
If you receive the error ERROR: Failed to download Chromium, please see the NPM article on preventing premission errors.
Given that a Chrome headless instance will need to be launched, it is advised that a local install be used if permission issues exist.
The following usage examples should be read sequentially as it references results from previous commands.
It is also recommended that all result files be viewed or manipulated with jq.
To use the CLI, identify the command you want to execute and provide any parameters and options.
tgcli [command] [options]
To see the full list of commands, execute
tgcli --help
Username and password can be provided as environment variables or as parameters. It is recommended that environment variables be used.
export TG_USERNAME="foo@example.com"
export TG_PASSWORD="bar"
Download 2nd and 3rd oldest variants
resource, keeping only fields id
and created_at
and save them to file variants.json
tgcli tg:resource-list:download variants variants.json --limit=2 --offset=1 --fields=id,created_at
Signing in ...
Getting variants count ...
Getting variants ...
████████████████████████████████████████ 100% | ETA: 0s | 2/2
Saving variants to file ...
Done
[{"id":1,"created_at":"2017-01-11T11:00:00.000Z"},{"id":2,"created_at":"2017-01-11T12:00:00.000Z"}]
Make a fetch call using variants.json
and output results to fetched-variants.json
. The fetch
call should make a GET call to get the variant by id.
tgcli tg:resource-list:fetch variants.json fetched-variants.json GET "variants/{{id}}"
Signing in ...
Performing fetches ...
████████████████████████████████████████ 100% | ETA: 0s | 2/2
Saving responses to file ...
Done
Plese note the following outputs have been shortended for readability.
[{"variant":{"id":1,"created_at":"2017-01-11T11:00:00.000Z","updated_at":"...","committed_stock_levels":{}}},{"variant":{"id":2,"created_at":"2017-01-11T12:00:00.000Z","updated_at":"...","committed_stock_levels":{}}}]
For a full list of commands, execute the program with --help
. All commands should be prefixed with tgcli
.
Command | Description |
---|---|
tg:resource-list:download [resource] [file] |
Download a list of a given resource |
tg:resource-list:fetch [listFile] [responsesFile] [method] [endpoint] |
Perform fetch action on each record of a provided resource list JSON file |
tg:resource:count [resource] |
Get the total records of a given resource |
tg:ajax:fetch [method] [endpoint] |
Perform a fetch call against the TradeGecko AJAX API, see the MDN entry for Fetch API for details |
The following list of resources were obtained by observing Chrome debugger XHR activity for connections related to https://go.tradegecko.com/ajax
- channels
- products
- variants
Although not fully tested, most resources listed in the TradeGecko API Reference should be available as well.
- Puppeteer for headless Chrome interaction
- yargs for CLI
- cli-progress for progress bars
- mustache for parameter templates