Hey, @substr
Do you get the same result when you try these requests using Postman?
I recreated your requests using the on-page PHP example for creating a contact and getting a contact by ID. Both worked as expected. Here’s my request and response for both:
Request - POST /crm/v3/objects/contacts
<?php
use HubSpot\Factory;
use HubSpot\Client\Crm\Contacts\ApiException;
use HubSpot\Client\Crm\Contacts\Model\AssociationSpec;
use HubSpot\Client\Crm\Contacts\Model\PublicAssociationsForObject;
use HubSpot\Client\Crm\Contacts\Model\PublicObjectId;
use HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectInputForCreate;
$client = Factory::createWithAccessToken('YOUR_ACCESS_TOKEN');
$associationSpec1 = new AssociationSpec([
'association_category' => 'HUBSPOT_DEFINED',
'association_type_id' => 279
]);
$to1 = new PublicObjectId([
'id' => '9291675216'
]);
$publicAssociationsForObject1 = new PublicAssociationsForObject([
'types' => [$associationSpec1],
'to' => $to1
]);
$properties1 = [
'email' => 'mlewis@biglytics.net',
'phone' => '(877) 929-0686',
'company' => 'Biglytics',
'website' => 'biglytics.net',
'lastname' => 'Lewis',
'firstname' => 'Mango'
];
$simplePublicObjectInputForCreate = new SimplePublicObjectInputForCreate([
'associations' => [$publicAssociationsForObject1],
'properties' => $properties1,
]);
try {
$apiResponse = $client->crm()->contacts()->basicApi()->create($simplePublicObjectInputForCreate);
var_dump($apiResponse);
} catch (ApiException $e) {
echo "Exception when calling basic_api->create: ", $e->getMessage();
}
Response
HTTP 201
{
"id": "2201",
"properties": {
"company": "Biglytics",
"createdate": "2024-02-23T16:45:07.050Z",
"email": "mlewis@biglytics.net",
"firstname": "Mango",
"hs_all_contact_vids": "2201",
"hs_calculated_phone_number": "+18779290686",
"hs_calculated_phone_number_country_code": "US",
"hs_email_domain": "biglytics.net",
"hs_is_contact": "true",
"hs_is_unworked": "true",
"hs_lifecyclestage_lead_date": "2024-02-23T16:45:07.050Z",
"hs_marketable_status": "false",
"hs_marketable_until_renewal": "false",
"hs_object_id": "2201",
"hs_object_source": "INTEGRATION",
"hs_object_source_id": "959085",
"hs_object_source_label": "INTEGRATION",
"hs_pipeline": "contacts-lifecycle-pipeline",
"hs_searchable_calculated_phone_number": "8779290686",
"lastmodifieddate": "2024-02-23T16:45:07.050Z",
"lastname": "Lewis",
"lifecyclestage": "lead",
"phone": "(877) 929-0686",
"website": "http://biglytics.net"
},
"createdAt": "2024-02-23T16:45:07.050Z",
"updatedAt": "2024-02-23T16:45:07.050Z",
"archived": false
}
Request GET /crm/v3/objects/contacts/{contactId}
<?php
use HubSpot\Factory;
use HubSpot\Client\Crm\Contacts\ApiException;
$client = Factory::createWithAccessToken('YOUR_ACCESS_TOKEN');
try {
$apiResponse = $client->crm()->contacts()->basicApi()->getById('2201', false);
var_dump($apiResponse);
} catch (ApiException $e) {
echo "Exception when calling basic_api->get_by_id: ", $e->getMessage();
}
Response
HTTP 200
{
"id": "2201",
"properties": {
"createdate": "2024-02-23T16:45:07.050Z",
"email": "mlewis@biglytics.net",
"firstname": "Mango",
"hs_object_id": "2201",
"lastmodifieddate": "2024-02-23T16:45:55.956Z",
"lastname": "Lewis"
},
"createdAt": "2024-02-23T16:45:07.050Z",
"updatedAt": "2024-02-23T16:45:55.956Z",
"archived": false
}
I hope this helps get you moving forward! — Jaycee