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".
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