APIs & Integrations

SHarde
Participant

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

SOLVE

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.

0 Upvotes
1 Accepted solution
Teun
Solution
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

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

SOLVE

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);



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


View solution in original post

6 Replies 6
Teun
Solution
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

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

SOLVE

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);



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


SHarde
Participant

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

SOLVE

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

0 Upvotes
Teun
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

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

SOLVE

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 🙂



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


Teun
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

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

SOLVE

I'm just going to mention @Jaycee_Lewis here to get the docs updated if I am correct 😁 



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


Jaycee_Lewis
Community Manager
Community Manager

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

SOLVE

Hey, @Teun 🙌 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





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




0 Upvotes
SHarde
Participant

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

SOLVE

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

0 Upvotes