Post

1 follower Follow
2
Avatar

Unable to insert field value for PodioAppItemField

Hi,

I am creating a new item and adding an app reference. I am following the docs and have tried everything but podio fails if i try to set this value. Here is what I am doing. (I've simplified this):

_$app = new PodioApp(111); _

_$item = new PodioItem(array( 'app' => $app, 'fields' => array(), )); _

_$item->fields = array(

    new PodioTextItemField('title'),

    new PodioAppItemField('app-reference'),

); _

_$item->field('title')->set_value('hello');

$item->field('app-reference')->set_value(22222); _

$item->save();

In this example, 22222 is the item_id of the referenced app item. I've tried placing this value into an array as well as an associative array but I get :

*Error! *

*PodioForbiddenError [ Error ]:

/usr/local/zend/apache2/htdocs/eduserv1/trunk/fuel/vendor/podio/podio-php/lib/Podio.php @ line 238 *

Please help.

Ben Hoffman Answered

Please sign in to leave a comment.

12 comments

0
Avatar

Hi Ben,

It would appear that you are using the app_item_id (from the URL). You need to use the item_id for the value. Go to the item you want to reference and click the little cloud icon in the right side of the grey bar at the top of the item to get the ID.

/Andreas

Andreas Haugstrup Pedersen 0 votes
0
Avatar

Hi Andreas,

Actually, I had done that at first but am now using item_id, not app_item_id. So this value actually comes from:

$parentProject = PodioItem::get_by_external_id(<<project App Id>>, $projectExternalId);

later...

$item->field('app-reference')->set_value(array('item_id'=>parentProject->item_id));

Ben Hoffman 0 votes
0
Avatar

Andreas, here is the log entry for the POST. It is trying to post to the correct app. The "parent" item_id 99641444 is correct. New new "child" id makes sense. But I get this error:

2013-11-27 16:21:16 403 POST /item/app/5799238/

2013-11-27 16:21:16 Request body: {"fields":{"title":[{"value":"xzczxc"}],"section-title":[{"value":"zczc"}],"description-of-problem":[],"type-2":[1],"status2":[1],"priority2":[1],"browser2":[1],"reporter":[{"value":"Ben Hoffman"}],"page-title":[{"value":"sdfsmsdf"}],"page-id":[{"value":"dcms-c5388464-43fc-45d9-a666-35b54790b8fc"}],"page-file":[{"value":"c_cns206_titlepage_d55.html"}],"page-link":[{"embed":15522490,"file":null}],"app-reference":[99641444]},"app":{"app_id":5799238}}

2013-11-27 16:21:16 Reponse: {"error_parameters":{},"error_detail":null,"error_propagate":false,"request":{"url":"http:\/\/api.podio.com\/item\/app\/5799238\/","query_string":"","method":"POST"},"error_description":"The app with id 5799257 does not have the right view on embed with id 15522490","error":"forbidden"}

Ben Hoffman 0 votes
0
Avatar

Andreas. Strangely, if I do not try to add the app-reference, all posts fine including the embedField. However, if I do not POST the embed field, the app reference will now POST!.   Now I am focusing on that embed field which I believe I am posting properly as I do the same in other places. Weird how it's one or the other.

Ben Hoffman 0 votes
0
Avatar

So what this is telling me is, I can add a record to the "child" app as long as I don't specify a "parent" app reference. Or, I can specify a "parent" app as long as the child has no EmbedField. BUT, if I specify a parent app AND the child has am EmbedField, the parent has some sort of rights problem with that.

Latest Log entry:

2013-11-27 16:59:29 403 POST /item/app/5799238/

2013-11-27 16:59:29 Request body: {"fields":{"title":[{"value":"xzczxc"}],"section-title":[{"value":"zczc"}],"description-of-problem":[],"type-2":[1],"status2":[1],"priority2":[1],"browser2":[1],"reporter":[{"value":"Ben Hoffman"}],"page-title":[{"value":"fdsfsfsad"}],"page-id":[{"value":"dcms-c5388464-43fc-45d9-a666-35b54790b8fc"}],"page-file":[{"value":"c_cns206_titlepage_d55.html"}],"page-link":[{"embed":15526985,"file":66238144}],"app-reference":[99641444]},"app":{"app_id":5799238}}

2013-11-27 16:59:29 Reponse: {"error_parameters":{},"error_detail":null,"error_propagate":false,"request":{"url":"http:\/\/api.podio.com\/item\/app\/5799238\/","query_string":"","method":"POST"},"error_description":"The app with id 5799257 does not have the right view on embed with id 15526985","error":"forbidden"}

Ben Hoffman 0 votes
0
Avatar

Are kyou by any chance re-using an embed_id from another item? Embeds are only valid for the item they are originally attached to. You must create a new embed (with a fresh embed_id) for each item you are creating.

Andreas Haugstrup Pedersen 0 votes
0
Avatar

First I have a :

$item->fields = array(

new PodioEmbedItemField('page-link'),

Then:

$attributes = array( 'url' => urldecode($urlString) );

$pageLink = \PodioEmbed::create( $attributes );

$item->field('page-link')->set_value($pageLink);

Ben Hoffman 0 votes
0
Avatar

Sorry... can't edit post above. Missing end paren but I think you get what I'm doing. Again, this works fine unless I also add a PodioAppItemField as well. If I leave it out, the PodioAppItemField works fine. It's one or the other.

Ben Hoffman 0 votes
0
Avatar

Hi Andreas,

This problem seems to be resolved. The only difference now is that I removed the urldecode() around the url string and I wrap the final value in an array ( $item->field('page-link')->set_value(array($pageLink)); )

I had tried this earlier but it DIDN'T work. Earlier than that it DID work as long as I didn't save the app-reference. Frankly I'm confused about why this is now working and since I can't debug the service layer, that's as far as I can go.

Thanks,

Ben

Ben Hoffman 0 votes