Pie
Pie

Reputation: 937

How To Upload CSV To Algolia Using A Script

I would like to upload my CSV file using a PowerShell script. How is one able to accomplish this?

I was unable to find anything in the documentation. If there is something it should be searchable in the documentation.

https://www.algolia.com/doc/

Upvotes: 2

Views: 558

Answers (3)

Sepehr
Sepehr

Reputation: 101

As of November 2018, you can use the Algolia CLI to easily import your JSON or CSV file(s) from your terminal:

  • $ npm i -g @algolia/cli
  • $ algolia import -s path/to/your/file.csv -a your_app_id -k your_api_key -n your_index_name

Upvotes: 5

Pie
Pie

Reputation: 937

I figured I'd post my solution. Just make sure that node.js and algolia-csv package is installed and then you can run the algolia-upload command from within PowerShell

https://github.com/algolia/algolia-csv-js

NPM Manager (Which is packaged with Node) https://www.npmjs.com/package/npm

Windows Installer - https://nodejs.org/en/download/

  1. After installing "node-v6.11.1-x64" open the "node.js command prompt" application via the start menu
  2. Run the following commands: npm install -g algolia-csv
  3. Now you can prepare your command. (The CSV file must have headers in the first row only).

Options: algolia-upload $APP_ID $API_KEY $indexName $file|$url [-d $delimiter] [-b $batchSizer] [--clear-index] [--parse-arrays=$column]

Mandatory parameters are the aplication id, a key with write rights, the target index name and the input CSV (locally or accessible with http/https).

Other parameters: -d let you set the delimiter used in your file. This should be set in quotes. Default is ','. -b let you set the batch size. Default is 10000. --clear-index forces the index to be cleared before uploading the new data. --parse-arrays= let you specify if a column value should be splitted with ',' before uploading the data. More than one column can be set. --geo-colums=latCol,longCol let you specify two columns that are to be used for creating the special algolia attribute _geoloc

This is the command that I ended up using just as a example.

algolia-upload APPID APIKEY INDEX PATH.csv

Upvotes: 2

Haroen Viaene
Haroen Viaene

Reputation: 1360

we don't currently have an example written for PowerShell, but the steps it would come to are:

  1. read the csv in PowerShell
  2. convert the csv to JSON
  3. push to the API using curl

However, by going this route, you can't take advantage of the retry and DSN logic that's built into the Algolia API clients. You can use any of the API clients to upload the data instead.

There's also a node CSV toolbox, which is a CLI to split and upload a csv file.

You can also upload it on the dashboard as described here

Upvotes: 1

Related Questions