# Error Creating Contact

**URL:** <https://community.hubspot.com/t/error-creating-contact/136939>\
**Category:** APIs & Integrations\
**Tags:** contacts\
**Created:** [July 26, 2025, 2:34pm UTC](https://community.hubspot.com/t/error-creating-contact/136939 "2025-07-26T14:34:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![KShiban](https://avatars.discourse-cdn.com/v4/letter/k/e495f1/32.png) [@KShiban](https://community.hubspot.com/u/KShiban)\
**Post date:** [July 26, 2025, 2:34pm UTC](https://community.hubspot.com/t/error-creating-contact/136939/1 "2025-07-26T14:34:17Z")

</div>

I am trying to create a contact in Hubspot through an API call from another application.

The contact is created successfully, but I an encounter an error when trying to retrieve the Id value of the newly created contact.

The first line of code executes successfully and the contact is created:

const response = await fetch(endpointUrl, config);

The next line of code results in a type error:  
“response.json is not a function”

const responseBody = await response.json();

---

<div class="post-metadata">

**Author:** ![Dwarner4](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@Dwarner4](https://community.hubspot.com/u/Dwarner4)\
**Post date:** [July 27, 2025, 11:29am UTC](https://community.hubspot.com/t/error-creating-contact/136939/2 "2025-07-27T11:29:25Z")

</div>

I’m also getting this error while creating a contact via API. Tried everything but still stuck. Did anyone find a fix for this?

---

<div class="post-metadata">

**Author:** ![GRajput](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/grajput/32/102020_2.png) [@GRajput](https://community.hubspot.com/u/GRajput)\
**Post date:** [July 28, 2025, 12:01pm UTC](https://community.hubspot.com/t/error-creating-contact/136939/3 "2025-07-28T12:01:46Z")

</div>

Hi @KShiban

Hey, I just tried to create the contact using API, but I was able to create and the contact ID in the response body as well.  
Here is the curl -

```lia-code-sample
curl --request POST \
 --url https://api.hubapi.com/crm/v3/objects/contacts \
 --header 'authorization: Bearer ' \
 --header 'content-type: application/json' \
 --data '{
 "properties": {
	"email": "v.josh@gn.com",
	"lastname": "Josh",
	"firstname": "vayu"
 }
}'

```

**link -** [Accounts Dashboard | HubSpot](https://developers.hubspot.com/docs/reference/api/crm/objects/contacts#post-%2Fcrm%2Fv3%2Fobjects%2Fcontacts)

I hope this will help you out. Please mark it as **Solution Accepted and upvote** to help another Community member.

Thanks!

---

<div class="post-metadata">

**Author:** ![KShiban](https://avatars.discourse-cdn.com/v4/letter/k/e495f1/32.png) [@KShiban](https://community.hubspot.com/u/KShiban)\
**Post date:** [July 28, 2025, 7:09pm UTC](https://community.hubspot.com/t/error-creating-contact/136939/4 "2025-07-28T19:09:15Z")

</div>

That’s great, but I have to be able to do with JavaScript, not cURL.

---

<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:** [August 4, 2025, 5:28pm UTC](https://community.hubspot.com/t/error-creating-contact/136939/5 "2025-08-04T17:28:01Z")

</div>

Hey, @KShiban 👋

To help us debug this, can you share a bit more information?

1. Could you share the more complete code block for the function making this API call?
2. What HTTP library are you using (`node-fetch`, `axios`, etc.)?
3. Could you add `console.log(response)` on the line right after your `fetch` call and share the output here?

I hope the `console.log` will tell us exactly what kind of object you’re working with and how to get the data from it.

Talk soon! — Jaycee

---

<div class="post-metadata">

**Author:** ![KShiban](https://avatars.discourse-cdn.com/v4/letter/k/e495f1/32.png) [@KShiban](https://community.hubspot.com/u/KShiban)\
**Post date:** [August 5, 2025, 1:51pm UTC](https://community.hubspot.com/t/error-creating-contact/136939/6 "2025-08-05T13:51:58Z")

</div>

Here is the complete function. It creates a new contact in HubSpot from VoiceFlow. The input variables are:  
Email  
LastName  
FirstName  
roi\_url  
hubspotApiToken  
export default async function main(args) {  
// Validate input variables from args - find the “validateInputs” function below  
const invalidFieldTrace = validateInputs(args);  
if (invalidFieldTrace) return invalidFieldTrace;  
const {  
Email,  
FirstName,  
LastName,  
roiUrl,  
hubspotApiToken,  
} = args.inputVars;  
const payload = {  
properties: {  
email: Email,  
firstname: FirstName,  
lastname: LastName,  
roi\_url: roiUrl,  
}  
};  
const endpointUrl = ‘[https://api.hubapi.com/crm/v3/objects/contacts](https://api.hubapi.com/crm/v3/objects/contacts)’;  
const config = {  
method: ‘POST’,  
headers: {  
‘Authorization’: `Bearer ${hubspotApiToken}`,  
‘Content-Type’: ‘application/json’,  
},  
body: JSON.stringify(payload)  
};  
try {  
const response = await fetch(endpointUrl, config);  
if (!response.ok) {  
throw new Error(`HTTP status code ${response.status}`);  
}  
const responseBody = await response.json();  
if (!responseBody || typeof responseBody !== ‘object’) {  
throw new Error(“Invalid or missing response body”);  
}  
const contactId = responseBody.id;  
return {  
outputVars: {  
contactId,  
},  
next: {  
path: ‘success’  
},  
trace: [  
{  
type: “debug”,  
payload: {  
message: ‘HubSpot API call successful’  
}  
},  
{  
type: “debug”,  
payload: {  
message: `Contact created - ID: ${contactId}`  
}  
},  
]  
};  
} catch (error) {  
return {  
next: {  
path: ‘error’  
},  
trace: [{  
type: “debug”,  
payload: {  
message: `HubSpot API call error: ${error.message}`  
}  
}]  
};  
}  
function validateInputs(args) {  
const {  
Email,  
FirstName,  
LastName,  
hubspotApiToken,  
} = args.inputVars;  
if (!FirstName) {  
return {  
next: { path: ‘error’ },  
trace: [{ type: “debug”, payload: { message: “Missing required input variable: FirstName” } }]  
};  
}  
if (!Email) {  
return {  
next: { path: ‘error’ },  
trace: [{ type: “debug”, payload: { message: “Missing required input variable: Email” } }]  
};  
}  
if (!LastName) {  
return {  
next: { path: ‘error’ },  
trace: [{ type: “debug”, payload: { message: “Missing required input variable: LastName” } }]  
};  
}  
if (!hubspotApiToken) {  
return {  
next: { path: ‘error’ },  
trace: [{ type: “debug”, payload: { message: “Missing required input variable: hubspotApiToken” } }]  
};  
}  
return null;  
}  
}

---

<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:** [August 8, 2025, 9:30pm UTC](https://community.hubspot.com/t/error-creating-contact/136939/7 "2025-08-08T21:30:50Z")

</div>

Hey, @KShiban 👋 It sounds like your 3rd party system is having an issue with `fetch`. I’d try updating your code to check if response.json is a function. If it is, it proceeds as normal. If not, it assumes the response is the data itself. — Jaycee
