Add new item

Answered

Comments

10 comments

  • Andreas Haugstrup Pedersen

    Hi Hen,

    What's the contents of your $attributes variable?

    /Andreas

    0
    Comment actions Permalink
  • Manu Raj

    Hi Andreas,

                         $attributes contain  some field id and values of the field

     

    'external_id' =>

    string

    'sales-test-item' (length=15)
    'fields' =>
    array (size=5)
    'meeting-title' =>

    string

    'StepTech Item testig' (length=20)
    'purpose-of-meeting' =>

    string

    'Qualify lead' (length=12)
    'date-of-meeting' =>
    array (size=6)
    'end' =>

    string

    '2013-09-03 19:30:00' (length=19)
    'end_date' =>

    string

    '2013-09-03' (length=10)
    'start_time' =>

    string

    '19:00:00' (length=8)
    'start' =>

    string

    '2013-09-03 19:00:00' (length=19)
    'end_time' =>

    string

    '19:30:00' (length=8)
    'start_date' =>

    string

    '2013-09-03' (length=10)
    'organiser' =>
    array (size=21)
    'about' =>

    string

    'I am Not BAD..........But I am Not sure............' (length=51)
    'user_id' =>

    int

    1651359
    'external_id' => null
    'name' =>

    string

    'Hen Raj' (length=7)
    'rights' =>
    array (size=3)
    ...
    'url' =>
    array (size=1)
    ...
    'title' =>
    array (size=1)
    ...
    'space_id' => null
    'profile_id' =>

    int

    78398073
    'org_id' => null
    'connection_id' => null
    'birthdate' =>

    string

    '1990-09-04' (length=10)
    'last_seen_on' =>

    string

    '2013-09-04 04:01:44' (length=19)
    'phone' =>
    array (size=1)
    ...
    'link' =>

    string

    'https://podio.com/users/1651359' (length=31)
    'avatar' =>

    int

    42251966
    'mail' =>
    array (size=1)
    ...
    'organization' =>

    string

    '
    StepTechInfo Solutions (P) Ltd' (length=27) 'type' =>

    string

    'user' (length=4)
    'image' =>
    array (size=7)
    ...
    'location' =>
    array (size=1)
    ...
    'participants' =>
    array (size=21)
    'about' =>

    string

    'I am Not BAD..........But I am Not sure............' (length=51)
    'user_id' =>

    int

    1651359
    'external_id' => null
    'name' =>

    string

    'Hen Raj' (length=7)
    'rights' =>
    array (size=3)
    ...
    'url' =>
    array (size=1)
    ...
    'title' =>
    array (size=1)
    ...
    'space_id' => null
    'profile_id' =>

    int

    78398073
    'org_id' => null
    'connection_id' => null
    'birthdate' =>

    string

    '1990-09-04' (length=10)
    'last_seen_on' =>

    string

    '2013-09-04 04:01:44' (length=19)
    'phone' =>
    array (size=1)
    ...
    'link' =>

    string

    'https://podio.com/users/1651359' (length=31)
    'avatar' =>

    int

    42251966
    'mail' =>
    array (size=1)
    ...
    'organization' =>

    string

    'StepTech Info Solutions (P) Ltd' (length=27)
    'type' =>

    string

    'user' (length=4)
    'image' =>
    array (size=7)
    ...
    'location' =>
    array (size=1)
    ...

    0
    Comment actions Permalink
  • Andreas Haugstrup Pedersen

    The paste went a little wrong. Can you print_r the contents instead of var_dump?

    0
    Comment actions Permalink
  • Manu Raj

     

    Array ( [external_id] => sales-test-item [fields] => Array ( [meeting-title] => StepTech Item testig [purpose-of-meeting] => Qualify lead [date-of-meeting] => Array ( [end] => 2013-09-03 19:30:00 [end_date] => 2013-09-03 [start_time] => 19:00:00 [start] => 2013-09-03 19:00:00 [end_time] => 19:30:00 [start_date] => 2013-09-03 ) [organiser] => Array ( [about] => I am Not BAD..........But I am Not sure............ [user_id] => 1651359 [external_id] => [name] => Hen Raj [rights] => Array ( [0] => view [1] => update [2] => delete ) [url] => Array ( [0] => http://spartanzofit.blogspot.com ) [title] => Array ( [0] => Programmer ) [space_id] => [profile_id] => 78398073 [org_id] => [connection_id] => [birthdate] => 1990-09-04 [last_seen_on] => 2013-09-04 04:22:30 [phone] => Array ( [0] => 09659685551 ) [link] => https://podio.com/users/1651359 [avatar] => 42251966 [mail] => Array ( [0] => itstephen34@gmail.com ) [organization] => Naga Info Solutions (P) Ltd [type] => user [image] => Array ( [perma_link] => [hosted_by] => podio [hosted_by_humanized_name] => Podio [thumbnail_link] => https://d3szoh0f46td6t.cloudfront.net/public/42251966 [link] => https://d3szoh0f46td6t.cloudfront.net/public/42251966 [file_id] => 42251966 [link_target] => _blank ) [location] => Array ( [0] => Nagercoil ) ) [participants] => Array ( [about] => I am Not BAD..........But I am Not sure............ [user_id] => 1651359 [external_id] => [name] => Hen Raj [rights] => Array ( [0] => view [1] => update [2] => delete ) [url] => Array ( [0] => http://spartanzofit.blogspot.com ) [title] => Array ( [0] => Programmer ) [space_id] => [profile_id] => 78398073 [org_id] => [connection_id] => [birthdate] => 1990-09-04 [last_seen_on] => 2013-09-04 04:22:30 [phone] => Array ( [0] => 09659685551 ) [link] => https://podio.com/users/1651359 [avatar] => 42251966 [mail] => Array ( [0] => itstephen34@gmail.com ) [organization] => Naga Info Solutions (P) Ltd [type] => user [image] => Array ( [perma_link] => [hosted_by] => podio [hosted_by_humanized_name] => Podio [thumbnail_link] => https://d3szoh0f46td6t.cloudfront.net/public/42251966 [link] => https://d3szoh0f46td6t.cloudfront.net/public/42251966 [file_id] => 42251966 [link_target] => _blank ) [location] => Array ( [0] => Nagercoil ) ) ) ) 

    0
    Comment actions Permalink
  • Andreas Haugstrup Pedersen

    Can you post your source code as well (remove any API keys, passwords etc.)

    0
    Comment actions Permalink
  • Manu Raj

    $app_id = 5303855;

    $app_item_details=PodioItem::filter($app_id);

    $attributes = array();

    foreach($app_item_details['items'] as $key=>$value)

    {

    $item_id = $value->__attributes['item_id'];

    $get_item_detail = PodioItem::get( $item_id );

    foreach($get_item_detail->__attributes["fields"] as $key1 => $value1)

    {

    // var_dump($value1);

    if(!empty($value1->__attributes["values"][0]["value"])){

    $attributes[ $value1->__attributes["external_id"] ] = $value1->__attributes["values"][0]["value"];

    }

    else{

    $attributes[ $value1->__attributes["external_id"] ] = $value1->__attributes["values"][0];

    }

    // var_dump($value1->__attributes["external_id"]);

    // var_dump($value1->__attributes["values"][0]);

    }

    }

    //var_dump($attributes["organiser"]);

    $create_item=PodioItem::create(5303855,

    array(

    "external_id" => "sales-test-item",

    'fields' =>

    array(

    "meeting-title" => "StepTech Item testig",

    "purpose-of-meeting" => "Qualify lead",

    "date-of-meeting" => $attributes["date-of-meeting"],

    "organiser" => $attributes["organiser"],

    "participants" => $attributes["participants"]

    )

    ),

    array()

    );

    }

    catch (PodioError $e) {

    // echo $err="Incorrect Username /Password";

    //Something went wrong. Examine $e->body['error_description'] for a description of the error.

    echo $e;

    //print_r($e->body); # Parsed JSON response from the API

    //print_r($e->status); # Status code of the response

    //print_r($e->url); # URI of the API request

    // You normally want this one, a human readable error description

    //print $e->body['error_description'];

    // $e->body['error_description'];

    }

    0
    Comment actions Permalink
  • Andreas Haugstrup Pedersen

    Hi Manu,

    Are you just trying to clone an item? If so there are better ways. You should pretty much never touch __attributes as podio-php has much nicer ways of working with the data.

    If you're just cloning an item there's a dedicated API operation for that: https://developers.podio.com/doc/items/clone-item-37722742 Use that is possible.

    If you need to change some values before creating the new item it's much better to use the available methods on the PodioItem object rather than mess around with __attributes. The data structures for items can quickly become quite complex and podio-php can do a lot to help you.

    Side note: PodioItem::filter() already returns PodioItem objects so there's no reason to call PodioItem::get() on each member of the collection. You'll just make your script slower.

    When you have a PodioItem object you can use methods like remove_field to remove unwanted fields or add_field to add new fields. On each field you can use set_value to modify the value of the field. On the PodioItem object you can e.g. remove the id property and call the save method and not have to worry about formatting the data correctly. You can see a ton of examples here: https://github.com/podio/podio-php/blob/master/examples/items.php

    /Andreas

    0
    Comment actions Permalink
  • Hen Raj

    Hi Andreas ,

    Thank you for your guidance i will turn my script what your mention  

    0
    Comment actions Permalink
  • Hen Raj

    Hi Andreas,

    Thanks for your guidance. My actual task to create a new product and also import new product programatically using Podio API Create function.When I executing the Create function, I trigerred and error like this

    PodioBadRequestError: "Invalid field 41253656 ('value'): Invalid value None (null): must be integer or null or JsonifiableAdaptable or null" Request URL: http://api.podio.com/item/app/5303855/ Request Body: null Stack Trace: #0 C:\wamp\www\Podio_Import _Test\lib\Podio.php(271): Podio::request('POST', '/item/app/53038...', Array, Array) #1 C:\wamp\www\Podio_Import _Test\models\PodioItem.php(141): Podio::post('/item/app/53038...', Array) #2 C:\wamp\www\Podio_Import _Test\add_item_test.php(150): PodioItem::create(5303855, Array, Array) #3 {main}

    COuld you please mention, Is there any format for passing arguments in this function ? 

    Hope you guys will reply ASAP

    Thanks

    0
    Comment actions Permalink
  • Andreas Haugstrup Pedersen

    Hi,

    As I mentioned in my previous comment the data structures can quickly becomes very complex when working with items. For that reason it's much much simpler to work with the objects podio-php provides for you. I've given you the longer explanation above with a link to some examples on how to use these objects.

    /Andreas

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk