<?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: 400 Response on contact update endpoint. in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/400-Response-on-contact-update-endpoint/m-p/760906#M61709</link>
    <description>&lt;P&gt;Hi SMarquez,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I solved this by forgoing the HubSpot package and using PHP curl functions instead. This is my implementation for updating contacts:&lt;/P&gt;&lt;LI-CODE lang="php"&gt;function update_contact( $contact_id, $properties, $subscribed )
    {
$params = json_encode(
            [
                'properties' =&amp;gt; $properties
            ]
        );

        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_URL =&amp;gt; "https://api.hubapi.com/crm/v3/objects/contacts/" . $contact_id,
            CURLOPT_RETURNTRANSFER =&amp;gt; true,
            CURLOPT_ENCODING =&amp;gt; "",
            CURLOPT_MAXREDIRS =&amp;gt; 10,
            CURLOPT_TIMEOUT =&amp;gt; 30,
            CURLOPT_HTTP_VERSION =&amp;gt; CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST =&amp;gt; "PATCH",
            CURLOPT_POSTFIELDS =&amp;gt; $params,
            CURLOPT_HTTPHEADER =&amp;gt; array(
                "Authorization: Bearer " . get_option('hs_api'),
                "accept: application/json",
                "content-type: application/json"
            ),
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);

        curl_close($curl);
}&lt;/LI-CODE&gt;&lt;P&gt;I used curl functions for all updates, subscribes, and unsubscribe interations, as the package just wasn't working. The package does work when using the search api, however.&lt;/P&gt;</description>
    <pubDate>Fri, 24 Feb 2023 19:47:07 GMT</pubDate>
    <dc:creator>kyleffotf</dc:creator>
    <dc:date>2023-02-24T19:47:07Z</dc:date>
    <item>
      <title>400 Response on contact update endpoint.</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/400-Response-on-contact-update-endpoint/m-p/666182#M54884</link>
      <description>&lt;P&gt;I'm using the hubspot-api-php package&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Trying to call the update endpoint&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PATCH
/crm/v3/objects/contacts/{contactId}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what the hubspot developer docs uses as an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;&amp;lt;?php
use HubSpot\Factory;
use HubSpot\Client\Crm\Contacts\ApiException;

$client = Factory::createWithApiKey("YOUR_HUBSPOT_API_KEY");

$properties = [
    "company" =&amp;gt; "Biglytics",
    "email" =&amp;gt; "bcooper@biglytics.net",
    "firstname" =&amp;gt; "Bryan",
    "lastname" =&amp;gt; "Cooper",
    "phone" =&amp;gt; "(877) 929-0687",
    "website" =&amp;gt; "biglytics.net"
];
$SimplePublicObjectInput = new SimplePublicObjectInput(['properties' =&amp;gt; $properties]);
try {
    $apiResponse = $client-&amp;gt;crm()-&amp;gt;contacts()-&amp;gt;basicApi()-&amp;gt;update("433380577", $SimplePublicObjectInput);
    var_dump($apiResponse);
} catch (ApiException $e) {
    echo "Exception when calling basic_api-&amp;gt;update: ", $e-&amp;gt;getMessage();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my implementation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;function update_contact( $contact_id, $properties )
    {
$client = Factory::createWithAccessToken(get_option('hs_api'));

$SimplePublicObjectInput = new SimplePublicObjectInput(['properties' =&amp;gt; $properties]);
        try {
            $apiResponse = $client-&amp;gt;crm()-&amp;gt;contacts()-&amp;gt;basicApi()-&amp;gt;update($contact_id, $SimplePublicObjectInput);
            error_log(print_r($apiResponse,true));
        } catch (ApiException $e) {
            error_log("Exception when calling basic_api-&amp;gt;update: ". $e-&amp;gt;getMessage());
        }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that $properties looks like this when inspected:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; Array
(
    [address] =&amp;gt; 123 Main St
    [address_2] =&amp;gt; P.O. 12
    [city] =&amp;gt; Vancouver
    [email] =&amp;gt; email@example.com
    [firstname] =&amp;gt; Kyle
    [lastname] =&amp;gt; 
    [mobilephone] =&amp;gt; (877) 929-0687
    [province] =&amp;gt; 
    [zip] =&amp;gt; 
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the response:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Exception when calling basic_api-&amp;gt;update: [400] Client error: `PATCH https://api.hubapi.com/crm/v3/objects/contacts/[the contact id]` resulted in a `400 Bad Request` response:
{"status":"error","message":"No properties found to update, please provide at least one.","correlationId":"be4a7ab7-2069 (truncated...)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The endpoint with the same properties and contact id works when using Postman, and also when using the "test call" feature in the API documentation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I doing something wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 19:34:11 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/400-Response-on-contact-update-endpoint/m-p/666182#M54884</guid>
      <dc:creator>kyleffotf</dc:creator>
      <dc:date>2022-07-15T19:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: 400 Response on contact update endpoint.</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/400-Response-on-contact-update-endpoint/m-p/666299#M54894</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/418610"&gt;@kyleffotf&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt; Thanks for reaching out. Let's see if we can get the conversation started —&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/20405"&gt;@himanshurauthan&lt;/a&gt;&amp;nbsp;do you have any PHP magic you can share?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&amp;nbsp; — Jaycee&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 22:33:26 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/400-Response-on-contact-update-endpoint/m-p/666299#M54894</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2022-07-15T22:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: 400 Response on contact update endpoint.</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/400-Response-on-contact-update-endpoint/m-p/694639#M57039</link>
      <description>&lt;P&gt;I have the same error, what is the solution?&lt;/P&gt;</description>
      <pubDate>Sun, 18 Sep 2022 23:48:35 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/400-Response-on-contact-update-endpoint/m-p/694639#M57039</guid>
      <dc:creator>SMarquez</dc:creator>
      <dc:date>2022-09-18T23:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: 400 Response on contact update endpoint.</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/400-Response-on-contact-update-endpoint/m-p/760906#M61709</link>
      <description>&lt;P&gt;Hi SMarquez,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I solved this by forgoing the HubSpot package and using PHP curl functions instead. This is my implementation for updating contacts:&lt;/P&gt;&lt;LI-CODE lang="php"&gt;function update_contact( $contact_id, $properties, $subscribed )
    {
$params = json_encode(
            [
                'properties' =&amp;gt; $properties
            ]
        );

        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_URL =&amp;gt; "https://api.hubapi.com/crm/v3/objects/contacts/" . $contact_id,
            CURLOPT_RETURNTRANSFER =&amp;gt; true,
            CURLOPT_ENCODING =&amp;gt; "",
            CURLOPT_MAXREDIRS =&amp;gt; 10,
            CURLOPT_TIMEOUT =&amp;gt; 30,
            CURLOPT_HTTP_VERSION =&amp;gt; CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST =&amp;gt; "PATCH",
            CURLOPT_POSTFIELDS =&amp;gt; $params,
            CURLOPT_HTTPHEADER =&amp;gt; array(
                "Authorization: Bearer " . get_option('hs_api'),
                "accept: application/json",
                "content-type: application/json"
            ),
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);

        curl_close($curl);
}&lt;/LI-CODE&gt;&lt;P&gt;I used curl functions for all updates, subscribes, and unsubscribe interations, as the package just wasn't working. The package does work when using the search api, however.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2023 19:47:07 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/400-Response-on-contact-update-endpoint/m-p/760906#M61709</guid>
      <dc:creator>kyleffotf</dc:creator>
      <dc:date>2023-02-24T19:47:07Z</dc:date>
    </item>
  </channel>
</rss>

