Skip to content
Advertisement

Mailchimp API ‘marketing_permissions’ field always fails validation with “This value should be of type array”

Using the DrewM Mailchimp API PHP wrapper I’m attempting to POST a subscriber and declare a value for the marketing_permissions field at the same time, but the Mailchimp API response is insisting that the value I’m providing for the marketing_permissions field is not an array.

But it is most certainly an array, as illustrated here:

$params = [
        'email_address' => $email,
        'status' => 'subscribed',
        'merge_fields' => [
            'STATUS' => $status,
            'FNAME' => $first_name,
            'LNAME' => $last_name,
            'JOBTITLE' => $title,
            'COMPANY' => $company,
            'PHONE' => $phone,
            'AGENCY' => $agency,
            'MESSAGE' => $message
        ],
        'marketing_permissions' => [
            [
                'marketing_permission_id' => '1234567890',
                'enabled' => true
            ]
        ]
    ];

    $subscriptionResult = $MailChimp->post('lists/1234567890/members', $params);

And the response I’m getting from the MC API is:

Array
(
    [type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/
    [title] => Invalid Resource
    [status] => 400
    [detail] => The resource submitted could not be validated. For field-specific details, see the 'errors' array.
    [errors] => Array
        (
            [0] => Array
                (
                    [field] => marketing_permissions
                    [message] => This value should be of type array
                )

        )

)

Anyone have any idea why the MC API won’t accept my array as an array?

Advertisement

Answer

It should look like this

marketing_permissions: [
    {
        'marketing_permission_id': '123123',
        'enabled': true
    }
]

interesting to get your marketing_permission_id you need to subscribe to the list via API and check response, there will be this unique id

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement