SparkPost/php-sparkpost

DELETE by campaign_id doesn't work through the php library

j4m3s opened this issue · 1 comments

j4m3s commented

Issue Summary:

It's not possible to delete scheduled transmissions by campaign_id (as detailed here in the API docs: https://developers.sparkpost.com/api/transmissions/#transmissions-get-retrieve-a-scheduled-transmission) using the php library because the sparkpost API expects the campaign_id to be passed as a query parameter, but the php library provides the payload as body parameters for DELETE requests.

Attempted:

$httpClient = new GuzzleAdapter(new Client());
$sparky = new SparkPost($httpClient, ['key' => '<REDACTED>']);

$payload = ["campaign_id" => 'myCampaign'];

$promise = $sparky->transmissions->delete($payload);
$promise->wait();

Expected Result:

204 response and successful delete of scheduled campaign emails

Actual Result:

PHP Fatal error:  Uncaught GuzzleHttp\Exception\ClientException: Client error: `DELETE https://api.sparkpost.com/api/v1/transmissions/` resulted in a `400 Bad Request` response:
{ "errors": [ { "message": "required query parameter is missing", "description": "query_parameter 'campaign_id' is requi (truncated...)

It's possible to work around this by passing the "?campaign_id=xyz" as the uri into the method:

$promise = $sparky->transmissions->delete('?campaign_id=myCampaign', $payload);

TBH I suspect this might actually be an issue with the API implementation rather than this PHP library, but thought I'd post it here for others' benefit and just in case it's the library that's doing the wrong thing.

Agreed.
I've updated the example in this draft PR here:

$promise = $sparky->transmissions->delete('?campaign_id=white_christmas');

This gives the expected 204 response in my testing.
You don't need a payload on a DELETE request.