server-client-python icon indicating copy to clipboard operation
server-client-python copied to clipboard

[docs/defensive code] 400003: Bad Request if you skip the authSetting attribute when creating a user

Open dev-mkc19 opened this issue 2 years ago • 5 comments

Describe the bug I try to add user to a site and receive error from API responsen, but fact user being added to the server. Unfortunately discussion from issue #990 does't help to resole the problem. More then that I sent request to server directly without using TSC library and got the same error response.

Versions Details of your environment, including:

  • Tableau Server version 2022.1.7 (20221.22.0916.0328) 64-bit Linux
  • Python version 3.8
  • TSC library version 0.23

To Reproduce Here's my code:

import tableauserverclient as TSC
import logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                    filename="tsc.log", level="DEBUG")

tableau_auth = TSC.PersonalAccessTokenAuth('debug', '<TOKEN>')
server = TSC.Server('https://tableau.<DOMAIN>.com', use_server_version=True)
server.auth.sign_in(tableau_auth)

newU = TSC.UserItem('test@<DOMAIN>.com', 'Viewer')

# add the new user to the site
newU = server.users.add(newU)

server.auth.sign_out()

Results

File ~/Documents/tsc_roject/env8/lib/python3.8/site-packages/tableauserverclient/server/endpoint/endpoint.py:147, in Endpoint.post_request(self, url, xml_request, content_type, parameters)
    146 def post_request(self, url, xml_request, content_type=XML_CONTENT_TYPE, parameters=None):
--> 147     return self._make_request(
...

ServerResponseError: 

	400003: Bad Request
		Payload is either malformed or incomplete

Direct request:

curl "https://tableau.<DOMAIN>.com/api/3.15/sites/abea43f7-3d3a-4c4a-adcf-2007aa48c888/users/" -X POST -H "X-Tableau-Auth:<TOKEN>" -d @add-user-to-site.xml

add-user-to-site.xml:

<tsRequest>
  <user name="test@<DOMAIN>.com"
    siteRole="Viewer" />
</tsRequest>

Response:

<?xml version='1.0' encoding='UTF-8'?><tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api https://help.tableau.com/samples/en-us/rest_api/ts-api_3_15.xsd"><error code="400003"><summary>Bad Request</summary><detail>Payload is either malformed or incomplete</detail></error></tsResponse>

dev-mkc19 avatar Oct 28 '22 15:10 dev-mkc19

Found the clue! In my case attribute auth_setting is required. So the code should looks like

newU = TSC.UserItem('test@<DOMAIN>.com', 'Viewer', auth_setting='ServerDefault')

bcantoni I suppose misunderstanding from my side was because of documentation marks auth-setting attribute as an optional and TSC library doesn't raise the error also.

dev-mkc19 avatar Oct 28 '22 15:10 dev-mkc19

Thanks for the detailed report. I'll double-check that and update the documentation to be more clear.

bcantoni avatar Oct 28 '22 15:10 bcantoni

@bcantoni Adding serverDefault to the request header does not work, we received the same error i.e.

400003: Bad Request
	Payload is either malformed or incomplete

while adding the user.

Below is the request -

<tsRequest><user name="[email protected]" displayName="User 1" siteRole="Viewer" authSetting="ServerDefault"/></tsRequest>

Do we need to add any more details in request ?

Note - we are logged in as Server Admin while creating user.

mohitbhandari37 avatar Mar 20 '23 07:03 mohitbhandari37

What kind of user management/auth does the server have? Local users, or Active Directory, or something else?

jacalata avatar Mar 25 '23 07:03 jacalata

I had the same issue, had to pass TableauIDWithMFA in auth_setting . Not sure if this helps anyone, but it seems to be required for Tableau Cloud instance.

keidikapllani avatar May 18 '23 16:05 keidikapllani