python-intercom
python-intercom copied to clipboard
Missing docs for the awesome scroll api
It seems to be already part of the package, but is missing from the docs.
Since it took me ages to figure it out, I thought I would give something back by sharing the code that I used to finally get it to work. I can successfully retrieve the data of 13,000+ users with this:
INTERCOM_API_TOKEN = "XXXXXXXX"
from intercom.client import Client
intercom_session = Client(personal_access_token=INTERCOM_API_TOKEN)
try:
myscroll = intercom_session.users.scroll()
i = 1
for user in myscroll:
print(str(i) + ' ' + user.name + ' ' + user.email)
i += 1
except:
print("An exception occurred, could not get scroll")
(update: the next(myscroll) statement was not needed)
A few things I noted when I converted my users = intercom_session.users.find(order="desc", sort="last_request_at") code to the scroll() code:
- before I would do myuser = users.users[i] and then myuser['user_id'] etc. that has changed to myser.user_id format.
- myuser['created_at'] would then be returned as an integer, while now myuser.created_at is returned as a datetime object. With myuser.created_at.timestamp() I can get the Unix timestamp again.
- if myuser.last_request_at is None then myuser.last_request_at.timestamp() returns an error.
- myuser.created_at.strftime('%Y-%m-%d %H:%M:%S') returns nice readable format time.
Came here searching for page/scroll api issues (even though I know this SDK is not maintained) and found this. Thanks @PiAir 🙏🏻