1

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
HWD
  • 1,547
  • 7
  • 36
  • 72
  • Sorry, looks like you have a typo in $atts array: a quote before `app' =>` is missing. But anyways, are you sure `$app_id` is set correctly? This is the only difference from the tutorial I can see. – Eugen Baryshnikau Apr 16 '20 at 12:30

1 Answers1

1

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
);
HWD
  • 1,547
  • 7
  • 36
  • 72