Unable to post data to Custom objects from Workflow using the API

Hello,

I’m trying to post the record to Custom Object from Workflow -- Custom Code Action. I’m using the POST API available here (POST/crm/v3/objects/{objectType}). I’m facing following issue while doing the same:

2022-07-21T06:02:34.925Z	ERROR	TypeError: Cannot read property 'create' of undefined
 at Object.exports.main (/var/task/file.js:26:60)
 at Runtime.exports.hubspot_handler [as handler] (/var/task/hubspotHandler.js:6:21)
 at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)

It seems there is some issue with the API.

Here is my code snippet:

const hubspotClient = new hubspot.Client({
accessToken: process.env.ACCESSTOKEN
});

const properties = {
“id”: 22,
“userId”: 17,
“title”: “Hi there”,
“completed”: true
};
const SimplePublicObjectInput = { properties };
const objectType = “User”;
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)
}

Also, I’m using Oauth token which is already added in Secrets in Custom Code Action.

Any leads to resolve this would be helpful.

@Teun -- Coud you please help here. We had resolved similar kind of issue couple of days back Any leads would be helpful. Thank you!!

Hi @SHarde ,

The docs have to be updated a bit I suppose.

If we look at the contacts endpoint, you can see that the base is a bit different: hubspotClient.crm.contacts.basicApi.create

So based on that, I suppose the basicApi object is not available directly from the CRM object. Based on the Github repo, I think you should try:

const apiResponse = await hubspotClient.crm.objects.basicApi.create(objectType, SimplePublicObjectInput);

I’m just going to mention @Jaycee_Lewis here to get the docs updated if I am correct :grin:

Hey, @Teun :raising_hands: I am going to work with the docs team and submit a request. I may have more questions (I’m always learning) I’ll tag you here if I do!

Talk soon — Jaycee

Hi @Teun ,

This solution worked for me. Could you please share a link wherein I can get all the working endpoints? This is a bit of time consuming to wait for an valid API to implement the required usecase. It would be really helpful if the docs get updated asap since lot of time is invested in getting the valid API.

Thanks for the help here.

Regards,

Swapnil

Hi @SHarde ,

Awesome! Happy it worked.
You can use the GitHub repo as an indication of how to build the endpoint. The discovery folder is the ‘base’. And if you navigate to the crm folder that would you mean you are looking at hubspotClient.crm, if you navigate to the contacts folder, you are looking at hubspotClient.crm.contacts

But I agree, the docs need an update :slightly_smiling_face: