fix: handle spaces in JSON when extracting Stripe IDs

- Update grep patterns to match JSON with spaces after colons
- Fixes false 'Error creating meter' message when meter created successfully
- Applies to meter ID and price ID extraction
This commit is contained in:
Graham McIntire 2026-03-06 11:02:48 -06:00
parent 3e721b9395
commit 13631595a7
No known key found for this signature in database

View file

@ -51,7 +51,7 @@ EXISTING_METERS=$(curl -s https://api.stripe.com/v1/billing/meters \
-u "${STRIPE_KEY}:" \
-H "Stripe-Version: 2024-11-20.acacia")
METER_ID=$(echo "$EXISTING_METERS" | grep -o '"event_name":"devices_monitored"' -B 20 | grep -o '"id":"mtr_[^"]*"' | head -1 | cut -d'"' -f4)
METER_ID=$(echo "$EXISTING_METERS" | grep -o '"event_name": "devices_monitored"' -B 20 | grep -o '"id": "mtr_[^"]*"' | head -1 | cut -d'"' -f4)
if [[ -n "$METER_ID" ]]; then
echo "✓ Found existing billing meter!"
@ -69,7 +69,7 @@ else
-d "default_aggregation[formula]=sum" \
-d "value_settings[event_payload_key]=value")
METER_ID=$(echo "$METER_RESPONSE" | grep -o '"id":"mtr_[^"]*"' | head -1 | cut -d'"' -f4)
METER_ID=$(echo "$METER_RESPONSE" | grep -o '"id": "mtr_[^"]*"' | head -1 | cut -d'"' -f4)
if [[ -z "$METER_ID" ]]; then
echo "Error creating meter:"
@ -101,7 +101,7 @@ PRICE_RESPONSE=$(curl -s https://api.stripe.com/v1/prices \
-d "unit_amount=100" \
-d "nickname=Per Device Monthly")
PRICE_ID=$(echo "$PRICE_RESPONSE" | grep -o '"id":"price_[^"]*"' | head -1 | cut -d'"' -f4)
PRICE_ID=$(echo "$PRICE_RESPONSE" | grep -o '"id": "price_[^"]*"' | head -1 | cut -d'"' -f4)
if [[ -z "$PRICE_ID" ]]; then
echo "Error creating price:"