campaignmonitor / createsend-php

A PHP library for the Campaign Monitor API
http://campaignmonitor.github.io/createsend-php
Other
285 stars 106 forks source link

Failed to deserialize your request #109

Closed mikoop79 closed 3 years ago

mikoop79 commented 3 years ago

getting this error with the following

[{
'response': {
Code: 400,
'Message': "Failed to deserialize your request. Please check the documentation and try again. Fields in error: subscriber"
},
'http_status_code': 400
}]

        $wrap = new \CS_REST_Subscribers($list, ['api_key'=>$key]);

        $response = $wrap->add(array(
            'EmailAddress' => 'test@test.com',
            'Name' => 'Michael',
            'Resubscribe' => 'true',
            'ConsentToTrack' => 'true'
        ));
markstaples commented 3 years ago

Hi @mikoop79 - have you tried looking at the sample code for subscriber add: https://github.com/campaignmonitor/createsend-php/blob/master/samples/subscriber/add.php - maybe 'Resubscribe' => 'true' is a potential issue, try changing it to 'Resubscribe' => true?

mikoop79 commented 3 years ago

thanks @markstaples I tried both which didnt work. But!...... I have solved the issue. 'ConsentToTrack' needs to be 'yes' instead of 'true'.

It is in the samples. https://github.com/campaignmonitor/createsend-php/blob/master/samples/subscriber/add.php

$subscriber = array(
            "EmailAddress" => $user->email,
            'Name' => $user->name,
            "ConsentToTrack" => 'yes'
        );