Migrating from legacy to v3 api

Hi there!
Ever since the api keys are now dupricated, I am rewriting my Hubspot apis such that I can use

Authorization: Bearer <private-app-token>

Instead of hapikey=key_value

However am I facing crutial issues which doesn’t seem to be documented on the latest Hubspot documentation/sites…

Issue 1

Since it is mendatory for our system to use Hubspot legacy endpoints

GET /contacts/v1/lists/all/contacts/all

GET /contacts/v1/lists/${id}/contacts/all

(the List endpoints are not yet available to v3 so I need to keep the legacy endpoints running)
When I make a request to Get contacts or Get List’s contacts, then only the first page of the response payload data is returned. The pagination (vidOffset) and request count (count) query params are not working.

Issue #2

My second issue is when I try calling the GET /limit endpoint, the response always returns a 403 even if I set the same/right Authentication Bearer token using the private app token (while not passing the hapikey=key_value anymore)

/integrations/v1/limit/daily

Here is the error message I am getting:

Request failed with status code 403 - Could not fetch Hubspot limit

Can you please help me understand and resolve those 2 issues please?
Thank you very much.
Related documentation:
- Auth Migration
- Get List Contacts
- Get Limit

Hello @audreyjw
Regarding your first issue with the HubSpot legacy endpoints, it is true that the pagination parameters are not supported in those endpoints. However, you can still fetch all the contacts or list contacts by making multiple requests and incrementing the vidOffset parameter with each subsequent request until you have fetched all the data. Here’s an example in Node.js:

const axios = require('axios');

async function getAllContacts() {
 let allContacts = [];
 let vidOffset = 0;
 let hasMore = true;
 while (hasMore) {
 const res = await axios.get(`https://api.hubapi.com/contacts/v1/lists/all/contacts/all?hapikey=YOUR_API_KEY&vidOffset=${vidOffset}&count=100`);
 allContacts = allContacts.concat(res.data.contacts);
 hasMore = res.data['has-more'];
 vidOffset = res.data['vid-offset'];
 }
 return allContacts;
}

Regarding your second issue with the GET /limit endpoint, make sure that the private app that you are using has the correct scopes to access the /limit endpoint. You can check the scopes by going to the App Marketplace, clicking on your private app, and then clicking on “Scopes” under the “Install” section. Make sure that the “Integrations: Read your API usage limits” scope is selected.
Thanks & Regards
Himanshu Rauthan

Hello Himanshu Rauthan,
Thank you for your reply,
Regarding Issue 1, I realized for the following two endpoints:

GET /contacts/v1/lists/${id}/contacts/all

GET /contacts/v1/lists/all/contacts/all

I am using axios package in nodejs to make the GET request and relized that with version

axios v1.3.3

I was not encoding query params arrays properly. Here is what I had to do in order to serialize the property query param (array) for anyone experiencing similary issues in the future:

paramsSerializer: { // ref: https://github.com/axios/axios/issues/5058#issuecomment-1272107602 indexes: null // by default: false},

After this change I was able to use the legacy endpoints with my private app token + pagination no problem! Sorry that was my mistake all along…!

For issue #2, I do not see the Integrations: Read your API usage limits option in my Hubspot account. I navigated here:
https://app.hubspot.com/private-apps/\/<private-app-id>/edit
I don’t see that option “Installs” under the “Scopes” tab:


Am I not looking at the right place?

Thank you for your help and I am looking forward to your reply.

Hello @audreyjw
Private apps can not be installed, they can be directly used by using private token.
Install option will be available in public apps using oauth2 flow.
Regarding the apis limits, you can check this doc: API usage guidelines and limits - HubSpot docs
Thanks & Regrads
Himanshu Rauthan

Hi Himanshu, not sure I understand you last reply.. You mentioned in your first reply:

Regarding your second issue with the GET /limit endpoint, make sure that the private app that you are using has the correct scopes to access the /limit endpoint. You can check the scopes by going to the App Marketplace, clicking on your private app, and then clicking on “Scopes” under the “Install” section. Make sure that the “Integrations: Read your API usage limits” scope is selected.


So I know that it’s an access token generetad by the private app. :slightly_smiling_face:
In my last reply I shared that I can’t see the :Integrations: Read your API usage limits" scope from the Scopes tab. Nothing is mentioned in the doc regarding this as well.
Even with the access token set in my response header as
Authentication: “Bearer <access-token>”
I am getting:
Request failed with status code 403 - Could not fetch Hubspot limit
Looking forward to solve this issue.

@audreyjw
Sorry for misunderstanding the image which you shared in the scopes section please score down where you can view and modify the scopes that your app has been granted. Make sure that the “Integrations: Read your API usage limits” scope is selected. If it is not, click on “Edit Scopes” and select this scope, then save your changes.
After you have verified that the correct scope is selected, try making the GET /limit request again and see if the issue has been resolved. If this resolves the issue plz let me know.

Hi @himanshurauthan like mentioned, I don’t see the option “Integrations: Read your API usage limits” can you share a URL sample of where I should see this?
I am currently looking into:
https://app.hubspot.com/private-apps/\/<private-app-id>/edit

Hello @audreyjw
Apologies for the misunderstanding, I checked especially about getting the rate limits from the API using a private app token but got the same response with status code 403 as you. The oauth scope it is looking for is only available for oauth2 access tokens so it seems there is currently no way to get the data with this endpoint using a private app token. But this rate limit information can be found in the headers of any API call response. So alternatively you can use any of the search endpoints to get that information and get the data from response headers.
Please let me know if that answers your question. Thanks

@himanshurauthan Thank you for your clarifications, my understanding is that this api /limit is not supported anymore by the new flow of authentication using the private app access token.
That being said, I will update my code such that I will read the response headers to know my limits.
Thank you again for your help!