API - Get usage for all customers in one call
Hi,
I want to get usage for all customers in one call. I do like this:
$client = new CheddarGetter_Client(URL, USER, PASS, PRODUCT);
$customers = $client->getCustomers(array('productCode'=>PRODUCT));
Now i want to loop trough all the customers and call
$customers->getCustomerItemQuantityRemaining($customerCode,'PAGEVIEWS');
This works if i know the $customerCode and what i want to know if there is a clever way to get the customercodes extracted from $customers response object. Or maybe loop trough them in some way
/sune
Discussions are closed to public comments.
If you need help with Cheddar please
start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by sune on 27 Mar, 2012 12:14 PM
Found a way - please let me know if there is a better solution...
Support Staff 2 Posted by Marc Guyer on 28 Mar, 2012 02:36 PM
Hi Sune -- The getCustomers call isn't very efficient. We're likely going to deprecate that call altogether or require some sort of paging mechanism so you'd need to call it for every 100 customer or so. Anything more than that and the result would cause memory issues.
If you need to do this once in a while, I don't see a problem if you do some sort of limiting by date in the call. If you're planning for this to be part of your normal process, I'd suggest another option. Without knowing exactly what you need to accomplish it's difficult to make a specific recommendation, however. Can you provide some more details?
3 Posted by sune on 28 Mar, 2012 02:42 PM
We have a SaaS service where we charge pageviews. So on daily basis i would calculate pageview usage in our system and add usage to CG current invoice. This will be done once a day counting yesterdays usage. But it could potential be 1000+ customers, so it seems to be a lot of API requests (also see my other supportquestion regarding adding usage for many customers http://support.cheddargetter.com/discussions/problems/1332-calling-... ).
I guess i could make my function so it would page 50 customers at a time and then run them trough as needed, as it will only happen once a day.
Support Staff 4 Posted by Marc Guyer on 30 Mar, 2012 01:55 PM
I suggest updating individual customers throughout the day as pageviews are used. Update an individual customer only periodically. Maybe only after every 1000 or so pageviews. So, customers' accounts are kept up to date throughout the day and you avoid managing a nightly job. That'll make CheddarGetter happy, too ;)
5 Posted by sune on 02 Apr, 2012 12:09 PM
Ok - what you are saying is running the script on one customer at a time troughout the day. I will defenetly NOT do it as pageviews are used, but instead with an interval. Otherwise i would have to update every second or so :)
Support Staff 6 Posted by Marc Guyer on 02 Apr, 2012 12:25 PM
Sounds good.
Marc Guyer closed this discussion on 02 Apr, 2012 12:25 PM.