Search code examples
podio

How to update a Podio category using PHP API


I'm using a webhook to kick off a series of PHP scripts that take advantage of the Podio PHP API. I've tried using several different API calls but haven't been able to sort this out. This is a test file I'm using so the actual logic of what its doing doesn't make much sense. When I run the code below I get the error.

PHP Fatal error:  Uncaught PodioBadRequestError: "Invalid value "status" (string): Not a valid option"
Request URL: http://api.podio.com/item/<removed>/value/<removed>

Stack Trace:
/data/www/default/contracts/lib/podio-php-master/lib/Podio.php(357): 
Podio::request('PUT', '/item/<removed>...', Array)
/data/www/default/contracts/lib/podio-php-master/models/PodioItemField.php(55): Podio::put('/item/<removed>...', Array)
/data/www/default/contracts/test-category.php(25): 
PodioItemField::update(<removed>, <removed>, Array, Array)
{main}
  thrown in /data/www/default/contracts/lib/podio-php-master/lib/Podio.php on line 291`

Here is my code:

//dummy item_id
$item_id = 123456789;

//dummy field_id      
$field_id = 987654321;

//Get the category field value
$item = PodioItem::get_field_value($item_id, $field_id);

//Create a variable with the text of the selected category option for validation
$button_value = $item[0]['value']['text'];

//Print the text of the selected option
print $button_value;

//Now that I have validated the current selection I want to change it 
//These are the names of the attributes for my category
$my_attributes = array("status", "text", "id", "color");

//These are the values I want to update them to
$my_options = array("active","Generated",21,"DCEBD8");

//This should update the record in podio with the new values
PodioItemField::update($item_id, $field_id, $my_attributes, $my_options);

I reviewed all of the examples in the documentation but I feel like I'm missing something simple. Is anyone familiar with this that can tell me what I'm doing wrong? I've tried to comment the code to make it clear what I expect to be happing on each line but I can definitely clarify more if needed.


Solution

  • You are passing the attributes in the wrong method. To update the Category field you just pass the id of the option that you want to change in an array. So the $my_attributes array must be like,

    $my_attributes = array(21);//id of the category option
    

    And the $my_options array should like this,

     $my_options = array('silent' => true, 'hook' => false);
    

    This should update the item in Podio with the new values,

    PodioItemField::update($item_id, $field_id, $my_attributes, $my_options);