Search code examples
phppodio

How to create Items in Podio using podio-php?


Podio's API documentation differs from podio-php's when it comes to creating new Items.

Based on Podio's tutorial, I would have to format each value according to its type, whereas podio-php describes using PodioItemFieldCollection to handle that for you. I prefer the latter option, but I keep getting this error:

Invalid value "1" (string): Not a valid option

I don't see much difference in my code versus the example given by podio-php. What's causing this error?

$fields = new PodioItemFieldCollection(array(
    new PodioTextItemField(array("external_id" => "my-text-field", "values" => "FooBar")),
    new PodioProgressItemField(array("external_id" => "my-number-field", "values" => 75))
));    

$atts = array(
    'app' => new PodioApp($app_id), 
    'fields' => $fields
);

$item = new PodioItem($atts);

No errors caught up to here. But when I try to save...

$response   = $item->save();

Invalid value "1" (string): Not a valid option

Solution

  • The $app_id was being passed in as a string. I've had this issue now with a few different ID values returned in an API response. I explicitly cast the value as an integer and the error went away:

    $atts = array(
        'app'    => new PodioApp((int)$app_id), 
        'fields' => $fields
    );