The Batch Requests plugin for Insomnia adds the ability to send a request repeatedly, changing parts of every request by variable data, taken from a CSV file. For every response, some data can be collected and added to the CSV file.
For a short demonstration, watch this:
Go to the Application>Preferences
menu in Insomnia, then go to the Plugins
tab, search for insomnia-plugin-batch-requests
and install it.
Note Want to send files in your repeated requests? See below. The
Batch
tag that is described in this section sends text values only
The plugin adds a template tag to mark the places that you want to replace. To add it, press Ctrl+Space
, search for the Batch
tag and press Enter
. Then, double click the tag to configure it. The tag can be inserted anywhere in the request (e.g. in the URL, query parameters, headers, or body)
When configuring the tag, set the following two values:
The live preview will always show the value of the Sample value
field, and this same value will be replaced when sending the request manually (e.g. via Insomnia's main Send button) The value will only vary when sending the request via the Batch Request dropdown option (see below).
The plugin also adds a context menu option to all requests. To see it, click on the dropdown arrow to the right of a request on the sidebar, then select the Batch Requests
option. This will open the plugin dialog.
On the plugin dialog, you should:
Outputs
:$.total
field will be written to the sales
column in the CSV file. This plugin uses the jsonpath-plus
syntax, which is also used by Insomniacontent-length
to fetch the response's length. This field is case-insensitive (i.e. you don't need to match the exact casing returned by the server)Run!
button at the bottom of the dialog. It will only become active when you have chosen a file and (if any outputs exist) completely filled all Outputs.Save
button to write the extracted data back to the CSV file, if you need it. Wait until all requests have been performed (as indicated by the progress bar) before clicking this button.Since v1.5.0
, it's possible to also send files that vary on each request, just like before it was possible to send text that varied.
For example, this could be useful to upload several files at once to Google Drive: just prepare a CSV that lists the paths to the files and any other data that must vary per file (e.g. the file's title), and then run the request several times.
The CSV must look like this (it must contain a column, here called fname
, that lists absolute file paths):
Then, create a request on Insomnia. Set its Body to Multipart. Add a new field to the body. Insert a Batch (File)
template tag: place the cursor in the Value of the field, press Ctrl+Space
, search for Batch (File)
, and insert it:
Warning Do not change the field's type to File! Leave it as Text, which is the default. If you change it to File, it isn't possible to insert template tags, since Insomnia only shows the file picker button, so you'd be forced to choose one single file for all requests
Click on the newly-added tag to open its configuration dialog:
When configuring the tag, set the following two values:
Click the Done button to save changes. The tag should now look like this:
From now on, the process continues as normal (see the Usage section above). Click the dropdown menu for the request, select the Batch Requests option, select a CSV file, configure any desired outputs, and click Run. Any fields whose content is a Batch (File) template tag will be replaced with the contents of the file whose path is contained in the configured column of the CSV file. Requests will then be sent as normal. For example, this is the third request sent with the CSV file that was shown above:
If you send the request manually (e.g. by clicking the Run button, or by pressing Ctrl+Enter
or F5
), the file that will be sent will be the one that was configured on the template tag's Sample Data field:
Since v1.4.0
, it's possible to extract data from several places in the response:
v1.4.0
. This option requires specifying a JSONPath expression to extract a specific value from the JSON response, such as $.data.id
200
). This option does not require any further configurationThe source of data is chosen in the center dropdown of each Output. If required, the right-hand text field will appear and must contain something, otherwise it'll be hidden.
There are two additional options that can be set when sending batch requests. They appear in the Run Config section, above the progress bar:
v1.1.0
): Inserts a delay before sending each request. It's useful if the remote API enforces a rate limit or it's otherwise desired to throttle requests. By default it's set to 0. Can also be altered for the entire Request Collection (see below)v1.3.0
): Controls the number of requests that can be in flight at the same time. If set to a value greater than 1, it'll send multiple requests in parallel. Once a request is done, another one will start. By default it's set to 1Since v1.2.0
, there is a Global Configuration dialog in which you can select a default request delay, in case you usually work with servers that require a delay between requests.
Batch Requests: Settings
option.Default delay
. Set its value to your preferred delay.~/.config/Insomnia/plugins
. Alternatively, open Insomnia, select the Application>Preferences
menu, go to the Plugins tab, then click the Reveal Plugins Folder
button.git clone https://github.com/jreyesr/insomnia-plugin-batch-requests
.npm i
.npm run dev
. This will start a dev server that will generate the dist/main.js
file and keep it updated whenever you change the source files.dist/main.js
file will be updated. To make Insomnia pick up the changes, select the Tools>Reload plugins
option from the top menus. Alternatively, press Alt+T
, then release both, then press R
.npm run test
package.json
.package.json
has been bumped.master
has the code.package.json
.