CMS Development

adunbar_dJ2
Participant | Diamond Partner
Participant | Diamond Partner

Custom Object API Call Offset

Hello, our development team developed a listing and posting template that dynamically updates based on custom object data.
 
However, we cannot show all of the units at a time due to HubSpot’s offset rule. We have added in the below to try and get around it, but the code isn't quite working as expected:
 

---{% set a = crm_objects("unit", "limit=100&offset=100", "building_address,building_name,unit_name,bedroom_count,neighborhood,unit__,status,renewal_status") %}---

 

 

When I opened up a support ticket with HubSpot, they mentioned the below: 

"

We can see you are using crm_objects() HubL function which uses the CRM API and therefore has the same limitations. In this case, the crm_objects() function receives 3 parameters, but we will focus specifically on the first 2.

 

The first parameter 'unit' is the type of object to search in the CRM and the second parameter is a query string. The query string limit=100&offset=100 limits the number of results returned by the API to 100 records and the offset parameter tells the API to start the search from the record in position 100 of the total results. However, in the next call, you still need to update the offset parameter to get the next 100 records. This means that your code must update the offset parameter on every call until you reach the last unit record in their portal"

 

--------

Can someone help provide some insight and/or sample code that can be used to give us a workaround? 

 

 

For Reference: 

Page: https://availability.chasencompanies.com 

 

Thanks in advance for any insight and help! 🙂 

0 Upvotes
5 Replies 5
nickdeckerdevs1
Contributor | Gold Partner
Contributor | Gold Partner

Custom Object API Call Offset

This should fix you up. You need to set the offset variable outside of your call and create a loop. This should get you started on your quest. 

{# you can set this stuff up differently and you can be a bit more intelligent about this in your loop to not have to do this kind of math, but this is a pretty basic way to get you moving in the direction I think you are looking to go #}
{% set limit = 100 %}
{% set offset = 0 %}
{% set max_records = 500 %}
{% set total_loops = ( max_records / limit ) %}

{% set this_other_stuff = 'building_address,building_name,unit_name,bedroom_count,neighborhood,unit__,status,renewal_status' %}
{% set listing = crm_objects('unit', 'limit=' ~ limit ~ '&offset=' ~ offset, this_other_stuff) %}

{# create a parent loop to control the amount of spins around the globe you need to take #}
{% for x in range (1, total_loops) %}
  {# just loop through your call how you have it set up -- and because we are using variables in here we can modify them! #}
  {% for unit in crm_objects('unit', 'limit=' ~ limit ~ '&offset=' ~ offset, this_other_stuff) %}
    <h1>{{ unit.unit_name }}</h1>
  {% endfor %}
  {# modify the offset value before we start the loop over again! #}
  {% set offset = offset + limit %}
{% endfor %}


My advice is never copy and paste code. Type this stuff in. Test this stuff line by line. Make sure you understand teh concepts, print out variables, etc. Let me know if you need some more help with this.

nickdeckerdevs1
Contributor | Gold Partner
Contributor | Gold Partner

Custom Object API Call Offset

It looks like we are running up against a limit on how many crm object calls can be on a page. It might be best to set up a cloud server to have this queried by the api, there is just too much data being brought in here

0 Upvotes
adunbar_dJ2
Participant | Diamond Partner
Participant | Diamond Partner

Custom Object API Call Offset

Thank you for sharing the code! Our development team said that they are still running into issues though. 

They tried adding the code inside our condition and it is not working, because our offset is greater than 300. When we added the preview function you shared it did not pull all of the data. 

 

Could we by chance add you into our sandbox to take a look? 

0 Upvotes
nickdeckerdevs1
Contributor | Gold Partner
Contributor | Gold Partner

Custom Object API Call Offset

Sure. Nicholas@deckerdevs.com. shoot me an email and let's set up a time to
review on Monday or Tuesday. I can take a look at it over the weekend if
you supply me with access and a few links
0 Upvotes
Jaycee_Lewis
Community Manager
Community Manager

Custom Object API Call Offset

Hi, @adunbar_dJ2 👋 Thanks for reaching out. Let's see if we can get the converstaion going — hey @miljkovicmisa @piersg @Gonzalo do you have any insight here?

 

Thank you! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot