nes at July 20th, 2016 02:52 — #1
I've been having trouble getting faster performance out of the API, so I'm hoping someone here can help
What I'm trying to do is show the number of leads for multiple salespeople between 2 dates.
Functionally it works but is just very slow, and I'm not sure whether the speeds that I need are even possible with the API...
Currently I use this:
$resultJSON = make_api_call('contacts.json?&per_page=100&page=1&date_filter=modified_at&since='.$fromDate.'&until='.$toDate, 'GET', array(), $UserOnePageID, base64_decode($UserOnePageKey));
I do this for about 20 OP accounts, and it takes about 30 seconds.
Is there a faster way?
liam at July 20th, 2016 05:08 — #2
This seems like an odd query to run. It searches for any contacts which have been updated by the user in a certain time frame. This update can be done by anyone in your account, so I'm not sure if this is an accurate metric for you. But if you say that this is functionally working for you, then that's fine. My only suggestion would be to checkout the additional counts data which is returned from the login request. Fetching this every day and saving it may give you a similar historic metric, and it's a lot faster.
Now if you are set with the method you are calling, then there are some things you can do to increase the speed.
- You can limit the
per_page count to 1, so only one contacts' data will be loaded and returned.
- Limit the fields that are returned from our API with each contact with the
fields param (see the docs). The easiest option would be to limit it to just returning the contact id:
nes at July 21st, 2016 18:33 — #4
Thanks for the quick response.
I have changed modified_at to be created_at, thanks for pointing that out.
Just so I'm clear on what your suggesting, you mean to login for each user every day, then calculate the amount of contacts created that day by subtracting yesterday's total from today's total?
Then I would save that in my own database. The script would be automated to run every day.
liam at July 22nd, 2016 03:13 — #5
Yes, I think that would be a better solution. The counts returned with the login / bootstrap request are precalculated in our DB so that request will always be fast. You will only need a single request to get all of the users counts.
If you store these in a local DB you will be able to run your queries against these to get the change in number of contacts per user for any date range which you have made a backup of.
There is one downside to this, which is that the contacts count will have deleted contacts subtracted from it, as opposed to your current method. Say I have a contact that is 1 year old. I deleted him last week, and I created 2 new contacts last week too. The counts will show that there was only a difference of +1 last week.
But users rarely delete contacts, so you may be able to work with this.
If you are running this code on a server, you could also subscribe to our webhooks to get updates whenever contacts are created.