2 Replies Latest reply on Oct 7, 2016 5:33 AM by Patrick Abernathy

    Add User to Site

    Mamady Sylla

      Hello,

       

      I have been working with the REST API for some time now.

       

      Whenever I try to call the service to add a user to a site I get a response of Error 500 Internal Server Error.

       

      Has anyone found a solution to this or has this been reported before?

       

      Kind regards,

       

      Mamady

        • 1. Re: Add User to Site

          Hey Mamady,

           

          If you're still hoping to get help with this question I have some questions:

           

          1. Are you able to successfully complete other commands?

          2. Could you show us the command you're using?

          • 2. Re: Add User to Site
            Patrick Abernathy

            Good morning.  I'm not sure if you have a solution or not with this, but I have this call implemented in a C# project I created so I'll plug in the code I use.  This code follows the API call to add the group and the user. My code fills in {siteId} after the API logs in.

             

            Hope this helps.

             

            public void AddUsersToGroupByName(string siteId, List<string> users)
            {
                foreach (var user in users)
                {
                    var tableauApi = new TableauApi();
                    var groupId = tableauApi.GetGroups().FirstOrDefault(g => g.Name == siteId).GroupId;
                    var userId = tableauApi.GetUsers().FirstOrDefault(g => g.Name == user).UserId;
            
                    tableauApi.AddUserToGroup(groupId, userId);
                }
            }
            
            

             

            public void AddUserToGroup(Guid groupId, Guid userId)
            {
                var endPoint = "sites/{siteId}/groups/" + groupId +"/users";
                var body =
                    "<tsRequest> " +
                    "   <user id=\"" + userId + "\" />" +
                    "</tsRequest> ";
                var client = new TableauRestClient(endPoint, HttpVerb.POST, body);
                client.MakeRequest();
            }