APIs & Integrations

09459
Miembro

Updating data in a custom object via the API

resolver

Hi,

 

We've created a custom object in our hubspot instance and have figured out how to post new records into that custom object through the API. All good so far. 

 

However, what I'm not able to figure out is how I would update a specific database record within the custom object. Is this possible? We want to how this custom object mirror a table in a third party system and the data in the table will need to be updated via the API to make this possible.

Is this possible? If not, is it possible to DELETE specific records in the custom object via the API? It's not optimal, but if I could delete a specific record in the custom object database via the API, I could then I could recreate it.
 Any assistance that you could provide would be greatly appreciated.

Thanks!



2 Soluciones aceptadas
webdew
Solución
Guía | Partner nivel Diamond
Guía | Partner nivel Diamond

Updating data in a custom object via the API

resolver

Hi @09459 ,

Hope this code helps:

<?php
$args['url'] = 'https://api.hubapi.com/crm/v3/objects/<ObjectTypeId>/<ObjectId>?hapikey=xxxxx;
$args['data']= json_encode([
"properties" =>
[
"propertyName" =>'propertyValue'
]
]);

// patch
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $args['url']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');

curl_setopt($ch, CURLOPT_POSTFIELDS, $args['data']);

$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Accept: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$result = json_decode($result);


Hope this helps!


If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.

Ver la solución en mensaje original publicado

dennisedson
Solución
Equipo de producto de HubSpot
Equipo de producto de HubSpot

Updating data in a custom object via the API

resolver

@09459 

We did a small video series on custom objects that may help.  Check them out here

Ver la solución en mensaje original publicado

4 Respuestas 4
09459
Miembro

Updating data in a custom object via the API

resolver

Thank you Dennis. I'm watched the video and created a Unique ID that macthing the primary ket in the table in 3rd party system. Is it now possible to update the record in the custom object using the new Unique ID from the external system?  I've verified that a POST gives a duplicate error and that neither PUT or PATCH are supported (at least to the same endpoint as the POST). I'm trying to avoid having to store the rowID of the custom object record in my third party database if possible.


rtessler
Participante

Updating data in a custom object via the API

resolver

I confirm neither PATCH or PUT works when trying to update custom object data in postman or python. Also when using POST as I did when initially creating the records, all records are rejected with error, Duplicate Unique Property Value. There seems to be no way to update the records. This behaviour is different for hubspot standard objects like contacts which allow updates through the API

dennisedson
Solución
Equipo de producto de HubSpot
Equipo de producto de HubSpot

Updating data in a custom object via the API

resolver

@09459 

We did a small video series on custom objects that may help.  Check them out here

webdew
Solución
Guía | Partner nivel Diamond
Guía | Partner nivel Diamond

Updating data in a custom object via the API

resolver

Hi @09459 ,

Hope this code helps:

<?php
$args['url'] = 'https://api.hubapi.com/crm/v3/objects/<ObjectTypeId>/<ObjectId>?hapikey=xxxxx;
$args['data']= json_encode([
"properties" =>
[
"propertyName" =>'propertyValue'
]
]);

// patch
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $args['url']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');

curl_setopt($ch, CURLOPT_POSTFIELDS, $args['data']);

$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Accept: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$result = json_decode($result);


Hope this helps!


If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.