Create Podio Item with different fields
AnsweredHello,
I am aware that this question was discussed before, but some of the entries are older then 2 years. I want to create an item in Podio with different types of fields. It works fine for simple text fields by using
$item = PodioItem::create(%APPID%, array('fields') => array("textfield" => 'example'));
But, I when I want to include field types like Embed, Reference, etc. I run into trouble because it returns a Bad Podio request. I tried to attach fields after creation like following
$field_id = %FIELDID%;
$field = new PodioAppItemField($field_id);
$field->set_value($item->item_id);
PodioItemField::update($item->item_id, $field_id, $field->as_json(false));
But, this yields an error and does not go thru to Podio. Could you please show an example how to accomplish this task.
Thank you!
-
These days it's generally simpler to create a PodioItem object rather than deal with the raw attributes. You can find a bunch of documentation at http://podio.github.io/podio-php/items/ and related pages
-
Hello,
it is my first time working with PodioAPI. It takes a while to get used to all the datastructures. But looking at the different test files helped me. I have one more question with a date field in format Y-m-d. I used the followingnew PodioDateItemField(array("external_id" => "datum", "values" => array("start_date_utc" => DateTime::createFromFormat('Y-m-d', $datum, new DateTimeZone('UTC'))))),
It goes through fine but I get the following PHP error
Undefined index: starttimeutc in PodioDateItemField->setvalue() (Line 482 in /podio-php/models/PodioItemField.php), Notice: Undefined index: starttimeutc in PodioDateItemField->setvalue() (Line 488 in /podio-php/models/PodioItemField.php).
Can you help?
-
Hi Simon,
You can see all the properties you can set in the documentation: http://podio.github.io/podio-php/fields/#date-field
The short version: Don't use the
utc
properties. Just set the regular properties, timezone management will be handled for you if you pass in DateTime objects as the values/Andreas
-
Just as a reference.
// Create field collection with different fields $fields = new PodioItemFieldCollection(array( new PodioTextItemField(array("external_id" => "name", "values" => $name)), new PodioDateItemField(array("external_id" => "date")), new PodioLocationItemField(array("external_id" => "city", "values" => array("value" => $city))), new PodioEmbedItemField(array("external_id" => "website")), new PodioAppItemField(array("external_id" => "contact", "values" => array("item_id" => $item_id_contact))), new PodioTextItemField(array("external_id" => "comment", "values" => $comment)) )); // Create item and attach fields $item = new PodioItem(array( "app" => new PodioApp(intval($app_id)), "fields" => $fields )); // Attach website if(!filter_var($website, FILTER_VALIDATE_URL) && !empty($website)){ $field_id = "website"; $embed = PodioEmbed::create(array("url" => $website)); $item->fields[$field_id]->values = $embed; } // Attach date $field_id = "date"; $item->fields[$field_id]->start_date = $date; // Save item $item->save();
The variables have to be set respectively.
Please sign in to leave a comment.
Comments
6 comments