/// <summary> /// <see cref="ITableauUserService.AddUserToSiteAsync"/> /// </summary> public async Task <TableauUser> AddUserToSiteAsync(string name, string siteRole) { _logger?.Debug($"Adding user {name} with role {siteRole}"); var url = _tableauApiService.SiteUrl.AppendUri($"users"); var user = new TableauUser() { Name = name, SiteRole = siteRole }; var requestJson = new JObject(); requestJson["user"] = JToken.Parse(user.ToRequestString()); var responseString = await _tableauApiService.SendPostAsync(url, requestJson.ToString()).ConfigureAwait(false); var responseJson = JToken.Parse(responseString); user = JsonConvert.DeserializeObject <TableauUser>( responseJson.Value <JObject>("user").ToString() ); _logger?.Debug($"User {user.Id} added as {siteRole}"); return(user); }
/// <summary> /// <see cref="ITableauGroupService.AddUserToGroupAsync"/> /// </summary> public async Task <TableauUser> AddUserToGroupAsync(string groupId, string userId) { _logger?.Debug($"Adding user {userId} to group {groupId}"); var url = _tableauApiService.SiteUrl.AppendUri($"groups/{groupId}/users"); var user = new TableauUser() { Id = userId }; var userJson = new JObject(); userJson["id"] = userId; var requestJson = new JObject(); requestJson["user"] = userJson; var responseString = await _tableauApiService.SendPostAsync( url, requestJson.ToString() ).ConfigureAwait(false); var responseJson = JToken.Parse(responseString); user = JsonConvert.DeserializeObject <TableauUser>( responseJson.Value <JObject>("user").ToString() ); _logger?.Debug($"User {userId} added to group {groupId}"); return(user); }