# Setting OPT-IN via API

**URL:** <https://community.hubspot.com/t/setting-opt-in-via-api/30598>\
**Category:** APIs & Integrations\
**Tags:** professional\
**Created:** [January 21, 2021, 9:21pm UTC](https://community.hubspot.com/t/setting-opt-in-via-api/30598 "2021-01-21T21:21:57Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![BusinessLanding](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/businesslanding/32/30597_2.png) [@BusinessLanding](https://community.hubspot.com/u/BusinessLanding)\
**Post date:** [January 21, 2021, 9:21pm UTC](https://community.hubspot.com/t/setting-opt-in-via-api/30598/1 "2021-01-21T21:21:57Z")

</div>

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](https://legacydocs.hubspot.com/docs/methods/email/update_status) but this appears to have no effect at all.
4. We tried the [POST /communication-preferences/v3/subscribe v3 API call](https://developers.hubspot.com/docs/api/marketing-api/subscriptions-preferences) 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?

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [January 25, 2021, 5:29pm UTC](https://community.hubspot.com/t/setting-opt-in-via-api/30598/2 "2021-01-25T17:29:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![zwolfson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zwolfson/32/81360_2.png) [@zwolfson](https://community.hubspot.com/u/zwolfson)\
**Post date:** [February 5, 2021, 7:16pm UTC](https://community.hubspot.com/t/setting-opt-in-via-api/30598/3 "2021-02-05T19:16:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BusinessLanding](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/businesslanding/32/30597_2.png) [@BusinessLanding](https://community.hubspot.com/u/BusinessLanding)\
**Post date:** [February 10, 2021, 4:43pm UTC](https://community.hubspot.com/t/setting-opt-in-via-api/30598/4 "2021-02-10T16:43:07Z")

</div>

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:

 ![37811iAB0C7E9047282928.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/c/0/c0f020222b1b83c6d13e7a92b3c698e5b080b6d4.png)

Is this possible from the API?

---

<div class="post-metadata">

**Author:** ![zwolfson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zwolfson/32/81360_2.png) [@zwolfson](https://community.hubspot.com/u/zwolfson)\
**Post date:** [March 15, 2021, 9:47pm UTC](https://community.hubspot.com/t/setting-opt-in-via-api/30598/5 "2021-03-15T21:47:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BusinessLanding](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/businesslanding/32/30597_2.png) [@BusinessLanding](https://community.hubspot.com/u/BusinessLanding)\
**Post date:** [March 17, 2021, 12:44pm UTC](https://community.hubspot.com/t/setting-opt-in-via-api/30598/6 "2021-03-17T12:44:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![softway](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/softway/32/20791_2.png) [@softway](https://community.hubspot.com/u/softway)\
**Post date:** [June 27, 2023, 1:14pm UTC](https://community.hubspot.com/t/setting-opt-in-via-api/30598/7 "2023-06-27T13:14:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BusinessLanding](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/businesslanding/32/30597_2.png) [@BusinessLanding](https://community.hubspot.com/u/BusinessLanding)\
**Post date:** [August 23, 2023, 6:45pm UTC](https://community.hubspot.com/t/setting-opt-in-via-api/30598/8 "2023-08-23T18:45:23Z")

</div>

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 [GitHub - HubSpot/hubspot-api-ruby: HubSpot API Ruby Client Libraries for V3 version of the API · GitHub](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

---

<div class="post-metadata">

**Author:** ![BusinessLanding](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/businesslanding/32/30597_2.png) [@BusinessLanding](https://community.hubspot.com/u/BusinessLanding)\
**Post date:** [February 10, 2021, 6:24pm UTC](https://community.hubspot.com/t/setting-opt-in-via-api/30598/9 "2021-02-10T18:24:43Z")

</div>

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%BCber-API/m-p/356790/highlight/true#M325](https://community.hubspot.com/t5/Fragen-Tipps-bew%C3%A4hrte-Methoden/Setzen-von-Double-Opt-In-%C3%BCber-API/m-p/356790/highlight/true#M325)

---

<div class="post-metadata">

**Author:** ![hossi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/hossi/32/39641_2.png) [@hossi](https://community.hubspot.com/u/hossi)\
**Post date:** [March 17, 2021, 1:18pm UTC](https://community.hubspot.com/t/setting-opt-in-via-api/30598/10 "2021-03-17T13:18:26Z")

</div>

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-with-GDPR-options/m-p/419435](https://community.hubspot.com/t5/APIs-Integrations/Opting-out-of-email-subscription-via-forms-API-with-GDPR-options/m-p/419435)

---

<div class="post-metadata">

**Author:** ![zwolfson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zwolfson/32/81360_2.png) [@zwolfson](https://community.hubspot.com/u/zwolfson)\
**Post date:** [April 2, 2021, 8:27pm UTC](https://community.hubspot.com/t/setting-opt-in-via-api/30598/11 "2021-04-02T20:27:33Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![BusinessLanding](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/businesslanding/32/30597_2.png) [@BusinessLanding](https://community.hubspot.com/u/BusinessLanding)\
**Post date:** [August 17, 2021, 11:41am UTC](https://community.hubspot.com/t/setting-opt-in-via-api/30598/12 "2021-08-17T11:41:23Z")

</div>

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?
