1 Reply Latest reply on Jul 6, 2016 8:48 AM by jack@guidestar

    Adding members to Security Groups

    jack@guidestar

      I am trying to add members to a SecurityGroup. I've looked at all the questions and answers in the Developer Community that I could find. None give a very explicit example of how to format the data part of the POST.

      I can get 400 (Bad Request) and 500 (Internal Server Error) but never 200.

      Here's my code, C# .NET 4.0:

       

      private static string addUserToGroup(string groupID, string memberID, string user, string passwd)

      {

           string response = string.Empty;

           try

           {

             using (var client = new WebClient())

             {

                  string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(user + ":" + passwd));

                  client.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;

                  client.Headers[HttpRequestHeader.Accept] = "application/json";

                  client.Headers[HttpRequestHeader.ContentType] = "application/json";

                  client.Encoding = System.Text.Encoding.UTF8;

       

                  string uri = ConfigurationManager.AppSettings["uri_prefix"] + "securityGroups/1028/members";          //evaluates to "https://<our URI>/api/core/v3/securityGroups/1028/members"

       

                  string value = @"[" + ConfigurationManager.AppSettings["uri_prefix"] + "people/2235]";                // evaluates to [https://<our URI>/api/core/v3/people/2235]

       

                 // string value = @"[""/people/2235"",""/people/2037""]"; // evaluates to this: ["/people/2235","/people/2037"] -- tried this too

       

                  response = client.UploadString(uri,"POST", value);

             }

           }

           catch(Exception ex)

           {

             Console.WriteLine("Exception: {0}", ex.Message);

           }

      return response;

      }

       

      I'd appreciate any replies that can help.