1

My API call to my SharePoint site returns a 400 Bad Request when querying certain Microsoft 365 groups with the ensureUser API call.

We have a requirement to use Microsoft 365 groups, so I'm trying to figure out why some work and others do not. Please take a look at my examples, and let me know if you can help.

I have created a Microsoft 365 Group:

enter image description here

but calling the ensureUser API call returns a 400 Bad Request:

https://mysite.sharepoint.com/sites/DemoTeamSite/_api/web/ensureUser?logonName='Marketing Dept'

enter image description here

I believe I have an identical Microsoft 365 Group:

enter image description here

which returns a 200 OK status:

enter image description here

As a sanity check, I created a new Security group:

enter image description here

and confirmed that I can query it:

enter image description here

FYI, none of these groups exist in SharePoint.

2 Answers 2

0

BTG Social is ID=27 in the user information list on that site. So yes, BTG Social is, or was once, in that SharePoint site. If you add those other groups to the site, they'll come back as well.

2
  • Isn't the purpose of ensureUser to make sure that the user is added to the site? From the documentation: "Checks whether the specified login name belongs to a valid user in the site. If the user doesn't exist, adds the user to the site." Oct 28, 2021 at 18:43
  • ah, yeah, you're right. Oct 28, 2021 at 20:51
0

You should confirm your user 'Marketing Dept' still enabled in AD. This error can be occurred as if the user is not enabled in AD, though it will still show as an SP User.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.