DenoDDeno
Powered by
wedmaniacW
Deno•3y ago•
3 replies
wedmaniac

Making Post Request To HubSpot Api

Hi there I'm trying to make a post request to the HubSpot Api. However the request results in a "HubSpot API responded with status: 401" ´401 Unauthorized is returned when the authentication provided is invalid.´
https://developers.hubspot.com/docs/api/crm/contacts

Selected scopes on the HubSpot app:
crm.objects.companies.read
crm.objects.contacts.read
crm.objects.contacts.write
crm.objects.companies.write

const body = {
  "properties": {
    "email": data.email,
    "phone": "(877) 929-0687",
    "company": "Biglytics",
    "website": "biglytics.net",
    "lastname": data.lastname,
    "firstname": data.firstname
  }
};

// Make the POST request to HubSpot
const response = await fetch('https://api.hubapi.com/crm/v3/objects/contacts', {
  method: 'POST',
  headers: {
    'content-type': 'application/json',
    'authorization': `Bearer ${HUBSPOT_ACCESS_TOKEN}`
  },
  body: JSON.stringify(body)
});

if (response.ok) {
  const result = await response.json();
  console.log(result);
} else {
  throw new Error(`HubSpot API responded with status: ${response.status}`);
}
const body = {
  "properties": {
    "email": data.email,
    "phone": "(877) 929-0687",
    "company": "Biglytics",
    "website": "biglytics.net",
    "lastname": data.lastname,
    "firstname": data.firstname
  }
};

// Make the POST request to HubSpot
const response = await fetch('https://api.hubapi.com/crm/v3/objects/contacts', {
  method: 'POST',
  headers: {
    'content-type': 'application/json',
    'authorization': `Bearer ${HUBSPOT_ACCESS_TOKEN}`
  },
  body: JSON.stringify(body)
});

if (response.ok) {
  const result = await response.json();
  console.log(result);
} else {
  throw new Error(`HubSpot API responded with status: ${response.status}`);
}


All help is super appreciative! Thank you in advance!
CRM API | Contacts
Contact records store information about individuals. The contacts endpoints allow you to manage this data and sync it between HubSpot and other systems.
CRM API | Contacts
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

(node) post request stuck at pending
Ali.AAli. / help
2y ago