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

**URL:** <https://community.hubspot.com/t/unable-to-post-data-to-custom-objects-from-workflow-using-the-api/61402>\
**Category:** APIs & Integrations\
**Tags:** cms-content, workflows\
**Created:** [July 21, 2022, 6:16am UTC](https://community.hubspot.com/t/unable-to-post-data-to-custom-objects-from-workflow-using-the-api/61402 "2022-07-21T06:16:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SHarde](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@SHarde](https://community.hubspot.com/u/SHarde)\
**Post date:** [July 21, 2022, 6:16am UTC](https://community.hubspot.com/t/unable-to-post-data-to-custom-objects-from-workflow-using-the-api/61402/1 "2022-07-21T06:16:49Z")

</div>

Hello,

I’m trying to post the record to Custom Object from Workflow -- Custom Code Action. I’m using the POST API available [here](https://developers.hubspot.com/docs/api/crm/crm-custom-objects) ( **POST** /crm/v3/objects/{objectType}). I’m facing following issue while doing the same:

```auto
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.

---

<div class="post-metadata">

**Author:** ![SHarde](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@SHarde](https://community.hubspot.com/u/SHarde)\
**Post date:** [July 21, 2022, 6:19am UTC](https://community.hubspot.com/t/unable-to-post-data-to-custom-objects-from-workflow-using-the-api/61402/2 "2022-07-21T06:19:32Z")

</div>

@Teun -- Coud you please help here. We had resolved similar kind of [issue](https://community.hubspot.com/t5/APIs-Integrations/Invoke-an-external-GET-API-and-store-the-data-retrieved-from-API/m-p/660296#M54621) couple of days back Any leads would be helpful. Thank you!!

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [July 21, 2022, 6:25am UTC](https://community.hubspot.com/t/unable-to-post-data-to-custom-objects-from-workflow-using-the-api/61402/3 "2022-07-21T06:25:43Z")

</div>

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](https://github.com/HubSpot/hubspot-api-nodejs/tree/master/src/discovery/crm), I think you should try:

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

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [July 21, 2022, 6:26am UTC](https://community.hubspot.com/t/unable-to-post-data-to-custom-objects-from-workflow-using-the-api/61402/4 "2022-07-21T06:26:49Z")

</div>

I’m just going to mention [@Jaycee\_Lewis](https://community.hubspot.com/t5/user/viewprofilepage/user-id/127074) here to get the docs updated if I am correct 😁

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [July 21, 2022, 5:23pm UTC](https://community.hubspot.com/t/unable-to-post-data-to-custom-objects-from-workflow-using-the-api/61402/5 "2022-07-21T17:23:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SHarde](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@SHarde](https://community.hubspot.com/u/SHarde)\
**Post date:** [July 22, 2022, 5:47am UTC](https://community.hubspot.com/t/unable-to-post-data-to-custom-objects-from-workflow-using-the-api/61402/6 "2022-07-22T05:47:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [July 22, 2022, 6:11am UTC](https://community.hubspot.com/t/unable-to-post-data-to-custom-objects-from-workflow-using-the-api/61402/7 "2022-07-22T06:11:01Z")

</div>

Hi @SHarde ,

Awesome! Happy it worked.  
You can use the [GitHub repo](https://github.com/HubSpot/hubspot-api-nodejs/tree/master/src/discovery) 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 🙂
