How do I trigger an event from a Bash shell script?

This solution was originally taken from this StackOverflow answer

Please note that it is essential that you validate the parameters you are sending if the content of your events are user generated.

Please also note that the channel name, event name and event data used in the following example is hard-coded and you would need to extract that into a parameter.

Finally update the values for key, secret, appId and cluster. The list of clusters can be found here

#!/bin/bash

key="my_key"
secret="my_secret"
appID="my_app_id"
cluster="my_cluster_name" timestamp=$(date +%s) data='{"name":"say_stuff","channel":"test","data":"{\"message\":\"oh_yeah\"}"}' # Be sure to use `printf %s` to prevent a trailing \n from being added to the data. md5data=$(printf '%s' "$data" | md5) path="/apps/${appID}/events" queryString="auth_key=${key}&auth_timestamp=${timestamp}&auth_version=1.0&body_md5=${md5data}" # Be sure to use a multi-line, double quoted string that doesn't end in \n as # input for the SHA-256 HMAC. authSig=$(printf '%s' "POST $path $queryString" | openssl dgst -sha256 -hex -hmac "$secret")
curl -H "Content-Type:application/json" -d "$data" "https://api-${cluster}.pusher.com${path}?${queryString}&auth_signature=${authSig}"
Was this article helpful?
0 out of 0 found this helpful
Haven't found what you were looking for?
Submit a ticket