3

I am sending emails via SendGrid with this inside the x-smtpapi header

$json_string = array(
    'unique_args' => array (
        'email_id' => 1
    )
);

It all seems to send okay, inside SendGrid I can view the "email_id" in the Email activity under Unique Args.

However when I try to use the API to look at this email, I cannot find a way to actually get these unique arguments from the API.

I am using this to try and get the headers returned with the bounced emails.

$request = 'https://api.sendgrid.com/api/bounces.get.json&api_user=username&api_key=password'

All I get is just the email addresses that have bounced, not the header information (the unique arguments)

I want to know, is it possible to get the unique arguments from the API. I have read it multiple times to no avail.

I hope this makes sense. Thanks

Mad Angle
  • 2,347
  • 1
  • 15
  • 33
baihu
  • 451
  • 1
  • 4
  • 16
  • read this:http://stackoverflow.com/questions/16639580/sendgrid-unique-arguments-with-individual-emails?rq=1 – jbutler483 Aug 29 '14 at 11:25
  • ^ doesn't really answer my question on how you can return email headers/unique_args from an API call. – baihu Aug 29 '14 at 11:32

1 Answers1

2

At present there's no way request to lookup specific events by unique_arg with the Web API.

However, the SendGrid Event Webhook will give you granular data on each event, such as a bounce as it happens. The Event Webhook POSTs data to your server every time an action is taken upon an email (e.g. open, click, bounce).

Once you receive it, you're responsible for storing this, although it's not a typical API it gives very specific data on events which you can then compile and rehash however you like.

To get started using the webhook, you'll do something like the following, and have SendGrid POST to the following script:

<?php
$data = file_get_contents("php://input");
$events = json_decode($data, true);

foreach ($events as $event) {
  // Here, you now have each event and can process them how you like
  process_event($event);
}

[Taken from the SendGrid Webhook Code Example]

Nick Q.
  • 3,947
  • 2
  • 23
  • 37