APIs & Integrations

TKrause
Membro

Hubspot Update Contact Email Subscriptions

I'm trying to update a contact's email subscriptions here's the code that I'm using....

 

$url = 'https://api.hubapi.com/email/public/v1/subscriptions/THE EMAIL?hapikey=API KEY HERE';

$data = array(
"subscriptionStatuses" => array(
array(
"id" => THE ID OF THE EMAIL SUBSCRIPTION LIST,
"subscribed" => true,
"optState" => "OPT_IN",
"legalBasis" => "LEGITIMATE_INTEREST_PQL",
"legalBasisExplanation" => "They signed up via a contact form from the Website"
)
),
"portalSubscriptionLegalBasis" => "LEGITIMATE_INTEREST_PQL",
"portalSubscriptionLegalBasisExplanation" => "They signed up via a contact form from the Website"
);

$cher = curl_init();
curl_setopt($cher, CURLOPT_POST, true); 
curl_setopt($cher, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($cher, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($cher, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($cher, CURLOPT_RETURNTRANSFER, true);
$responser = curl_exec($cher);
curl_close($cher);
echo $put_json;
var_dump($responser);

 

The response that I'm getting is just 

bool(false)

 

Any idas how to resolve this issue?  Or get a response back that I can work with?

0 Avaliação positiva
1 Resposta 1
JPanama
Moderador da HubSpot
Moderador da HubSpot

Hubspot Update Contact Email Subscriptions

Hi @TKraus

 

Thanks for getting in touch. Can you confirm which method you're using? This endpoint requires PUT. Also, can you confirm you're pulling the SubscriptionID using this method? 

 

Best, 
Joe (HubSpot Moderator)