Web Services Python Example: Add a New User

A common administrative task is to create a new user. This example uses methods such as addUser and addProductToUser. For each step, the login token and other parameters are passed.

For your purposes, you may want to extend this code with other methods that can add a user to a space, assign custom subject areas, give access to reports in the report catalog, etc.

Prerequisites

  • The user account that logs into the web service must be an Account Administrator because an Account Administrator has the privileges to create new users.
  • The Account Administrator must have the Web Services product.

Overview

The client sends the SOAP request to the external web service end point.

https://server_URL/CommandWebservice.asmx?wsdl

 

Example Python Code

from suds.client import Client
# url: URL end point, adminUser: Admin user that has all requirements,  password: Admin user password.
url = 'https://mrc.bws.birst.com/CommandWebservice.asmx?wsdl'
adminUser='adminUserName'
adminPassword='adminUserPassword'
# creating client.
client = Client(url)
# get the login token.
login_token = client.service.Login(adminUser,adminPassword)
# raise exception if token is not available.
if login_token is None:
raise Exception
# userNameToCreate: new username to be created. userPassword: new user password. userEmail: new user email. 
# OptionalArguments: string value for password and email. 
userNameToCreate = "someUser"
userPassword = "somePassword"
userEmail = "some@email.com"
optionalArguments = "password=" + userPassword + " email=" + userEmail
# web service to create user.
result = client.service.addUser(login_token, userNameToCreate, optionalArguments)
# check if call is successful.
if result is not None:
raise Exception
# adding webservice Product to user (dummy value).
webServiceProduct = 11011011
result = client.service.addProductToUser(login_token, userNameToCreate, webServiceProduct)
if result is not None:
raise Exception
#should successfully print the login token.
print(client.service.Login(userNameToCreate,userPassword))