APIs & Integrations

Lemppa
Participant

Is this API broken? contacts/v1/lists/id/contacts/all? it is returning has_more true and vidoffset 0

SOLVE

Hello,

This API is currently not working as should and it is causing infinite loop in my request:

https://developers.hubspot.com/docs/methods/lists/get_list_contacts

 

has_more is returning always true and vid_offset value is always 0.

 

Here is the code that I use to get contacts and it has worked previously:

 bool hasMore = true;
            string rawresp = "";
            vidOffset = 100;
            while (hasMore == true)
            {
                HttpWebRequest request = default(HttpWebRequest);
                HttpWebResponse response = null;
                StreamReader reader = default(StreamReader);

                string searchUrl = "";
                string api = "contacts/v1/lists/" + list.listId + "/contacts/all?";

                searchUrl = Collector.Default.HubspotApiAddress + api + "hapikey=" + Collector.Default.HubspotApiKey + "&count=100&vidOffset=" + vidOffset;


                ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications;
                System.Net.CredentialCache myCache = new System.Net.CredentialCache();

                myCache.Add(new Uri(searchUrl), "Basic", new System.Net.NetworkCredential(Collector.Default.HubspotUser, Collector.Default.HubspotPassword));
                request = (HttpWebRequest)WebRequest.Create(searchUrl);

                request.Credentials = myCache;

                response = (HttpWebResponse)request.GetResponse();
                reader = new StreamReader(response.GetResponseStream());

                rawresp = reader.ReadToEnd();
                Contacts root = JsonConvert.DeserializeObject<Contacts>(NormaliseJsonVariables(rawresp));
                hasMore = root.has_more;
                vidOffset = root.vid_offset;

                foreach (Contact con in root.contacts)
                {
                    //GetContactDetails(con, con.profile_url, list);
                    
                    //RemoveContactFromList(con, list, contactLists);
                    //AddContactToList(con, list, contactLists);
                }               
                response.Close();
                Thread.Sleep(1000);
            }
0 Upvotes
1 Accepted solution
Lemppa
Solution
Participant

Is this API broken? contacts/v1/lists/id/contacts/all? it is returning has_more true and vidoffset 0

SOLVE

Hi,

Managed to solve this by my self. I was missing the variable vid-offset normalization to vid_offset.

 

public string NormaliseJsonVariables(string res)
        {
            string normal = res;
            normal = normal.Replace("canonical-vid", "canonical_vid");
            normal = normal.Replace("merged-vids", "merged_vids");
            normal = normal.Replace("portal-id", "portal_id");
            normal = normal.Replace("is-contact", "is_contact");
            normal = normal.Replace("profile-token", "profile_token");
            normal = normal.Replace("profile-url", "profile_url");
            normal = normal.Replace("page-url", "page_url");
            normal = normal.Replace("form-submissions", "form_submissions");
            normal = normal.Replace("form-id", "form_id");
            normal = normal.Replace("conversion-id", "conversion_id");
            normal = normal.Replace("portal-id", "portal_id");
            normal = normal.Replace("page-title", "page_title");
            normal = normal.Replace("page-id", "page_id");
            normal = normal.Replace("meta-data", "meta_data");
            normal = normal.Replace("identity-profiles", "identity_profiles");
            normal = normal.Replace("saved-at-timestamp", "saved_at_timestamp");
            normal = normal.Replace("deleted-changed-timestamp", "deleted_changed_timestamp");
            normal = normal.Replace("saved-at-timestamp", "saved_at_timestamp");
            normal = normal.Replace("deleted-changed-timestamp", "deleted_changed_timestamp");
            normal = normal.Replace("merge-audits", "merge_audits");
            normal = normal.Replace("canonical-vid", "canonical_vid");
            normal = normal.Replace("merged-vids", "merged_vids");
            normal = normal.Replace("has-more", "has_more");
            normal = normal.Replace("vid-offset", "vid_offset");
            return normal;
        }

View solution in original post

2 Replies 2
Lemppa
Solution
Participant

Is this API broken? contacts/v1/lists/id/contacts/all? it is returning has_more true and vidoffset 0

SOLVE

Hi,

Managed to solve this by my self. I was missing the variable vid-offset normalization to vid_offset.

 

public string NormaliseJsonVariables(string res)
        {
            string normal = res;
            normal = normal.Replace("canonical-vid", "canonical_vid");
            normal = normal.Replace("merged-vids", "merged_vids");
            normal = normal.Replace("portal-id", "portal_id");
            normal = normal.Replace("is-contact", "is_contact");
            normal = normal.Replace("profile-token", "profile_token");
            normal = normal.Replace("profile-url", "profile_url");
            normal = normal.Replace("page-url", "page_url");
            normal = normal.Replace("form-submissions", "form_submissions");
            normal = normal.Replace("form-id", "form_id");
            normal = normal.Replace("conversion-id", "conversion_id");
            normal = normal.Replace("portal-id", "portal_id");
            normal = normal.Replace("page-title", "page_title");
            normal = normal.Replace("page-id", "page_id");
            normal = normal.Replace("meta-data", "meta_data");
            normal = normal.Replace("identity-profiles", "identity_profiles");
            normal = normal.Replace("saved-at-timestamp", "saved_at_timestamp");
            normal = normal.Replace("deleted-changed-timestamp", "deleted_changed_timestamp");
            normal = normal.Replace("saved-at-timestamp", "saved_at_timestamp");
            normal = normal.Replace("deleted-changed-timestamp", "deleted_changed_timestamp");
            normal = normal.Replace("merge-audits", "merge_audits");
            normal = normal.Replace("canonical-vid", "canonical_vid");
            normal = normal.Replace("merged-vids", "merged_vids");
            normal = normal.Replace("has-more", "has_more");
            normal = normal.Replace("vid-offset", "vid_offset");
            return normal;
        }
Willson
HubSpot Employee
HubSpot Employee

Is this API broken? contacts/v1/lists/id/contacts/all? it is returning has_more true and vidoffset 0

SOLVE

Hi @Lemppa 

 

Great, glad to hear you managed to get this working again!

 

Product Manager @ HubSpot
0 Upvotes