APIs & Integrations

SayakMitra
Member

Get all deals API returning incorrect offset

There is an issue where the offset param in the get all deals are returning the same offset value And do so - this gets us stuck in an infinite loop where we never get the next page of results.

 Here is the endpoint url: 'https://app.hubspot.com/deals/v1/deal/paged?hapikey={Signature}&includeAssociations=true&limit=200&Offset={vidOffset}&properties=dealname'

its returning same offset value: 524562026 which causing infinite loop and not getting all the deals.

8 Replies 8
data2Visual
Member

Get all deals API returning incorrect offset

Is there any update on this issue? I am facing the same issue for https://developers.hubspot.com/docs/methods/lists/get_lists API.

 

I am getting has-more true in response but offset is not updating. Though I am passing lastest update in API params.

0 Upvotes
Bulat
Participant

Get all deals API returning incorrect offset

1) It might be because 'offset' is string (alphanumeric) and not integer. So, you are effectively converting that string to 0. 🙂 Use it without converting to integer.

 

2) You are trying to use 'Offset' field in the request. And it should be lowercase: 'offset'.

0 Upvotes
hot_z
Contributor

Get all deals API returning incorrect offset

Hi there,

 

Is the returned 'hasMore' holding the value of 'true' in the returned response? I've just tried grabbing my own deals - https://developers.hubspot.com/docs/methods/deals/get-all-deals, in my own portal and did not run into such an issue.

0 Upvotes
SayakMitra
Member

Get all deals API returning incorrect offset

Yes, it returns 'hasMore' value of 'true' in response.which is causing infinite loop

0 Upvotes
hot_z
Contributor

Get all deals API returning incorrect offset

Well that's strange. I'm unsure how this could happen but I think if you shared more of what you've implemented, it could potentially allow someone here to assist further. 🙂

0 Upvotes
SayakMitra
Member

Get all deals API returning incorrect offset

we have 300+ records in deals and set the limit to 200 per batch and the default offset value is zero. in first batch API return 200 records, hasMore value is true and offset is 524562026, in second iteration by passing offset value = 524562026, its returning same records with a same offset value and hasMore value true. which leads to stuck in an infinite loop where we never get the next batch of results.

 

Request:

var hasMore = true;
long vidOffset = 0;

while (hasMore)
{
var strUrl = $"https://app.hubspot.com/deals/v1/deal/paged?hapikey=HAPIKEY&includeAssociations=true&limit=200&Offset={vidOffset}&properties=dealname";

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strUrl);
req.Method = "GET";
req.ContentType = "application/json";
using (var resp = (HttpWebResponse)req.GetResponse())
{
using (var sr = new StreamReader(resp.GetResponseStream()))
{
searchResult = sr.ReadToEnd();
}
}
var jr = JsonReader.ParseObject(searchResult);
var arr = (JsonArray)jr["deals"];
vidOffset = Convert.ToInt32(jr["offset"].ToString());
hasMore = Convert.ToBoolean(jr["hasMore"].ToString());
}

 

Response:

 

first iteration

deals:[200]-records

hasMore: true

offset: 524562026

 

second iteration

deals:[200]--same records

hasMore: true

offset: 524562026

 

 and so on......

 

Note: we are facing the same issue for Get all companies API

0 Upvotes
SayakMitra
Member

Get all deals API returning incorrect offset

Hello,

Any update on this ticket..?

0 Upvotes
SayakMitra
Member

Get all deals API returning incorrect offset

we have around 300+ records, we set the initial value of offset to 0, in the first iteration it's returning  200 deals with offset value 524562026 and 'hasMore' value of 'true'. and from next iteration, it's giving same deals, offset value and 'hasMore' value of 'true'.

 

Request:

 

var hasMore = true;
long vidOffset = 0;

while (hasMore)
{
var strUrl = $"https://app.hubspot.com/deals/v1/deal/paged?hapikey={Signature}&includeAssociations=true&limit=200&O...";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strUrl);
req.Method = "GET";
req.ContentType = "application/json";
using (var resp = (HttpWebResponse)req.GetResponse())
{
using (var sr = new StreamReader(resp.GetResponseStream()))
{
searchResult = sr.ReadToEnd();
}
}
var jr = JsonReader.ParseObject(searchResult);
var arr = (JsonArray)jr["deals"];
vidOffset = Convert.ToInt32(jr["offset"].ToString());
hasMore = Convert.ToBoolean(jr["hasMore"].ToString());
}

Response: 

 

1st iteration

 

deals: [200]

hasMore: true

offset: 524562026

 

2nd iteration. and so on

deals: [200] 

hasMore: true

offset: 524562026

 

0 Upvotes