APIs & Integrations

NFortin
Member

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

SOLVE

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.

0 Upvotes
1 Accepted solution
NFortin
Solution
Member

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

SOLVE

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.

View solution in original post

0 Upvotes
2 Replies 2
NFortin
Solution
Member

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

SOLVE

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.

0 Upvotes
Teun
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

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

SOLVE

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.



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


0 Upvotes