APIs & Integrations

09459
Membre

Updating data in a custom object via the API

Résolue

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 Solutions acceptées
webdew
Solution
Guide | Partenaire solutions Diamond
Guide | Partenaire solutions Diamond

Updating data in a custom object via the API

Résolue

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.

Voir la solution dans l'envoi d'origine

dennisedson
Solution
Équipe de développement de HubSpot
Équipe de développement de HubSpot

Updating data in a custom object via the API

Résolue

@09459 

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

Voir la solution dans l'envoi d'origine

4 Réponses
09459
Membre

Updating data in a custom object via the API

Résolue

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
Participant

Updating data in a custom object via the API

Résolue

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
Solution
Équipe de développement de HubSpot
Équipe de développement de HubSpot

Updating data in a custom object via the API

Résolue

@09459 

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

webdew
Solution
Guide | Partenaire solutions Diamond
Guide | Partenaire solutions Diamond

Updating data in a custom object via the API

Résolue

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.