Skip to main content
Solved

[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

Best answer by djones4

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.


View original
Did this topic help you find an answer to your question?

4 replies

  • Author
  • New Participant
  • 2 replies
  • June 24, 2024

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.


rbarbosa Box
  • Developer Advocate
  • 553 replies
  • June 24, 2024

Hi @djones4


Welcome to the forum and thank you for your contribution.


  • Author
  • New Participant
  • 2 replies
  • Answer
  • June 25, 2024

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.



system
  • Community Manager
  • 22 replies
  • June 29, 2024

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings