0

I'm using Sharepoint 2019 and looking to update the owner of a group utilizing the REST API. There have been plenty of examples for the "usual" asks - authentication, create site, add users, rename, etc. But changing a group owner has been elusive.

I've tried using HttpClient with many variations of the following:

try
{
    var requestBody = new
    {
        __metadata = new { type = "SP.Group" },
        Owner = new { Id = sharePointUserId.ToString() }
    };

    opts = new Options()
    {
        SiteUrl = _restService.Options.SiteUrl,
        Endpoint = $"{_ENDPOINT_SITEGROUPS}/getById({groupId})/owner",
        Body = JsonConvert.SerializeObject(requestBody)
    };

    var response = await _restService.Post(opts);
    responseString = await response.Message.Content.ReadAsStringAsync();
}

...

If I use PATCH I receive a JSON response as follows:

"{\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.UnknownError\",\"message\": 
{\"lang\":\"en-US\",\"value\":\"Unknown Error\"}}}"

If I use POST I receive:

"{\"error\":{\"code\":\"-1, 
Microsoft.SharePoint.Client.InvalidClientQueryException\",\"message\":{\"lang\":\"en- 
US\",\"value\":\"Invalid request.\"}}}"

Does anyone have a working example (in any language)? I guess I really need to know:

  • Which verb is correct? (and headers)
  • What is the proper structure of the the request?
  • Is the URL correct? (I can extrapolate on the particulars, but I think you'll get the idea)
Jesse Q
  • 1,451
  • 2
  • 13
  • 18

0 Answers0