I followed
https://developers.hubspot.com/docs/guides/api/settings/users/public-permissions documentation for retrieving a contact’s permitted user lists according to the create, delete, and update options. But I want to retrieve a contact’s permissions for only one user.
I followed this https://developers.hubspot.com/docs/guides/api/settings/users/public-permissions documentation, But I have to load all contacts for filter specific user’s contacts permissions. This took too much time for me. Is there any direct solutions for Retrieve specific user’s contacts permissions?
Hi @HWimalasiri and welcome, we are delighted to see you here!
Great question, thanks for asking the HubSpot Community!
I am glad to see that you already explored the permission endpoints for that, thanks!
I’d love to ask our Top Experts: Hi @sylvain_tirreau, @Anton and @zach_threadint do you have a workaround or a way to help @HWimalasiri for a specific user, please?
Have a lovely day and thanks so much in advance for your valuable contributions!
Bérangère
As the documentation you mention says, you give the id of the object you want to retrieve at the end of hcrn (resourceId).
hcrn:{accountId}:{resourceType}:{resourceTypeId}:{resourceId}
Examples with portail 999999:
If you want to recover a contact’s permissions for contact id 123456:
hcrn:999999:crm-object:0-1:123456
If you want to retrieve a user’s permissions for user id 654321:
hcrn:999999:crm-object:0-115:654321
Yes @sylvain_tirreau . I also tried that parameter you mentioned here.
But it shows the “Object type id 0-115 is not supported” message to me.
Yes, that’s normal. Sorry to have misled you.
You can only retrieve users for a contact (deal, ticket, company) with this API. Nothing else.
But you can build a helper like that (my example is in Python) :
def get_user_permissions(data: dict, user_id: int) -> dict:
user_perms = {}
resources = data.get("resources", {})
for resource_id, actions in resources.items():
perms = []
for action_name, info in actions.items():
if user_id in info.get("permittedUsers", []):
perms.append(action_name)
if perms:
user_perms[resource_id] = perms
return user_perms
This way you pass the result (I took the response code from the documentation page) of your query (hcrn:999999:crm-object:0-1:123456) into the function:
user_id = 2620022
perms = get_user_permissions(hubspot_response, user_id)
print(perms)
And you’ll have something like that:
# {'hcrn:123456:crm-object:0-1:64151': ['crm-object:COMMUNICATE',
# 'crm-object:EDIT',
# 'crm-object:VIEW',
# 'crm-object:DELETE']}