Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'marketing_permissions' field always fails validation with "This value should be of type array" #299

Open
AJB99 opened this issue Jun 26, 2020 · 1 comment

Comments

@AJB99
Copy link

AJB99 commented Jun 26, 2020

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?

@stefantalen
Copy link

stefantalen commented Oct 8, 2020

According to the documentation, marketing_permissions should contain an array of objects.

Looks like you are sending an array of arrays.

Edit: Just came across this myself. Here is a nice fix:

$mailchimp->post('lists/1234567890/members', [
    'email_address'         => $email,
    'status'                => 'subscribed',
    'marketing_permissions' => [
        (object)['marketing_permission_id' => '1234567890', 'enabled' => true],
        (object)['marketing_permission_id' => '2345678901', 'enabled' => true],
        (object)['marketing_permission_id' => '3456789012', 'enabled' => true],
    ]
]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants