Command line tool to push JSON payloads to a Coveo Push source (or a Catalog source, through the Stream API).
- Node.js 24 or newer (see
.nvmrc). - No runtime dependencies: HTTP calls use Node's built-in
fetch, and arguments are parsed withnode:util.parseArgs.
npm install --global coveo-pushapi-cliThe first time you run pushapi in a folder, it helps you create the config file .pushapi-config.json by asking for your source ID, organization ID, platform and API key. The file is created with 0600 permissions since it holds your API key. Don't commit it.
# Push one JSON payload file. Don't forget to set DocumentId in the payloads.
pushapi file.json
# Push one file, then delete every item of the source that is older than 24 hours.
# Typical when you create/update all valid items and want the leftovers gone.
pushapi file.json -d 24
# Push every .json file of a folder, batched into as few requests as possible.
pushapi folder
# Dry run: build the batch files (.pushapi.buffer.N) locally, without pushing anything.
pushapi folder --dry-run
pushapi --help| Option | Description |
|---|---|
-d, --deleteOlderThan <hours> |
Delete source items older than <hours> before pushing. |
-D, --dry-run |
Create the batch files without pushing them. |
--help, --version |
Show help / version. |
Uploads accept a mix of these JSON formats, including within the same folder:
- an array of items
- a Push API payload:
{ "AddOrUpdate": [ ... ] } - a single item object
See the samples/ folder for examples.
{
"org": "your-org-id",
"source": "your-source-id",
"apiKey": "xx--your-api-key--abc",
"platform": "push.cloud.coveo.com",
"useStreamApi": false,
"debug": false
}| Key | Description |
|---|---|
org |
Coveo organization ID. |
source |
Push (or Catalog) source ID. |
apiKey |
API key with the Edit privilege on the source. |
platform |
Push API host. Defaults to push.cloud.coveo.com. Use pushdev., pushstg. or pushhipaa. for the other platforms. |
useStreamApi |
true for a Catalog source: payloads go through the Stream API instead of the Push API. |
debug |
true to log every request and its response code. |
The tool does a minimal validation of the payload (every document needs a DocumentId), then runs these API calls:
- Change the source state to
REBUILD - Get a file container
- Upload the payload to the file container
- Send the batch command to process the file container
- Change the source state back to
IDLE(even if a previous step failed)
With useStreamApi, it instead opens a stream, uploads one chunk per batch, and closes the stream.
| Code | Meaning |
|---|---|
0 |
Success. |
1 |
Missing config file, missing input file, or invalid payload. |
2 to 5 |
Invalid config: missing config / apiKey / org / source. |
10 |
A request to the platform failed. The response body is printed. |
The package is an ES module. It can also be loaded with require() on Node 24+.
import { main } from 'coveo-pushapi-cli';
// Reads .pushapi-config.json from the current folder.
await main('folder-with-payloads', { deleteOlderThan: 24, dryRun: false });git clone https://github.com/coveooss/pushapi-nodejs.git
cd pushapi-nodejs
npm install
npm test # node --test
npm run lint # eslintTests run against a mocked fetch; nothing is pushed to Coveo. CI runs lint and tests on every Node release line declared in engines.
- Branch or fork
- Pull request
- And... that's pretty much it!
- Jérôme Devost (GitHub profile)