<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do you Update legalConsentOptions or subscriptionTypeId when updating a contact  properties. in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/How-do-you-Update-legalConsentOptions-or-subscriptionTypeId-when/m-p/748320#M60858</link>
    <description>&lt;P&gt;Via the API? I think you have to use the Communication Preferences API for this. I don't think there is a way to do them together. Communication Preferences are linked to email address and not contact ID.&lt;/P&gt;</description>
    <pubDate>Fri, 27 Jan 2023 21:48:44 GMT</pubDate>
    <dc:creator>keithford</dc:creator>
    <dc:date>2023-01-27T21:48:44Z</dc:date>
    <item>
      <title>How do you Update legalConsentOptions or subscriptionTypeId when updating a contact  properties.</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-do-you-Update-legalConsentOptions-or-subscriptionTypeId-when/m-p/748306#M60857</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;'legalConsentOptions'&lt;/SPAN&gt;&lt;SPAN&gt; =&amp;gt; &lt;/SPAN&gt;&lt;SPAN&gt;array&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;'legitimateInterest'&lt;/SPAN&gt;&lt;SPAN&gt; =&amp;gt; &lt;/SPAN&gt;&lt;SPAN&gt;array&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;'value'&lt;/SPAN&gt;&lt;SPAN&gt; =&amp;gt; &lt;/SPAN&gt;&lt;SPAN&gt;true&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;'subscriptionTypeId'&lt;/SPAN&gt;&lt;SPAN&gt; =&amp;gt; &lt;/SPAN&gt;&lt;SPAN&gt;$subscriptionTypeid&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;'legalBasis'&lt;/SPAN&gt;&lt;SPAN&gt; =&amp;gt; &lt;/SPAN&gt;&lt;SPAN&gt;$legal_basis&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;'text'&lt;/SPAN&gt;&lt;SPAN&gt; =&amp;gt; &lt;/SPAN&gt;&lt;SPAN&gt;''&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 27 Jan 2023 21:06:40 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-do-you-Update-legalConsentOptions-or-subscriptionTypeId-when/m-p/748306#M60857</guid>
      <dc:creator>FAko</dc:creator>
      <dc:date>2023-01-27T21:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do you Update legalConsentOptions or subscriptionTypeId when updating a contact  properties.</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-do-you-Update-legalConsentOptions-or-subscriptionTypeId-when/m-p/748320#M60858</link>
      <description>&lt;P&gt;Via the API? I think you have to use the Communication Preferences API for this. I don't think there is a way to do them together. Communication Preferences are linked to email address and not contact ID.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 21:48:44 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-do-you-Update-legalConsentOptions-or-subscriptionTypeId-when/m-p/748320#M60858</guid>
      <dc:creator>keithford</dc:creator>
      <dc:date>2023-01-27T21:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do you Update legalConsentOptions or subscriptionTypeId when updating a contact  properties.</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-do-you-Update-legalConsentOptions-or-subscriptionTypeId-when/m-p/749008#M60911</link>
      <description>&lt;P&gt;Could you guide me on using the communication preference api. crm()-&amp;gt;communicationPreference() not working. What methods do we chain for this?.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 19:14:12 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-do-you-Update-legalConsentOptions-or-subscriptionTypeId-when/m-p/749008#M60911</guid>
      <dc:creator>FAko</dc:creator>
      <dc:date>2023-01-30T19:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do you Update legalConsentOptions or subscriptionTypeId when updating a contact  properties.</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-do-you-Update-legalConsentOptions-or-subscriptionTypeId-when/m-p/749046#M60913</link>
      <description>&lt;P class=""&gt;My class creates $this-&amp;gt;api connection and this method handles subscribing an email address (using PHP).&amp;nbsp;Hope this helps.&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;use HubSpot\Client\CommunicationPreferences\Model\PublicUpdateSubscriptionStatusRequest;
use HubSpot\Client\CommunicationPreferences\ApiException as HubSpotApiException;

    public function subscribeByEmail(string $email, string $subscription_id, string $legal_basis, string $legal_basis_explanation): bool {
        try {
            $public_update_subscription_status_request = new PublicUpdateSubscriptionStatusRequest();

            if (in_array($legal_basis, $public_update_subscription_status_request-&amp;gt;getLegalBasisAllowableValues())) {
                $public_update_subscription_status_request-&amp;gt;setEmailAddress($email);
                $public_update_subscription_status_request-&amp;gt;setLegalBasis($legal_basis);
                $public_update_subscription_status_request-&amp;gt;setLegalBasisExplanation($legal_basis_explanation);
                $public_update_subscription_status_request-&amp;gt;setSubscriptionId($subscription_id);

                $response = $this-&amp;gt;api-&amp;gt;communicationPreferences()-&amp;gt;statusApi()-&amp;gt;subscribe($public_update_subscription_status_request);
                if ($response-&amp;gt;getStatus() === 'SUBSCRIBED') {
                    $this-&amp;gt;return['success'] = true;
                    $this-&amp;gt;return['message'] = '';
                } else {
                    $this-&amp;gt;return['success'] = false;
                    $this-&amp;gt;return['message'] = "Subscribe returned a status of " . $response-&amp;gt;getStatus();
                }
            } else {
                $this-&amp;gt;return['success'] = false;
                $this-&amp;gt;return['message'] = "Legal basis ({$legal_basis}) is invalid.";
            }
        } catch (HubSpotApiException $e) {
            if ($e-&amp;gt;getCode() == 400) {
                if (strpos($e-&amp;gt;getMessage(), 'already subscribed') !== false) {
                    $this-&amp;gt;return['success'] = true;
                    $this-&amp;gt;return['message'] = "Email ({$email}) already subscribed to {$subscription_id}.";
                } elseif (strpos($e-&amp;gt;getMessage(), 'cannot be updated because they have unsubscribed') !== false) {
                    $this-&amp;gt;return['success'] = false;
                    $this-&amp;gt;return['message'] = "Cannot resubscribe ({$email}) to {$subscription_id}.";
                } else {
                    throw new ApiException($e-&amp;gt;getMessage(), $e-&amp;gt;getCode(), $e-&amp;gt;getResponseHeaders(), $e-&amp;gt;getResponseBody(), $e);
                }
            } elseif ($e-&amp;gt;getCode() == 404 &amp;amp;&amp;amp; strpos($e-&amp;gt;getMessage(), 'does not exist') !== false) {
                $this-&amp;gt;return['success'] = false;
                $this-&amp;gt;return['message'] = "Subscription ID {$subscription_id} does not exist.";
            } else {
                throw new ApiException($e-&amp;gt;getMessage(), $e-&amp;gt;getCode(), $e-&amp;gt;getResponseHeaders(), $e-&amp;gt;getResponseBody(), $e);
            }
        }
        return $this-&amp;gt;return['success'];
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 20:18:32 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-do-you-Update-legalConsentOptions-or-subscriptionTypeId-when/m-p/749046#M60913</guid>
      <dc:creator>keithford</dc:creator>
      <dc:date>2023-01-30T20:18:32Z</dc:date>
    </item>
  </channel>
</rss>

