setItemQuantity not working with PHP library

Dan Kamins's Avatar

Dan Kamins

06 May, 2010 10:35 PM

The setItemQuantity method does not seem to be working with the PHP library. How are we supposed to specify the itemCode?

The error:
Fatal error: Uncaught exception 'CheddarGetter_Response_Exception' with message 'An itemId or itemCode is required' in Response.php:316

The API method from the PHP library:

 * Set a usage item quantity
 * @param string $code Your code for the customer
 * @param string|null $id CG id for the customer
 * @param array $data Your (itemCode or CG itemId) and quantity
 * @return CheddarGetter_Response
 * @throws CheddarGetter_Response_Exception
public function setItemQuantity($code, $id = null, array $data) {
    $this->_requireIdentifier($code, $id);
    return new CheddarGetter_Response(
            '/customers/set-item-quantity/' . (($id) ? 'id/'.$id : 'code/'.$code),

The API docs are here:

I don't see how "itemCode" even has a chance to get into the URL with this code, but maybe I'm calling it wrong or misreading. I think this is how we're supposed to call it based on the method docs, right?
$client->setItemQuantity($custcode, NULL, array('quantity' => $quantity));

But how do we provide itemCode exactly? The $data description hints at it, but from the API docs, all we're supposed to post is quantity=12345... I tried this too and it didn't work:
$client->setItemQuantity($custcode, NULL, array('MYITEMCODE' => $quantity));

Please explain and provide a one-line example of how to use this method. Thank you!

P.S. The same applies for addItemQuantity, etc.

  1. Support Staff 1 Posted by Marc Guyer on 06 May, 2010 10:47 PM

    Marc Guyer's Avatar

    Ahh, there does appear to be a discrepancy between the API doc and the PHP wrapper. The customers/set-item-quantity call can accept parameters in two ways. The first is documented in the API docs. The second is what the PHP wrapper is expecting but it's not documented. For the PHP wrapper:

        array('itemCode'=>'MYITEMCODE', 'quantity'=>$quantity)

    The same goes for customers/add-item-quantity

  2. 2 Posted by Dan Kamins on 07 May, 2010 12:07 AM

    Dan Kamins's Avatar

    Great, thank you -- this is working now. Is there by any chance an undocumented way to set more than one tracked item in a single API call?

  3. Support Staff 3 Posted by Marc Guyer on 07 May, 2010 12:13 AM

    Marc Guyer's Avatar

    There isn't but that's an interesting thought. I wonder how often that
    would be useful.

  4. 4 Posted by Dan Kamins on 07 May, 2010 12:23 AM

    Dan Kamins's Avatar

    Started a new suggestion thread to close this one / track the suggestion separately:

  5. Support Staff 5 Posted by Marc Guyer on 07 May, 2010 03:13 PM

    Marc Guyer's Avatar

    Thanks for starting the new thread!

  6. Marc Guyer closed this discussion on 07 May, 2010 03:13 PM.

Discussions are closed to public comments.
If you need help with Cheddar please start a new discussion.

Keyboard shortcuts


? 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

28 Mar, 2024 10:45 PM
24 Jan, 2024 08:33 AM
11 Jan, 2024 07:13 AM
30 Nov, 2023 02:07 AM
22 Nov, 2023 08:41 AM