Post

2 followers Follow
4
Avatar

Create Podio Item with different fields

Hello,

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!

Wurstsalat Answered

Please sign in to leave a comment.

6 comments

0
Avatar

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 following

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

Wurstsalat 0 votes
0
Avatar

Appearently some of the underdashes went missing. It states start_time_utc.

Wurstsalat 0 votes
0
Avatar

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.

Wurstsalat 0 votes