Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Set group owner using REST API

$
0
0

I'm trying to use the REST API to set the owner of a SharePoint group. I can successfully create the group using REST, but I can't change the owner. I've tried the following.

1 - Specifying a group owner while creating the group

Endpoint: .../_api/web/sitegroups
Method: POST
Headers:
Content-Type: application/json; odata=verbose
Body:
{ '__metadata': { 'type': 'SP.Group' }, 'Title': '<title>', 'Description': '<description>', 'Owner': { '__metadata': { 'type': 'SP.Principal' }, 'Title': '<owner_title>'}}

This returns a 500 error: "The specified name is already in use. Please try again with a new name". In other words, the owner title I specified already exists, which is correct - I'm trying to make an existing principal the owner of the new group.

2 - Merging a new group owner into an existing group

Endpoint: .../_api/web/sitegroups(<group_id>)
Method: POST
Headers:
Content-Type: application/json; odata=verbose
X-HTTP-Method: MERGE
Body:
{ '__metadata': { 'type': 'SP.Group' }, 'Owner': { '__metadata': { 'type': 'SP.Principal' }, 'Title': '<owner_title>'}}

This returns a 500 error with a Microsoft.SharePoint.SPException: "Exception from HRESULT: 0x80131904". The trace logs don't shed any light on it.

3 - Using the owner endpoint directly

Endpoint: .../_api/web/sitegroups(<group_id>)/owner
Method: POST
Headers:
Content-Type: application/json; odata=verbose
X-HTTP-Method: PUT
Body:
{ '__metadata': { 'type': 'SP.Principal' }, 'Title': '<owner_title>'}
This throws various 400 errors. If the current owner of the group is a user, I get the error "The required property 'Email' does not exist in the message" - i.e. it wants SP.User properties. If the current owner of the group is another group, I get the error "The required property 'AllowMembersEditMembership' does not exist in the message." - i.e. it wants SP.Group properties.

I've tried various adaptations of the three approaches above, such as specifying additional SP.Principal properties or passing SP.User or SP.Group objects instead, but with no success. Any ideas?


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>