Update Category in Item

Comments

12 comments

  • Andreas Garnæs

    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

    0
    Comment actions Permalink
  • Samson Burton

    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?

    0
    Comment actions Permalink
  • Andreas Garnæs

    It should work then. Could you try enable debugging and share the output please? http://podio.github.io/podio-php/debug/

    0
    Comment actions Permalink
  • Samson Burton

    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??

    0
    Comment actions Permalink
  • Andreas Garnæs

    What does the output look like if you use the approach described here instead? http://podio.github.io/podio-php/fields/#setting-values-1

    0
    Comment actions Permalink
  • Samson Burton

    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.

    0
    Comment actions Permalink
  • Andreas Garnæs

    I think there's a save missing as shown here: http://podio.github.io/podio-php/items/#change-field-value

    0
    Comment actions Permalink
  • Samson Burton

    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();
    
    0
    Comment actions Permalink
  • Andreas Garnæs

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

    0
    Comment actions Permalink
  • Samson Burton

    No, it's still not showing the update. Not that I'm seeing anyway. The final request is a GET request.

    Here's the new log.

    http://www.filedropper.com/podio_1

    0
    Comment actions Permalink
  • Andreas Garnæs

    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)));
    
    0
    Comment actions Permalink
  • Samson Burton

    That worked!! Fantastic!! Thank you so much!!

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk