Retrieve my entire suppression list from Sparkpost

220 views Asked by At

I hope someone can give me some guidance and maybe an example.
I can't seem to find a way to do this. I need to retrieve my entire suppression list from Sparkpost using C#.

I have searched all over and all I have found is what's on the API C# reference page which is:

var client = new Client("MY_API_KEY");

client.Suppressions.List(); // returns a list of

client.Suppressions.List(new { limit = 3 }); // it accepts an anonymous type for filters

client.Suppressions.List(new SuppressionQuery()); // a SuppressionQuery is also allowed for typed help

But it gives no instructions as to how to use this. Does anyone have the code in C# to retrieve the entire suppression list?

Thanks in advance, Sam

1

There are 1 answers

1
Yepher On

I do not have a C# specific example but I think this should get you up and running. This is the SparkPost API you need https://developers.sparkpost.com/api/suppression-list/

If language is not super important and just looking for the easiest way to pull the list have a look here: https://www.sparkpost.com/docs/tech-resources/download-suppression-list/

... Or my pal tuck1s has this great example in Python: https://github.com/tuck1s/sparkySuppress

You will need to change $SPARKPOST_API_KEY to your API key for this.

Use this to get a summary of your suppression lists

curl -v -H "Content-Type: application/json" -H "Authorization: $SPARKPOST_API_KEY" -X GET "https://api.sparkpost.com/api/v1/suppression-list/summary"

You can do this to get your suppression list records

curl -v \
-H "Content-Type: application/json" \
-H "Authorization: $SPARKPOST_API_KEY" \
-X GET "https://api.sparkpost.com/api/v1/suppression-list?sources=Bounce+Rule,Manually+Added"

Here are the sources you can pull the suppressions for:

  • Bounce Rule
  • Compliance
  • List Unsubscribe
  • Manually Added
  • Spam Complaint
  • Unsubscribe Link

That will produce results like this

{
"results": [
    {
        "recipient": "[email protected]",
        "type": "transactional",
        "source": "Manually Added",
        "description": "MBL: [email protected],hard-bounce,\"smtp;550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces. Learn more at https://support.google.com/mail/answer/",
        "created": "2020-10-23T18:50:07+00:00",
        "updated": "2020-10-23T18:50:07+00:00",
        "transactional": true
    },
    {
        "recipient": "[email protected]",
        "type": "transactional",
        "source": "Manually Added",
        "description": "MBL: [email protected],hard-bounce,\"smtp;550 5.1.10 RESOLVER.ADR.RecipientNotFound; Recipient not found by SMTP address lookup\",\"2015-12-18 17:49:49.74724\",\"2016-01-28 19:44:39\",\"2016-01-14 19:44:39.83638\",\"2016-01-28 19:44:39\",",
        "created": "2020-10-23T18:50:07+00:00",
        "updated": "2020-10-23T18:50:07+00:00",
        "transactional": true
    }
],
"links": [
    {
        "href": "/api/v1/suppression-list?page=2&sources=Bounce Rule,Manually Added&per_page=1000",
        "rel": "next"
    },
    {
        "href": "/api/v1/suppression-list?page=10&sources=Bounce Rule,Manually Added&per_page=1000",
        "rel": "last"
    }
],
"total_count": 1111578

}

To get the next page of results just follow the URI sent in /links/href

Here is a C# example as produced by PostMan for the above Curl command

var client = new RestClient("https://api.sparkpost.com/api/v1/suppression-list?sources=Bounce+Rule,Manually+Added");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "SPARKPOST_API_KEY");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);