const hubspot = require('@hubspot/api-client');
const hubspotClient = new hubspot.Client({"apiKey":"YOUR_HUBSPOT_API_KEY"});
const properties = {
"conversation_dashboard": "test_object1"
};
const SimplePublicObjectInput = { properties };
const objectType = "2-104812028";
try {
const apiResponse = await hubspotClient.crm.basicApi.create(objectType, SimplePublicObjectInput);
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)
}
When we try to run this code we get the following error:
ERROR TypeError: Cannot read property 'create' of undefined
Can someone help us with his? (in NODE local it seems to work fine)
Hi @Wiljekoffie, Thanks for reaching out!
Can you help me understand what you’re trying to do with this custom code action?
We would like to create a new custom object based on a closed conversation.
Hi Wiljekoffie,
The endpoint
hubspotClient.crm.basicApi.create
does not seem to work as indicated in the api documentation (Accounts Dashboard | HubSpot). I get the same error. Intead of using the wrapped endpoint form of the hubspotClient, use the unwrapped endpoint form of the hubspotClient (GitHub - HubSpot/hubspot-api-nodejs: HubSpot API NodeJS Client Libraries for V3 version of the API · GitHub -scroll down to the section “No wrapped endpoint(s)”), like so:
const hubspotClient = new hubspot.Client({"apiKey":"YOUR_HUBSPOT_API_KEY"});
const properties = {
"conversation_dashboard": "test_object1"
};
const SimplePublicObjectInput = { properties };
const objectType = "2-104812028";
try {
const apiResponse = await hubspotClient.apiRequest({
method: "POST",
path: `/crm/v3/objects/${objectType}`, // Use backsticks for interpolation
body: SimplePublicObjectInput
});
console.log(apiResponse.body);
} catch(err){
console.error(err);
throw err;
}
In addition to the hubspotClient, you could also use axios for the request, like so:
const axios = require('axios');
const properties = {
"conversation_dashboard": "test_object1"
};
const SimplePublicObjectInput = { properties };
const objectType = "2-104812028";
//Use backsticks (`) for interpolating the objectType and the api key
axios.post(`https://api.hubapi.com/crm/v3/objects/${objectType}?hapikey=${process.env.key}`, SimplePublicObjectInput)
.then(resp => {
console.log(resp.data)
}).catch(err => {
console.log(err);
throw err;
});
The two above methods work.
