/// <summary> /// Create the user on the server /// </summary> /// <param name="userName"></param> /// <param name="userRole"></param> /// <param name="userAuthentication"></param> /// <returns></returns> private SiteUser CreateUser(string userName, string userRole, SiteUserAuth userAuthentication) { string authSettingText = SiteUserAuthToAttributeText(userAuthentication); //ref: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#add_user_to_site var sb = new StringBuilder(); var xmlWriter = XmlWriter.Create(sb, XmlHelper.XmlSettingsForWebRequests); xmlWriter.WriteStartElement("tsRequest"); xmlWriter.WriteStartElement("user"); xmlWriter.WriteAttributeString("name", userName); xmlWriter.WriteAttributeString("siteRole", userRole); xmlWriter.WriteAttributeString("authSetting", authSettingText); xmlWriter.WriteEndElement(); //</user> xmlWriter.WriteEndElement(); //</tsRequest> xmlWriter.Close(); var xmlText = sb.ToString(); //Get the XML text out //Generate the MIME message //Create a web request var urlCreateUser = _onlineUrls.Url_CreateSiteUser(_onlineSession); var webRequest = this.CreateLoggedInWebRequest(urlCreateUser, "POST"); TableauServerRequestBase.SendPostContents(webRequest, xmlText); //Get the response var response = GetWebReponseLogErrors(webRequest, "create user"); using (response) { var xmlDoc = GetWebResponseAsXml(response); //Get all the workbook nodes var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); var xNodeProject = xmlDoc.SelectSingleNode("//iwsOnline:user", nsManager); try { return(new SiteUser(xNodeProject)); } catch (Exception parseXml) { StatusLog.AddError("Create user, error parsing XML response " + parseXml.Message + "\r\n" + xNodeProject.InnerXml); return(null); } } }