Hey @jpsanchez Thanks for your reply, thanks for your time.
I believe issue is more complex, this was quite dificult to explain maybe, not to post any sensitive data. Lets recap.
I use this to Create Batch of Custom Objects:
POST
/crm/v3/objects/{objectType}/batch/create
Custom object required property in HS instance declared as follow:
prop_one (internal value)
field type: Dropdown select
1 - this might be the issue, because of de-duplication, I thought that first, but Batch Creation takes, as I understand, this under consideration because it is about creating instance custom object in batches like so:
{ "inputs": [
{"properties":{"prop_one":"prop name","prop_two":"5:30"}},
{"properties":{"prop_one":"prop name","prop_two":"6:30"}}] }
de-duplication will fire while prop_two will be the same as I have investigated already:
so response return only one instance of object ( as API thoughts this is duplicate - not ideal, but I can live with this eventually)
code from HS endpoints example:
const BatchInputSimplePublicObjectInput = { inputs: [{"properties":{"prop_one":"prop name","prop_two":"5:30"}},{"properties":{"prop_one":"prop name","prop_two":"5:30"}}] };
const objectType = "2-104078180";
try {
const apiResponse = await hubspotClient.crm.batchApi.create(objectType, BatchInputSimplePublicObjectInput);
console.log(JSON.stringify(apiResponse.body, null, 2));
} catch (e) {
e.message === 'HTTP request failed'
? console.error(JSON.stringify(e.response, null, 2))
: console.error(e)
}
{ "inputs": [
{"properties":{"prop_one":"prop name","prop_two":"5:30"}},
{"properties":{"prop_one":"prop name","prop_two":"5:30"}}
]
}
RES
{
"status": "COMPLETE",
"results": [
{
"id": "252238555",
"properties": {
"hs_createdate": "2022-05-05T09:38:24.863Z",
"hs_lastmodifieddate": "2022-05-05T09:38:24.863Z",
"hs_object_id": "252238555",
"prop_two": "5:30",
"prop_one": "prop name"
},
"createdAt": "2022-05-05T09:38:24.863Z",
"updatedAt": "2022-05-05T09:38:24.863Z",
"archived": false
}
],
"startedAt": "2022-05-05T09:38:24.830Z",
"completedAt": "2022-05-05T09:38:25.084Z"
}
while there is difference with at lease one prop value this will be fine, two instances of the custom object will be created.
const objectType = “2-104078180” - this is my custom objectType id Please find:
Retrieve existing custom objects
To retrieve all custom objects, make a GET request to /crm/v3/schemas.
To retrieve a specific custom object, make a GET request to one of the following endpoints:
/crm/v3/schemas/{objectTypeId}
/crm/v3/schemas/{fullyQualifiedName}. You can find an object’s
fullyQualifiedName in its schema, which is derived from p{portal_id}_{object_name}.
For example, your request URL may look like the following:
https://api.hubapi.com/crm/v3/schemas/2-3465404
Issue here is different nature:
I am not able to define body.param for body input other than hardcoded values using Batch Create API v3 for custom object:
POST
/crm/v3/objects/{objectType}/batch/create
and code that works in endpoint example HS API dev page:
const hubspot = require('@hubspot/api-client');
const hubspotClient = new hubspot.Client({"apiKey":"xxx"});
const BatchInputSimplePublicObjectInput = { inputs: [{"properties":{"prop_one":"prop name","prop_two":"5:30"}},{"properties":{"prop_one":"prop name","prop_two":"6:30"}}] };
const objectType = "2-104078180";
try {
const apiResponse = await hubspotClient.crm.batchApi.create(objectType, BatchInputSimplePublicObjectInput);
console.log(JSON.stringify(apiResponse.body, null, 2));
} catch (e) {
e.message === 'HTTP request failed'
? console.error(JSON.stringify(e.response, null, 2))
: console.error(e)
}
node.js code - does not work in node.js application.
my function App:
the same code from endpoint throw an error:
*** Error throw: “Cannot read property ‘create’ of undefined”
I have worked this around using:
modified code ( while try catch block is handled in AZFunction )
and Not wrapped endpoint(s) recipies of ‘@hubspot/api-client’ package:
async function searchForShiftsbyMonth(context, query, body) {
const hubspot = require('@hubspot/api-client');
const hubspotClient = new hubspot.Client({"apiKey":"xxx"});
let inputBody = { "inputs": [{"properties":{"prop_one":"prop name","prop_two":"5:30"}},
{"properties":
{"prop_one":"prop name","prop_two":"6:30"}}] }
const objectType = "2-104078180";
//also have tried with fullyQualifiedName
//which is derived from p{portal_id}_{object_name}
const result = await hubspotClient.apiRequest({
method: 'POST',
path: `/crm/v3/objects/${objectType}/batch/create?`,
body: inputBody,
});
return result.body;
}
So as you can see I have an Azure Functions that will hit endpoint, and return RES
and this one works.
Issue here - why code rfom copied from HS Guide does work on HS page but in Node.js app throws error?
*** Error throw: “Cannot read property ‘create’ of undefined”
But like I said this was overcome.
What I am not able to figure out is how to code params to be passed as body.params in HTTP POST request:
instead of hardcodding this in the App:
like so
let inputBody = { “inputs”: [
{“properties”:{“prop_one”:“prop name”,“prop_two”:“5:30”}},
{“properties”:{“prop_one”:“prop name”,“prop_two”:“6:30”}}
] }
I would like to be able to change peops making HTTP request, so in code I am lookind for something like that:
let inputBody = { "inputs": [
{"properties":{"prop_one":body.prop_one,"prop_two":body.prop_two}},
{"properties":{"prop_one":body.prop_one,"prop_two":body.prop_two}}
]}
(and yes I am aware of de-duplication as I have mentioned on top of the post)
to be able to create various requests with varions body params passed by another app as body params to this function:
for example in POSTMAN:
{ “inputs”: [
{“properties”:{“prop_one”:“prop name”,“prop_two”:“5:30”}},
{“properties”:{“prop_one”:“prop name”,“prop_two”:“6:30”}}
] }
or
{ “inputs”: [
{“properties”:{“prop_one”:“prop name but different one”,“prop_two”:“8:30”}},
{“properties”:{“prop_one”:“prop name”,“prop_two”:“9:30”}}
] }
but so far I am getting this code errot throws:
*** Error throw: “Cannot create object with type: {fullyQualifiedName of my custom property here} . The following required properties were missing: [prop_one]” “HTTP request failed”
I will appreciate help.
Tanks in advance.