APIs & Integrations

BusinessLanding
Participant

Setting OPT-IN via API

We are having trouble setting the OPT-IN status of  contacts in clients Hubspot account. The documentation between V1 and V3 API does not seem consistant:

 

  1. We use the API to create a HubSpot contact from our back-end system (OK)
  2. At this point the contact cannot be sent any emails from, for example, HubSpot dashboard as the OPT-IN is not set and we have GDPR enabled. We tested and could manually set the opt-in via the dashboard & could then send emails to contact.
  3. We tried the v1 API call to set OPT-IN but this appears to have no effect at all.
  4. We tried the POST /communication-preferences/v3/subscribe v3 API call to subscribe and with a :legalBasis and this correctly updates the contact record. However we still cannot send an email from the dashboard unless we first mainally set the OPT-IN status.

Is this the correct precedure as it seems like we are missing a v3 API call to set the general status of contact to OPT-IN?

0 Upvotes
11 Replies 11
zwolfson
HubSpot Employee
HubSpot Employee

Setting OPT-IN via API

@hossi and @BusinessLanding 

I was able to do some testing and confirmed with the team that double opt and GDPR subscriptions are seperate concepts. You cannot set double opt-in via the API. If a contact is created via the Form Submissions API, they can then receive the dobule opt-in email. 

-Zack

0 Upvotes
BusinessLanding
Participant

Setting OPT-IN via API

This is a means that Europeayn websites cannot be used to register opted-in subsribers on Hubspot. This seems to be a significant omission. Is there a plan to provide a solution? Is there a suggested work-around?

0 Upvotes
hossi
Member

Setting OPT-IN via API

It seems I am not the only one having challenges using the API when GDPR options are enabled. I just opened an issue regarding the form submit API. https://community.hubspot.com/t5/APIs-Integrations/Opting-out-of-email-subscription-via-forms-API-wi...

BusinessLanding
Participant

Setting OPT-IN via API

Interestingly a related post has just poped up below this thread, it's in German but it seems to suggest that what we are trying to do via the API is impossible:

 

https://community.hubspot.com/t5/Fragen-Tipps-bew%C3%A4hrte-Methoden/Setzen-von-Double-Opt-In-%C3%BC...

zwolfson
HubSpot Employee
HubSpot Employee

Setting OPT-IN via API

Hi @BusinessLanding ,

 

Could you share an example of a contact who should be opted in to receive and email and the email you are attempting to send them?  I'm not able to reproduce the behavior you describe.  Some things to note for the sake of being thorough.

  • V3 API is definitely the way to go for GDPR enabled accounts
  • Make sure the subscription ID you've opted them into matches the subscription type for the email you are trying to send.
  • If this is a sales email, there is a special subscription type for that called One To One
  • You can get the ids of all the subscriptions in your account from `/communication-preferences/v3/definitions`

Feel free to direct message me any links or request examples you don't feel comfortable posting here.

 

Thanks,
Zack
 

0 Upvotes
BusinessLanding
Participant

Setting OPT-IN via API

Thanks.  Before I try that again I want to make sure we are talking about the same thing:

 

We want to use the API set the opt-in (or even double opt-in) for all current subscriptions. We don't want manual intervention from the dashboard and we want to avoid this:

 

hubspot-double-opt-in.png

 

Is this possible from the API?

 

0 Upvotes
zwolfson
HubSpot Employee
HubSpot Employee

Setting OPT-IN via API

Hi @BusinessLanding so sorry for the very late reply.  Opting your contacts into all current subsciption types is definitely possible via the API. 

 

I need to confirm with others intnerally on how having double opt-in impacts this. I don't believe that it's possible to set a contact as dobule opt in confirmed through the API but I need to confirm that. 

0 Upvotes
BusinessLanding
Participant

Setting OPT-IN via API

Thanks, we are making some progress,. To quote you, it seems that the key question is this:

 


I don't believe that it's possible to set a contact as dobule opt in confirmed through the API but I need to confirm that. 

We'd very much appreciete is you could clarify this as soon as possible.

softway
Member

Setting OPT-IN via API

Hi, have you reached any conclusion as to how to create/update a contact via API and HS sending opt-in email confirmation?

BusinessLanding
Participant

Setting OPT-IN via API

Sorry for the late reply, but yes, we did eventually get it working (without help from Hubspot).

 

Basically you need to get all the subscription IDs, then explicity opt-in to each subscription. We used API V3, Ruby and https://github.com/HubSpot/hubspot-api-ruby

 

So you will have something like this:

 

body = {
  emailAddress: self.email,
  subscriptionId: subscription_id,
  legalBasis: "CONSENT_WITH_NOTICE",
  legalBasisExplanation: "#{reason} on #{Time.now}}"
}

begin
  api_response =         api_client.communication_preferences.status_api.subscribe(body: body)

 

rescue Hubspot::CommunicationPreferences::ApiError => e
#
# Error may be caused because the contact is already

# subscribed. The API does not return a specific error code

 

 

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Setting OPT-IN via API

Hello @BusinessLanding 

Apologies for delayed response 😅

I am going to test this in my account and see if I have same issue.

@MatthewShepherd , @tjoyce , have you all encountered this before?

0 Upvotes