Http error 400 attempting to use $hubspot->emailSubscription()->updateSubscription()

Hi,

I’m trying to use the $hubspot->emailSubscription()->updateSubscription($email_addr,$data) method as documented here from php.

I can get it to work to unsubscribe from all emails by setting data as:-

$data = [“unsubscribeFromAll” => true];

However by requirement is to be able to unsubscribe from a given category by id using:-

$data = [
“subscriptionStatuses” => [
“id” => $MARKETING_SUBS_ID,
“optState” => “OPT_OUT”
]
];

or

$data = [
“subscriptionStatuses” => [
“id” => $MARKETING_SUBS_ID,
“subscribed” => false
]
];

But nothing works, I get error code 400 - Bad request.

Hi @NFortin, Are you sending the data by using CURL? If you JSON encoded your PHP var, what happens if you `print_r` the result? Would you be able to share that output?
There is a big warning in the documentation that tells you that you can not subscribe / unsubscribe a contact that you have unsubscribed before using `[“unsubscribeFromAll” => true];`. Are you testing with another contact? Could be the issue as well.

I was not sending data by CURL, or not directly anyway, but using the methods detailed above. The warning about previously unsubscribed from all did not apply.

I’ve given up on getting that method working, I wonder if its deprecated?

I’m now using this instead - which does work, so I’ve worked around the problem.