Problem with contacts
Hi,
i have written a script that uses my account auth to change the contact on a couple of customers. Strangely i get the following error:
The user with id 1009728 does not have the right view on profile with id 1037122
Even though i can change the manually myself, what am i doing wrong?
-
It looks like this:
$customers = PodioItem::filter(2382740,array('limit'=>50,'offset'=>$i*50));
$customers = $customers['items'];
foreach ($customers as $customer) {
$sales=trim(strip_tags($customer->field('sales')->attributes['values'][0]['value']));
$sales_id=$users[$sales];
}
$customer->fields=array(new PodioTextItemField('sales-agent'));
$customer->field('sales-agent')->set_value($sales_id);
$customer->save(); -
What is it you're trying to do? I'm pretty sure your code will not do whatever you're trying to do. You have the final three lines outside of your loop so each customer item will not be saved. And on the third-to-last line you override all field values on the item -- are you trying to add a field to the item?
Are you migrating values from a text field into a contact field?
-
I'm in California so I sleep when you are awake :)
The sales_id -- you are certain this is a profile_id? In Podio users have both a user_id and a profile_id. The contact field only accepts profile_ids.
A few other random tips:
- You don't have to access 'attributes' like that. In your case you'll get the exact same result from: $sales=trim($customer->field('sales')->humanized_value());
- If you want to save some bytes and keep things simpler you can call save() directly on the ItemField. Then only that field value will be sent to the API and you don't have to worry about accidentally updating something you didn't intend to: $customer->field('sales-agent')->save();
-
Hi,
thanks for the pointers, i have switched to the profile_id and i use the humanized_value. Stil when i do:
$customer->field('sales-agent')->set_value($sales_id);
$customer->field('sales-agent')->save();the second line throws:
The user with id 1009728 does not have the right view on profile with id 1037122
-
Could you perhaps try the code? It looks like this (sales-agent is a contact field and sales is a text field):
require_once '../podio-php/PodioAPI.php';
Podio::$debug = true;
Podio::setup(CLIENT_ID, CLIENT_SECRET);
Podio::authenticate('password', array('username' => MY_USERNAME, 'password' => MY_PASSWORD));$users=array();
try {
$org=PodioOrganization::get_all();
$org_id=$org[0]->org_id;$contacts=PodioContact::get_all();
foreach ($contacts as $contact) {
$users[$contact->name]=$contact->profile_id;
}
echo count($users)." users loaded\n";for ($i=0;$i<50;$i++) {
$customers = PodioItem::filter(MY_APP_ID,array('limit'=>50,'offset'=>$i*50));
$customers = $customers['items'];
foreach ($customers as &$customer) {
$sales=trim(strip_tags($customer->field('sales')->humanized_value()));
if (array_key_exists($sales,$users)) {
$sales_id=$users[$sales];
$customer->field('sales-agent')->set_value($sales_id);
$customer->field('sales-agent')->save();
}
}
}
} catch (PodioError $e) {
print $e->body['error_description'];
} -
Hi Carl
It does look like it is the wrong profile_id, but I can't really understand why that would be the case. The alleged profile_id is indeed a user_id for a user in the same organization as you. Can you check that it is failing with the exact same error message, and not on another id?
Christian
-
Hey Carl,
$sales_id is probably a blank string, so you're trying to save a blank string into a place where a numeric id would go. On your end you should make sure that $sales_id is not a blank string. I have it on my list to make the client a little smarter when it comes to null values, but for now you have to handle it.
/Andreas
Please sign in to leave a comment.
Comments
18 comments