# Custom Code workflow

**URL:** <https://community.hubspot.com/t/custom-code-workflow/52186>\
**Category:** Data Hub\
**Tags:** workflows\
**Created:** [February 25, 2022, 2:51pm UTC](https://community.hubspot.com/t/custom-code-workflow/52186 "2022-02-25T14:51:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wiljekoffie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wiljekoffie/32/89259_2.png) [@Wiljekoffie](https://community.hubspot.com/u/Wiljekoffie)\
**Post date:** [February 25, 2022, 2:51pm UTC](https://community.hubspot.com/t/custom-code-workflow/52186/1 "2022-02-25T14:51:25Z")

</div>

```lia-code-sample
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)

---

<div class="post-metadata">

**Author:** ![jbogaert](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jbogaert/32/33027_2.png) [@jbogaert](https://community.hubspot.com/u/jbogaert)\
**Post date:** [March 2, 2022, 8:49am UTC](https://community.hubspot.com/t/custom-code-workflow/52186/2 "2022-03-02T08:49:52Z")

</div>

Hi @Wiljekoffie, Thanks for reaching out!  
Can you help me understand what you’re trying to do with this custom code action?

---

<div class="post-metadata">

**Author:** ![Wiljekoffie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wiljekoffie/32/89259_2.png) [@Wiljekoffie](https://community.hubspot.com/u/Wiljekoffie)\
**Post date:** [March 2, 2022, 8:56am UTC](https://community.hubspot.com/t/custom-code-workflow/52186/3 "2022-03-02T08:56:05Z")

</div>

We would like to create a new custom object based on a closed conversation.

---

<div class="post-metadata">

**Author:** ![LMartinez7](https://avatars.discourse-cdn.com/v4/letter/l/ea666f/32.png) [@LMartinez7](https://community.hubspot.com/u/LMartinez7)\
**Post date:** [April 12, 2022, 9:38pm UTC](https://community.hubspot.com/t/custom-code-workflow/52186/4 "2022-04-12T21:38:37Z")

</div>

Hi Wiljekoffie,  
The endpoint

`hubspotClient.crm.basicApi.create`

**does not seem to work** as indicated in the api documentation ([Accounts Dashboard | HubSpot](https://developers.hubspot.com/docs/api/crm/crm-custom-objects)). 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](https://github.com/HubSpot/hubspot-api-nodejs) -scroll down to the section “No wrapped endpoint(s)”), like so:

```lia-code-sample
 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:

```lia-code-sample
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.

[  
  ![LMartinez7_0-1649799505988.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/d/e/dee46938f1da026c844299c8a81b894a2ad4d705.png)  
 ](https://hubs.ly/Q017J6HH0)

---

<div class="post-metadata">

**Author:** ![Wiljekoffie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wiljekoffie/32/89259_2.png) [@Wiljekoffie](https://community.hubspot.com/u/Wiljekoffie)\
**Post date:** [April 13, 2022, 8:00am UTC](https://community.hubspot.com/t/custom-code-workflow/52186/5 "2022-04-13T08:00:03Z")

</div>

Thanks a million!
