You can use cURL in a loop to send POST requests with multiple variables from a CSV file. Here's a basic example of how to achieve this using a Bash script:
Assuming you have a CSV file named "data.csv" with the format:
```csv
variable1,variable2,variable3
value1a,value2a,value3a
value1b,value2b,value3b
value1c,value2c,value3c
```
You can create a Bash script to loop through the CSV and send POST requests using cURL:
```bash
#!/bin/bash
# CSV file path
csv_file="data.csv"
# API endpoint
api_url="https://example.com/api"
# Read the CSV file line by line, skipping the header
tail -n +2 "$csv_file" | while IFS=, read -r variable1 variable2 variable3; do
# Construct the JSON data
json_data="{\"variable1\": \"$variable1\", \"variable2\": \"$variable2\", \"variable3\": \"$variable3\"}"
# Send the POST request using cURL
response=$(curl -X POST -H "Content-Type: application/json" -d "$json_data" "$api_url")
# Print the response
echo "Response for $variable1, $variable2, $variable3: $response"
done
```
In this script:
- `csv_file` is the path to your CSV file.
- `api_url` is the URL of the API you want to send POST requests to.
- The script reads the CSV file line by line, splitting each line into variables, and constructs a JSON payload to send in the POST request.
- It then uses cURL to send the POST request to the API endpoint.
- The response from the API is printed for each set of variables.
Make sure to customize the script to match your specific CSV file format and API endpoint. Additionally, you may need to adjust the cURL options (e.g., headers and authentication) according to your API's requirements.