Created
August 1, 2023 05:43
-
-
Save yongqianme/7965d24eee39fe2bcf75ef785f4f0084 to your computer and use it in GitHub Desktop.
Delete stripe customers in Bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Step 1: Get the JSON list and extract the "id" into an array called "ids" | |
response=$(curl -G https://api.stripe.com/v1/customers \ | |
-u sk-key: \ | |
-d limit=3) | |
# Check if the curl command was successful | |
if [ $? -ne 0 ]; then | |
echo "Error occurred while fetching data from the API." | |
exit 1 | |
fi | |
# Extract "id" from the JSON response using jq | |
ids=($(echo "$response" | jq -r '.data[].id')) | |
# Step 2: Delete the customers using their ids from the "ids" array | |
for id in "${ids[@]}"; do | |
delete_response=$(curl -X DELETE "https://api.stripe.com/v1/customers/$id" -u sk_test_your_key:) | |
# Check if the delete curl command was successful | |
if [ $? -eq 0 ]; then | |
echo "Customer with id $id deleted successfully." | |
else | |
echo "Error occurred while deleting customer with id $id." | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment