问题
I am attempting to add a contact to a contact field, the field currently has no information in the app. I originally attempted this through app authentication but found this post on Podio forum and this on here and changed authentication to user.
The user is a workspace admin, the profile_id I am adding is a workspace member and the app has no restrictions on it.
What am I missing and how do I resolve the issue?
$item_id = 1111111;
$field_id = 2222222;
$profile_id = 3333333;
Podio::authenticate_with_password( 'admin_user_email', 'password' );
$item = PodioItem::get_basic( $item_id );
$external_id = 'sign-off-authority';
$contact = new PodioContactItemField( array( 'field_id' => $field_id, 'external_id' => $external_id, 'values' => array( 'profile_id' => $profile_id ) ) );
$item->fields[] = $contact;
$item->save();
results in the following stacktrace:
Fatal error:
Uncaught PodioForbiddenError:
"The user with id #### does not have the right view on profile with id ####"
Request URL: http://api.podio.com/item/1111111 Stack Trace:
#0 C:\xampp\htdocs\podio-api\lib\Podio.php(322): Podio::request('PUT', '/item/1111111', Array)
#1 C:\xampp\htdocs\podio-api\models\PodioItem.php(184): Podio::put('/item/1111111', Array)
#2 C:\xampp\htdocs\podio-api\models\PodioItem.php(67): PodioItem::update(1111111, Array, Array)
#3 C:\xampp\htdocs\getItems.php(48): PodioItem->save()
#4 {main} thrown in C:\xampp\htdocs\podio-api\lib\Podio.php on line 286
回答1:
I found out that either php or podio's php api library was converting my stored value into an array and not retaining it as an integer value. I tried using both user_id and profile_id with neither working, until I realised through output logs what was happening. I had to update the code to this:
$profile_id = 3333333;
$arr = [];
$arr['profile_id'] = $profile_id;
$contact = new PodioContactItemField( array( 'field_id' => $field_id, 'external_id' => $external_id, 'values' => $arr ) );
by creating an array and adding that to the object it retained it's preset format and was accepted by the api. Now the code runs fine.
回答2:
It works for me using user_id instead of profile_id. Can you give it a try?
Here is working example in ruby:
Podio.client.authenticate_with_credentials(<user_email>, <user_password>)
field_external_id = 'requester'
field_new_value = [{'value' => {'type' => 'user', 'id' => <some_other_user_id>}},
{'value' => {'type' => 'user', 'id' => <different_user_id>}}]
Podio::ItemField.update(item_id, field_external_id, field_new_value)
来源:https://stackoverflow.com/questions/40908970/the-user-with-id-does-not-have-the-right-view-on-profile-with-id