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

  1. Found a way - please let me know if there is a better solution...

    $client = new CheddarGetter_Client(URL, USER, PASS, PRODUCT);       
    $customers = $client->getCustomers(array('productCode'=>PRODUCT));
    
    //Get customerCodes:
    $cc = array_keys($customers->toArray());
    print_r($cc);
    
  2. 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. 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.

  4. 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. 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 :)

  6. Sounds good.

  7. Marc Guyer closed this discussion on 02 Apr, 2012 12:25 PM.

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

Recent Discussions