1

I am trying to add AD group to SharePoint site in REST using EnsureUser but I kept getting error message "The specified user c:0+.w|S-1-5-21-1814438218-152777602-930774774-762833 could not be found". Can someone please tell me what the correct format is for the logonName string? AD is on prem and we are using SP Online. Below is the code:

 string digest = formDigest == "" ? GetRequestDigest() : formDigest; string logonNameStr = WebUtility.HtmlEncode("c:0+.w|") + "S-1-5-21-1814438218-152777602-930774774-762833"; <== This seems to be incorrect string ensureUserUrl = _siteUrl + "_api/web/EnsureUser"; using (var handler = GetHttpClientHandler(_siteUrl)) { using (HttpClient client = GetHttpClient(handler)) { client.DefaultRequestHeaders.Add("X-RequestDigest", digest); var payload = new { logonName = logonNameStr }; string jsonBody = JsonSerializer.Serialize(payload); using (StringContent content = new StringContent(jsonBody)) { content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json;odata=verbose;charset=utf-8"); HttpResponseMessage response = client.PostAsync(ensureUserUrl, content).Result; string jsonStr = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) //if adding user failed { throw new Exception(String.Format("Failed to add AD group {0} to SharePoint site: {1}", groupName, jsonStr)); } } } } 

1 Answer 1

1

Got the answer from the MS Engineer. The LogonNameStr just have to be the name of the AD Group, no domain, no SID. And that works successfully.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.