[Python] Updating user enterprise not working, permission error

We have a number of users outside of our domain that were inappropriately added as managed users. I want to roll them off the enterprise and convert them to external users, but when using box-sdk-gen and emit a client.users.update_user_by_id(xxxx, enterprise=None) nothing happens. It seems to execute successfully, but fetching that user again shows that the enterprise information is still present.

If I try to execute with enterprise={'id':None} or enterprise='null' I get a 403 insufficient permissions error. I noticed that the type on the enterprise field is str so that’s why I tried the latter.

{       'code': 'access_denied_insufficient_permissions',
        'help_url': 'http://developers.box.com/docs/#errors',
        'message': 'Access denied - insufficient permission',
        'request_id': 'xxxxx',
        'status': 403,
        'type': 'error'}
	Raw body: {"type":"error","status":403,"code":"access_denied_insufficient_permissions","help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Access denied - insufficient permission","request_id":"xxxxx"}

What am I doing wrong? Can anyone point me to how I roll these users off the enterprise?

Thanks

I believe I solved this, it’s a bug in the library. When serializing the request body, it filters out values that are None, and values like “null” are not acceptable for this. I believe I was getting 403 because the server checking for my ability to change the enterprise to “null” was not found, and it assumed I was trying to change a user to an enterprise I wasn’t authorized to change to.

I modified the source code of the library, changing the method update_user_by_id within the file .venv\Lib\site-packages\box_sdk_gen\managers\users.py to include this at line 618:

        json_body: SerializedData = serialize(request_body)
        if json_body['enterprise'] == 'null':
            json_body['enterprise'] = None

This lets me set the value to the string ‘null’ and it gets properly handled by the server. Will be submitting a PR to the repo.

Hi @djones4

Welcome to the forum and thank you for your contribution.

I did a quick, non-exhaustive, check on other endpoints and there are many fields across multiple endpoints which the api accepts null but would fall victim to the same bug. I am moving to the github issue for further discussion on this, hopefully engaging with the maintainers to find a solution.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.