Search code examples
sparkpost

SparkPost API suppression-list returning "Method not allowed"


I am trying to insert an entry into the Suppression List described here

I have tried this on my end, using PHP code, but I also get the same response using their own console on the provided website using a valid API key having the same result.

This is the call:

PUT https://api.sparkpost.com/api/v1/suppression-list/email@gmail.com

This is the Request:

Content-Type: application/json
Authorization: XXXXXXXXXXXXX
Content-Length: 142
{
  "transactional": false,
  "non_transactional": true,
  "description": "User requested to not receive any non-transactional emails."
}    

This is the response I am getting from the server:

connection: keep-alive
x-apiary-transaction-id: 5638e31d13b31d0700ae2b0a
cache-control: no-cache, no-store
content-type: application/json; charset=utf-8
date: Tue, 03 Nov 2015 16:38:54 GMT
server: msys-http
content-length: 45
x-newrelic-app-data: PxQDVFVRCQITVlZRDgcFV0YdFHYaFhEHQxFSERdoYWYcShNDHVEdUlIEG1FIVgsFBFxSVg8IG0RQBBQfQFdQVAFWWlsBXVdTUVcPURNNVQMIRVI8
via: 1.1 vegur
{
  "errors": [
    {
      "message": "Method Not Allowed"
    }
  ]
}   

Solution

  • When you add entires to the suppression list you need to PUT them to https://api.sparkpost.com/api/v1/suppression-list and the body of the request needs to be like this:

    {
      "recipients": [
        {
          "email": "rcpt_1@example.com",
          "transactional": true,
          "description": "User requested to not receive any transactional emails."
        },
        {
          "email": "rcpt_2@example.com",
          "non_transactional": true
        }
      ]
    }
    

    The API documentation for this endpoint is at https://www.sparkpost.com/api#/reference/suppression-list/bulk-insertupdate/insert-or-update-list-entries

    As a side note you should make sure not to post the Authorization header in your questions in the future. That's your API key - I'd recommend deleting that key and creating a new one.