Post

2 followers Follow
0
Avatar

Update Category in Item

I've tried multiple methods of changing a category from option 1 to option 2 and none of them are working properly.

Examples:

$item = PodioItem::get_basic($ItemID);
$field_id = 'print-to-pdf';

$item->fields[$field_id]->values = 2;

(this is the simplest version, following the API documentation. The category doesn't change. $ItemID is retrieved from the original POST and is correct)

PodioItem::update($ItemID, array('fields' => array("print-to-pdf" => array('id' => 2))));

(This is typically used for updating multiple fields but can be used for one as well, doesn't work.)

PodioItemField::update( $ItemID, $FieldID, array(), array(2));

(This one I've used to successfully update raw data fields, but it isn't working for categories.)

Could I get some help here?

Thank you

Samson Burton

Please sign in to leave a comment.

12 comments

0
Avatar

Hi Samson,

I'm not sure what the issue is, however please note that the value 2 is id of the option. It may be the case you have two options "Green" and "Blue", but they have ids 17 and 42.

Let me know if the above doesn't fix it for you.

Best,
Andreas

Andreas Garnæs 0 votes
Comment actions Permalink
0
Avatar

The problem is this. I have a Podio item with a category field. The option ID's of the categories are 1, 2, and 3. When option 1 is selected within the Podio platform, a webhook is triggered and a php script on my server runs. However, after the script runs I need to change the selected option from "1" to "2". (these are the optionIDs). The problem is, whatever script I run, following the API documentation, the category does not update from option 1 to option 2.

Simply put, using PHP I'm trying to select the second option of my category within an item.

Any help?

Samson Burton 0 votes
Comment actions Permalink
0
Avatar

So here's the output from the log file.

2015-09-19 00:47:40 400 PUT /item/322660606
2015-09-19 00:47:40 Request body: {"fields":{"print-to-pdf":{"id":2}}}
2015-09-19 00:47:40 Reponse: {"error_parameters":{},"error_detail":null,"error_propagate":false,"request":{"url":"http:\/\/api.podio.com\/item\/322660606","query_string":"","method":"PUT"},"error_description":"Invalid value null (null): Not a valid option","error":"invalid_value"}
This was created using the PHP code:
PodioItem::update($ItemID, array('fields' => array("print-to-pdf" => array('id' => 2))));
So from what I understand it's telling me that my 'id' entry is wrong? But here is the item information:
{
"status": "active",
"external_id": "print-to-pdf",
"config": {
"default_value": null,
"description": null,
"settings": {
"multiple": false,
"options": [
{
"status": "active",
"text": "Create engagement",
"id": 1,
"color": "DCEBD8"
},
{
"status": "active",
"text": "Engagement letter created",
"id": 2,
"color": "DCEBD8"
},
{
"status": "active",
"text": "Engagement letter sent",
"id": 3,
"color": "DCEBD8"
}
],
"display": "inline"
},
So I don't understand why it is telling me the value is wrong.
Any idea what is going on here??

Samson Burton 0 votes
Comment actions Permalink
0
Avatar

Using that method still doesn't work. My code is as follows:

            $item = PodioItem::get_basic($ItemID);

    $field_id = 'print-to-pdf';

    // Set value to a single option
    $item->fields[$field_id]->values = 3; // option_id=4

$ItemID comes from the webhook that is triggered.

The log file is too large to post here, but I've uploaded it at this link: http://www.filedropper.com/podio

The request should be made at the end, but I'm not seeing it.

Samson Burton 0 votes
Comment actions Permalink
0
Avatar

This is now the code. Still not updating the category.

            $item = PodioItem::get_basic($ItemID);
            $field_id = 'print-to-pdf';

            // Set value to a single option
            $item->fields[$field_id]->values = 2; // option_id=4
            $item->save();
Samson Burton 0 votes
Comment actions Permalink
0
Avatar

What does the log output look like now? Is the update request present?

Andreas Garnæs 0 votes
Comment actions Permalink
0
Avatar

My suggestions would be to either try:

$field = $item->fields["print-to-pdf"];
$field->values = 2;
$field->save();

Or go back to your original approach and use:

PodioItem::update($ItemID, array('fields' => array("print-to-pdf" => 2)));
Andreas Garnæs 0 votes
Comment actions Permalink