HubSpot / hubspot-php

HubSpot PHP API Client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error creating or updating contact using old API

whiterook6 opened this issue · comments

We need to create or update a user in our codebase and we use the old Hubspot PHP API, though we use a private app for authentication.

The code we're running is this:

$client = Factory::createWithOAuth2Token( getenv( 'HUBSPOT_PRIVATE_APP_KEY' ), null, [
	'http_errors' => false
] );

// ...

$formatted_properties = array_map( function ( HubspotProperty $property, $value ) {
	return [
		'property' => $property->get_name(),
		'value'    => $value
	];
}, $properties, array_keys( $properties ) );
error_log(print_r($formatted_properties, true));
$client->contacts()->createOrUpdate(
	$user->user_email,
	$formatted_properties
);

We get this error when submitting the API call:

Screen Shot 2023-01-25 at 1 47 35 PM

When printing the contents of $formatted_properties, we get this:

Array
(
    [0] => Array
        (
            [property] => company_name
            [value] => g
        )

    [1] => Array
        (
            [property] => slack_channel
            [value] => f
        )

    [2] => Array
        (
            [property] => new_customer_report_url
            [value] => h
        )

)

Any ideas? It seems like it's not sending a POST body correctly, but I can't figure out why.

commented

Hi @whiterook6 .
What version of the SDK do you use?
On my local machine it works correctly (the SDK version 5.0.1).

$client = Factory::createWithOAuth2Token('*');


$formatted_properties = [
    [
        'property' => 'company',
        'value' => 'g'
    ],
    [
        'property' => 'slack_channel',
        'value' => 'f'
    ],
    [
        'property' => 'new_customer_report_url',
        'value' => 'h'
    ],
];

$client->contacts()->createOrUpdate(
	'test.legacy@exapmle.com',
	$formatted_properties
);