Updating data in a custom object via the API

SOLVE
09459
Member

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!



0 Upvotes
2 Accepted solutions

Accepted Solutions
webdew
Solution
Top Contributor | Diamond Partner

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.

View solution in original post

0 Upvotes
dennisedson
Solution
Community Manager

@09459 

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

Thanks,

Dennis




Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content

View solution in original post

3 Replies 3
webdew
Solution
Top Contributor | Diamond Partner

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.

View solution in original post

0 Upvotes
dennisedson
Solution
Community Manager

@09459 

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

Thanks,

Dennis




Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content

View solution in original post

09459
Member

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.


0 Upvotes