APIs & Integrations

HWimalasiri
Participant

Retrieve specific user's contacts permissions

SOLVE

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?

0 Upvotes
1 Accepted solution
sylvain_tirreau
Solution
Top Contributor

Retrieve specific user's contacts permissions

SOLVE

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']}

 

View solution in original post

4 Replies 4
sylvain_tirreau
Top Contributor

Retrieve specific user's contacts permissions

SOLVE

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

HWimalasiri
Participant

Retrieve specific user's contacts permissions

SOLVE

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.

HWimalasiri_0-1748331581687.png

 

0 Upvotes
sylvain_tirreau
Solution
Top Contributor

Retrieve specific user's contacts permissions

SOLVE

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']}

 

BérangèreL
Community Manager
Community Manager

Retrieve specific user's contacts permissions

SOLVE

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


HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates.
Learn More.


Saviez vous que la Communauté est disponible en français?
Rejoignez les discussions francophones en changeant votre langue dans les paramètres! !