Checking SparkPost Message Events via the API with Wget

If you are using SparkPost for email delivery and wish to check message events, you can view message events information using the Wget utility, which is available for Linux, OS X, and Microsoft Windows systems. The man page for the command on a CentOS Linux system is here and the home page for the utility is at GNU Wget. Alternatively, for information on how to use curl, instead, see SparkPost - Addresses Associated With Bounced Email.

To download message events information for the last hour using the SparkPost application programming interface (API) with Wget, you can use a command similar to wget https://api.sparkpost.com/api/v1/message-events?events=bounce,out_of_band --header="Authorization: my_API_key" --header="Accept: application/json" where my_API_key is an API key provided to you by SparkPost. However, if you haven't granted access to message events for that key, you will receive a "ERROR 403: Forbidden" error as shown below. The API key, which in this case is a dummy key, is provided by sending a custom header that includes Authorization: my_API_key:

$ wget https://api.sparkpost.com/api/v1/message-events?events=bounce,out_of_band
 --header="Authorization: d12cc66a1a29755ef10fc1a1450d96dc23495970" --header="Ac
cept: application/json"                                --2016-09-04 21:44:34--  
https://api.sparkpost.com/api/v1/message-events?events=bounce,out_of_band
Resolving api.sparkpost.com (api.sparkpost.com)... 54.191.102.120, 54.69.65.44, 
52.40.18.107
Connecting to api.sparkpost.com (api.sparkpost.com)|54.191.102.120|:443... conne
cted.
HTTP request sent, awaiting response... 403 Forbidden
2016-09-04 21:44:39 ERROR 403: Forbidden.

$

To grant a key permission to access message event data, log into your SparkPost account at the SparkPost website, then click on Account, select API Keys and for an existing or new API key check the check box next to "Message Events: Read-only".

DJI Phantom 3 Drone

SparkPost - API Keys - message
events permission

Then click on the UPDATE API KEY button. After you do so, when you issue the Wget command, you should see output similar to the following:

$ wget https://api.sparkpost.com/api/v1/message-events?events=bounce,out_of_band
 --header="Authorization: d12cc66a1a29755ef10fc1a1450d96dc23495970" --header="Ac
cept: application/json"
--2016-09-04 21:50:08--  https://api.sparkpost.com/api/v1/message-events?events=
bounce,out_of_band
Resolving api.sparkpost.com (api.sparkpost.com)... 54.69.65.44, 54.191.102.120, 
52.40.18.107
Connecting to api.sparkpost.com (api.sparkpost.com)|54.69.65.44|:443... connecte
d.
HTTP request sent, awaiting response... 200 OK
Length: 195529 (191K) [application/json]
Saving to: ‘message-events?events=bounce,out_of_band’

100%[======================================>] 195,529      101KB/s   in 1.9s

2016-09-04 21:50:18 (101 KB/s) - ‘message-events?events=bounce,out_of_band’ save
d [195529/195529]

$

I.e., you will get a "200 OK" message rather than a "403 Forbidden" message.

If you want to specify an output file name of your own choosing, include a -o option following it by the file name you wish to use for the output.

$ wget https://api.sparkpost.com/api/v1/message-events?events=bounce,out_of_band
 --header="Authorization: d12cc66a1a29755ef10fc1a1450d96dc23495970" --header="Ac
cept: application/json"  -o message-events_last_hour.txt

$

You will see output similar to what is stored in message-events_last_hour.txt

 

TechRabbit ad 300x250 newegg.com

Justdeals Daily Electronics Deals1x1 px