I have a outpout.json file which contains email and token as a key value pair and i want to call a post api for each of these email in a shell script but it is calling the api only once for the first email and token not the next one
{ "[email protected]":"9RN_5atv9F1e0zCKrkjRHQP1IYu1Wknz", "[email protected]":"2Is864BMgiocY0gveVZZSelB4YT5fP-G" }
this is my shell script
#!/bin/bash
send_email() {
local email=$1
local token=$2
echo "Sending email to: $email, Token: $token" # Add logging
# Call API using curl with request body only
response=$(curl -s -X POST -H "Content-Type: application/json" -d "{"email": "$email", "token": "$token"}" http://127.0.0.1:8081/emailIssues)
echo "API Response: $response" # Log API response
}
# Check if output.json exists in the same directory
if [ ! -f "output.json" ]; then
echo "Error: output.json file not found"
exit 1
fi
# Read and process JSON data
json=$(cat output.json)
echo "JSON Data: $json" # Log JSON data
echo "$json" | jq -r 'to_entries[] | "(.value) (.key)"' | while read -r token email; do
echo "Processing: Email: $email, Token: $token" # Log processing of each email and token
# Call send_email function with email and token
send_email "$email" "$token"
done
i was expecting that for each email and token it will call the api
1