Create Podio Item with different fields

Answered

Comments

6 comments

  • Andreas Haugstrup Pedersen

    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

    0
    Comment actions Permalink
  • Wurstsalat

    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?

    0
    Comment actions Permalink
  • Wurstsalat

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

    0
    Comment actions Permalink
  • Wurstsalat

    Still no underdashes ....

    0
    Comment actions Permalink
  • Andreas Haugstrup Pedersen

    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

    0
    Comment actions Permalink
  • Wurstsalat

    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.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk