I am trying to create a dropdown to show a user a list of customers based on their current access.
I have two user scenarios:
- Users who can see all customers (user has permissions for customers set to View All)
- Users who are limited to their customers
I can’t do a generic search with a filter based on hubspot_ower_id because then all users would be limited to just the companies they own.
I found some API documentation for Public Permissions
(Public Permissions API documentation )
I don’t beleive that the Settings>Users>Public permissions API has a wrapper around it so based on the Github documentation I’ve wrapped the call in a generic API call.
$resource = 'hcrn:2637216:crm-object:' . $objCode . ':' . $objID['id'];
$path = '/resource-permissions/v3/permitted-users?resource=' . $resource;
try {
$response = $Factory->apiRequest([
'method' => 'GET',
'path' => $path,
'headers' => [
'Authorization' => 'Bearer ' . $accessToken,
'Content-Type' => 'application/json',
'Accept' => 'application/json, */*;q=0.8'
],
'defaultJson' => true
]);
} catch (ApiException $e) {
echo "Exception when calling visibility api: ", $e->getMessage();
continue;
}
Where the objCode is 0-2 and the Id is an id of a customer record.
The call returns a listing of the user id’s who can see the object.
I then have to take that set of allowed users and check it agains the logged in users id. When trying to search multiple customers, the API call sometimes fails with a 500 code. If it does go through, it is slow to make all of the calls.
For now I am limited the search results to find customers that match K (for example) to 10 returned. I then check all 10 with individual API calls.
My questions:
- Is there a different way to, based on users email / user ID, limited the CRM customers they can see?
- Is there a way to make a call to the permitted-users API for multiple ID’s at the same time. The documentation says that you can, but there doesn’t seem to be any notes on the format it would need to take. I’ve tried &hcrn… and it comes back with a validation error.