Created
July 25, 2019 21:23
-
-
Save shcallaway/71229578268cdad32e927faa1e0c0779 to your computer and use it in GitHub Desktop.
Create or update a Marqeta webhook
This file contains 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 | |
read -p "Enter your Marqeta username: " MARQETA_USERNAME | |
read -p "Enter your Marqeta password: " MARQETA_PASSWORD | |
read -p "Enter your Marqeta subdomain: " MARQETA_SUBDOMAIN | |
read -p "Enter your webhook URL: " WEBHOOK_URL | |
read -p "What should this webhook be called? " WEBHOOK_NAME | |
read -p "What basic auth username will the webhook accept? " WEBHOOK_BASIC_AUTH_USERNAME | |
read -p "What basic auth password will the webhook accept? " WEBHOOK_BASIC_AUTH_PASSWORD | |
# Secret feature: you can also update webhooks! | |
HTTP_METHOD=PUT | |
WEBHOOK_TOKEN="" | |
echo | |
echo "Configuration:" | |
echo "MARQETA_USERNAME=$MARQETA_USERNAME" | |
echo "MARQETA_PASSWORD=$MARQETA_PASSWORD" | |
echo "MARQETA_SUBDOMAIN=$MARQETA_SUBDOMAIN" | |
echo "WEBHOOK_URL=$WEBHOOK_URL" | |
echo "WEBHOOK_NAME=$WEBHOOK_NAME" | |
echo "WEBHOOK_TOKEN=$WEBHOOK_TOKEN" | |
echo "WEBHOOK_BASIC_AUTH_USERNAME=$WEBHOOK_BASIC_AUTH_USERNAME" | |
echo "WEBHOOK_BASIC_AUTH_PASSWORD=$WEBHOOK_BASIC_AUTH_PASSWORD" | |
echo "HTTP_METHOD=$HTTP_METHOD" | |
echo | |
read -p "Are you sure? [y/n] " -n 1 -r | |
if [[ ! $REPLY =~ ^[Yy]$ ]]; then | |
echo | |
exit 0 | |
fi | |
# This is the endpoint for creating a webhook. | |
MARQETA_ENDPOINT=https://$MARQETA_SUBDOMAIN.marqeta.com/v3/webhooks | |
# Use a different URL if we're updating a webhook. | |
if [[ $HTTP_METHOD -eq PUT ]]; then | |
MARQETA_ENDPOINT=https://$MARQETA_SUBDOMAIN.marqeta.com/v3/webhooks/$WEBHOOK_TOKEN | |
fi | |
echo | |
echo "Sending HTTP $HTTP_METHOD $MARQETA_ENDPOINT" | |
echo | |
curl -i -X $HTTP_METHOD -H 'Content-type: application/json' \ | |
--user $MARQETA_USERNAME:$MARQETA_PASSWORD \ | |
-d "{ | |
\"active\": true, | |
\"events\": [\"*\"], | |
\"name\": \"$WEBHOOK_NAME\", | |
\"config\": { | |
\"url\": \"$WEBHOOK_URL\", | |
\"basic_auth_username\": \"$WEBHOOK_BASIC_AUTH_USERNAME\", | |
\"basic_auth_password\": \"$WEBHOOK_BASIC_AUTH_PASSWORD\" | |
} | |
}" $MARQETA_ENDPOINT | |
echo |
This file contains 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
{ | |
"token": "0c2134fd-3350-40a2-b24b-65xa5d5e0ef9", | |
"name": "My Webhook", | |
"active": true, | |
"config": { | |
"url": "https://my-server.com", | |
"secret": "", | |
"basic_auth_username": "m**********a", | |
"basic_auth_password": "x**********=" | |
}, | |
"events": [ | |
"*" | |
], | |
"created_time": "2019-07-25T20:57:30Z", | |
"last_modified_time": "2019-07-25T21:16:48Z" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment