APIs & Integrations

EIbbetson
Participant

Wrapped API: NodeJS Headers

Hello,

(Enterprise customer, no API Addon)

 

I am rebuilding some APIs using the new Access Token and @hubspot/api-client for Node.JS

 

The connection and calls work fine however, on the response side, I get the message correctly but how do I access the response headers?

 

I need to know if the headers are accessible and if X-HubSpot-RateLimit-Remaining, is featured in the headers.

 

I cannot find any documentation on this at all for the Wrapped APIs and the only community posts said it worked on Postman. I am using NodeJs and as such need it to be accessible here.

2 Replies 2
Teun
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Wrapped API: NodeJS Headers

Hi @EIbbetson ,


I would like to advise you to use Axios, as it gives you much more control on how the data is being send, but also accessing the response data. 
Here is quick example using Axios:

  const axios = require('axios')

  const properties = ['firstname', 'lastname', 'email']
  let url = `https://api.hubapi.com/crm/v3/objects/contacts/${contactId}?archived=false`

  properties.forEach((property) => {
    url = url + `&properties=${property}`
  })

  return axios({
    method: 'get',
    url: url,
    headers: {
      'Authorization': `Bearer ${accessToken}`,
      'Content-Type': 'application/json'
    }
  }).then((response) => {
    console.log(response.data) // Response body
    console.log(response.headers) // Response headers
  }).catch((error) => {
    throw new Error(error.data.message)
  })


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.


EIbbetson
Participant

Wrapped API: NodeJS Headers

I am aware of Axios and looks like I am needing to use it for the Association APIs. 

My question now becomes, why offer these Wrapped APIs if the limit needs to be managed but is not supplied and other services such as Axios and HTTPS are better equiped?

 

I decided to use the Wrapped APIs for a longer term solution where it would update the API used instead of changing all the URLs from potential legacy ones. 

Are Wrapped APIs not ideal and should be scrapped in favour of other tools?