如何使用Podio PHP API为新项目设置类别字段


How to set category field for new item with Podio PHP API

我有一个Podio应用程序,它由php API通过网站上的表单填充。

使用Create Item片段适用于文本字段、货币值等,但我一直无法解开如何设置类别字段的文档。

类别字段"出席"是一个简单的是/否选项。

这里显示的方法在与创建项目片段组合时会生成一个服务器错误,如下所示:

$fields = new PodioItemFieldCollection(array(
      new PodioTextItemField(array("external_id" => "title", "values" => $name)),
      new PodioTextItemField(array("external_id" => "email", "values" => $email)),
));
$item = new PodioItem(array(
    'app' => new PodioApp(intval($app_id)),
    'fields' => $fields,
));
pseudo code: if attending = yes, $attending = 1, else $attending = 2 //id's of yes and no in category field
$item->fields['attending']->values = $attending;
$item->save();

我错过了什么?谢谢

对于那些仍在寻找答案的人:诀窍是使用数组

在打开收藏之前对$attenting进行评估,然后简单地将此行添加到PodioItemFieldCollection中。

new PodioCategoryItemField(array(
   'external_id' => 'attending', 'values' => array($attending))),

所以整个片段看起来像这个

($foo == 'yes') ? $attending = 1: $attending = 2 ; // evaluating $foo for yes
$fields = new PodioItemFieldCollection(array(
  new PodioTextItemField(array("external_id" => "title", "values" => $name)),
  new PodioTextItemField(array("external_id" => "email", "values" => $email)),
  new PodioCategoryItemField(array(
    'external_id' => 'attending', 'values' => array($attending))) // must be an array
));
$item = new PodioItem(array(
'app' => new PodioApp(intval($app_id)),
'fields' => $fields,
));
$item->save();

您可以在以下位置找到示例:http://podio.github.io/podio-php/fields/#category-现场

如果仍然不起作用,请将podio-php置于调试模式,这样您就可以查看发送到podio的数据:http://podio.github.io/podio-php/debug/