APIs & Integrations

Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

Trouble creating instance of custom object

Hey all!
I'm running into an issue when creating an instance of a custom object the API is returning a list of pre-existing instances rather than creating a new instance.
Endpoint:
api.hubapi.com/crm/v3/objects/objectType?hapikey=XXXXXXXXXXXXXX
Body:

 

{
  "type": "Test",
  "value": "a value"
}

 


Response:

 

 

{
    "results": [
        {
            "id": "252344695",
            "properties": {
                "hs_createdate": "2021-07-28T17:49:49.013Z",
                "hs_lastmodifieddate": "2021-07-29T14:23:42.549Z",
                "hs_object_id": "252344695"
            },
            "createdAt": "2021-07-28T17:49:49.013Z",
            "updatedAt": "2021-07-29T14:23:42.549Z",
            "archived": false
        },
        {
            "id": "252344705",
            "properties": {
                "hs_createdate": "2021-07-28T17:59:02.808Z",
                "hs_lastmodifieddate": "2021-07-29T14:23:50.688Z",
                "hs_object_id": "252344705"
            },
            "createdAt": "2021-07-28T17:59:02.808Z",
            "updatedAt": "2021-07-29T14:23:50.688Z",
            "archived": false
        },
        {
            "id": "253086079",
            "properties": {
                "hs_createdate": "2021-07-29T14:15:38.953Z",
                "hs_lastmodifieddate": "2021-07-29T14:55:00.920Z",
                "hs_object_id": "253086079"
            },
            "createdAt": "2021-07-29T14:15:38.953Z",
            "updatedAt": "2021-07-29T14:55:00.920Z",
            "archived": false
        },
        {
            "id": "253086080",
            "properties": {
                "hs_createdate": "2021-07-29T14:16:30.524Z",
                "hs_lastmodifieddate": "2021-07-29T14:23:10.685Z",
                "hs_object_id": "253086080"
            },
            "createdAt": "2021-07-29T14:16:30.524Z",
            "updatedAt": "2021-07-29T14:23:10.685Z",
            "archived": false
        }
    ]
}

 

 

I'm positive Im doing something incorrectly but can't seem to locate it!

 

We are also having issue updating(PATCH) instances. The Patch returns a similar response

 

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
0 Upvotes
3 Replies 3
webdew
Guide | Diamond Partner
Guide | Diamond Partner

Trouble creating instance of custom object

Hi @Kevin-C ,

Hope below code will help for you :

Insert custom object :

$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.hubapi.com/crm/v3/objects/<objectTypeId>?hapikey=demo",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>'{
"properties": {
"<property_name1>":"<property_value1>",
"<property_name2>":"<property_value2>",
"<property_name3>":"<property_value3>",
}
}',
CURLOPT_HTTPHEADER => array(
"accept: application/json",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
$res = json_decode($response);
// will come update code
curl_close($curl);


Update custom object :

$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.hubapi.com/crm/v3/objects/<objectTypeId>/<objectId>?hapikey=demo",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS =>'{
"properties": {
"<property_name1>":"<property_value1>",
"<property_name2>":"<property_value2>",
"<property_name3>":"<property_value3>",
}
}',
CURLOPT_HTTPHEADER => array(
"accept: application/json",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
$res = json_decode($response);
// will come update code
curl_close($curl);

Hope this helps!


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

Thanks and Regards. 

natsumimori
Community Manager
Community Manager

Trouble creating instance of custom object

Hi Kevin😄

I will tag in fellow Community contributors here- @JBeatty and @tjoyce , would you mind sharing your advice for Kevin?

0 Upvotes
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

Trouble creating instance of custom object

Thanks you so much @natsumimori 

 

I was able to get the request working. Soon as I get a chnace to compare my code I'll post the the full solution!

 

But a part of the issue was using Postman and not including the content-length header.

Kevin Cornett - Sr. Solutions Architect @ BridgeRev