Deleting a SharePoint Team Site using Power Automate - sharepoint-online

I have a Power Automate workflow that is doing a lot of different things, and at the end, it tries to delete a Team Site (site collection) in my SharePoint Online tenant. I am using an HTTP action to do this, and it looks like this:
Site Address: https://xxx.sharepoint.com/sites/yyy
Method: POST
Uri: _api/web
Headers:
"accept": "application/json;odata=verbose"
"content-type": "application/json;odata=verbose"
"X-HTTP-Method": "DELETE"
The error is
{
"error": {
"code": 502,
"source": "flow-apim-msmanaged-na-westus-01.azure-apim.net",
"clientRequestId": "1ed0536f-78f3-45cc-a636-a10af5d670f0",
"message": "BadGateway",
"innerError": {
"status": 502,
"message": "Cannot delete top-level site: https://xxx.sharepoint.com/sites/yyy.\r\nclientRequestId: 1ed0536f-78f3-45cc-a636-a10af5d670f0\r\nserviceRequestId: 668965a0-c019-2000-72ee-7660a568e911",
"source": "https://xxx.sharepoint.com/sites/yyy/_api/web",
"errors": [
"-2146232832",
"Microsoft.SharePoint.SPException"
]
}
}
}
Is this possible from Power Automate, and if so, what should I be doing differently?

If it is a modern site (Communication sites and Non-group associated Team Sites) you should be able to use the _api/SPSiteManager endpoint in a Send an HTTP request to SharePoint action.
Delete a modern site
url: /_api/SPSiteManager/delete
method: POST
accept: application/json;odata.metadata=none
odata-version: 4.0
body:
{
"siteId":"d11e59ca-1465-424c-be90-c847ba849af5"
}
When it is a group connected site I would use the Delete Group method from the Graph API in a Send an HTTP request action of the Office 365 Groups connector.
DELETE https://graph.microsoft.com/v1.0/groups/{id}

Related

Error using SharePoint REST API endpoint for creating a Modern Teams site: The parameter request does not exist in method CreateGroupEx

The bounty expires in 5 days. Answers to this question are eligible for a +50 reputation bounty.
arresteddevelopment wants to draw more attention to this question.
I am trying to use the SharePoint REST API endpoint _api/GroupSiteManager/CreateGroupEx to create a SharePoint Modern Teams site
url: /_api/GroupSiteManager/CreateGroupEx
accept: application/json;odata.metadata=none
odata-version: 4.0
method: POST
body:
{
"request": {
"Title": "Communication Site 1",
"Url":"https://contoso.sharepoint.com/sites/commsite1",
"Lcid": 1033,
"ShareByEmailEnabled":false,
"Classification":"Low Business Impact",
"Description":"MyDescription",
"WebTemplate":"STS#3",
"SiteDesignId":"6142d2a0-63a5-4ba0-aede-d9fefca2c767",
"Owner":"owner#yourtenant.onmicrosoft.com"
}
}
I have proven my API process by creating a Modern Communication site with the endpoint /_api/SPSiteManager/create and "WebTemplate":"SITEPAGEPUBLISHING#0"
When I attempt to create the Modern Teams site I get the error:
Failed: {"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The parameter request does not exist in method CreateGroupEx."}}}
Try to update the request body like below:
body:{
"request": {
alias: "Communication Site 1",
displayName: "Communication Site 1",
isPublic: true,
optionalParams: {
Classification: "Low Business Impact",
CreationOptions: [`SPSiteLanguage:1033`,`implicit_formula_292aa8a00786498a87a5ca52d9f4214a_6142d2a0-63a5-4ba0-aede-d9fefca2c767`],
Description: "MyDescription",
Owners: "owner#yourtenant.onmicrosoft.com"
}
}
}
Also I have noticed that changing the Accept to below helps:
'Accept': 'application/json;odata.metadata=minimal'
It clearly complains about the "request" parameter, telling that there is no such parameter. Worked for me:
url: /_api/GroupSiteManager/CreateGroupEx
accept: application/json
method: POST
body: {
"alias": "CommunicationSite1",
"displayName": "Communication Site 1",
"isPublic": true,
"optionalParams": {
"CreationOptions": [
"SPSiteLanguage:1033",
"implicit_formula_292aa8a00786498a87a5ca52d9f4214a_6142d2a0-63a5-4ba0-aede-d9fefca2c767"
],
"Description": "MyDescription",
"Owners": ["owner#yourtenant.onmicrosoft.com"]
}
}
Some notes:
alias should not contain spaces (it is a part of url and email nickname)
I have no idea what the classification could be, just omited (your string does not seem work)
owners should be an array, not a string

How can I pass Body Parameters to API Post operation using API Management Action in Logic App?

I have an azure function which works well when I call it from postman . I am trying to invoke the same from logic app as when an HTTP request is received. However, I am unable to pass raw content in the APIM as it does not give me an option for the same. It let me add only the subscription key.
My Azure APIM accepts file name, subscription key only.
Any help in this regard is much appreciated.
Postman : (I have added Headers - Content-Type, Accept: using )
Headers:
Content-Type :
Accept:
Ocp-Apim-Subscription-Key
Body:
{
"name": "olaf"
}
Azure Logic App: (Using Peek Code);
{
"inputs": {
"method": "post",
"headers": {
"Accept": "application/json",
"Content-Type": "text/csv"
},
"pathTemplate": {
"template": "/scg-liquidTransformer-functionApp/liquidtransformer/{liquidtransformfilename}",
"parameters": {
"liquidtransformfilename": "#{encodeURIComponent('xmlsample.liquid')}"
}
},
"api": {
"id": "/subscriptions/XXXXXXXXXXXXXXXXXXXXX/resourceGroups/scg-mel-dev-arg-liquidtransformer/providers/Microsoft.ApiManagement/service/scg-liquidTransformer-functionApp-apimservice/apis/scg-liquidtransformer-functionapp"
},
"subscriptionKey": "XXXXXXXXXXXXXXXXXXXXXXXX"
}
}
I need to send body {} as a parameter input in the azure functionenter image description here.
Thanks,
Paul.
enter image description here
You need to do configuration in your APIM, please refer to the steps below:
1. Go to your APIM, find your api and click the "pencil" icon.
2. In next page, click "Request" tab and click "Add representation" to add "application/json".
3. Then click "New definition"
4. Input the json sample of request body, it will generate the schema automatically in "Payload" box.
5. Click "Save", then go back to your logic app and add the APIM api. You can find there is a field "name" for you to choose.

Adding User to Group using Graph API B2C

I am using Azure AD B2C to create users.
After a user is created I would like to add them to a Group
Using Postman I have made the following request (with access token in the header). Note: I have managed to successfully create a group using the Api.
POST
https://graph.windows.net/{azure-tenant}/groups/{group-objectId/members/$ref?api-version=1.6
With Body:
{
"#odata.id": "https://graph.windows.net/{azure-tenant}/directoryObjects/{user-objectId}"
}
Which is what the documentation specifies. No matter the body that is sent I get the following error
{
"odata.error": {
"code": "Request_BadRequest",
"message": {
"lang": "en",
"value": "The request URI is not valid. Since the segment 'members' refers to a collection, this must be the last segment in the request URI. All intermediate segments must refer to a single resource."
},
"requestId": "48cf65f3-20ba-411e-8121-f7ea54252f3a",
"date": "2019-05-27T06:09:25"
}
}
I tried removing the /$ref
POST
https://graph.windows.net/{azure-tenant}/groups/{group-objectId/members?api-version=1.6
Body:
{
"#odata.id": "https://graph.windows.net/{azure-tenant}/directoryObjects/{user-objectId}"
}
as well as
{
"#odata.id": "https://graph.windows.net/{azure-tenant}/users/{user-objectId}"
}
Now the error that gets returned now is:
{
"odata.error": {
"code": "Request_BadRequest",
"message": {
"lang": "en",
"value": "Unsupported resource type 'DirectoryObject' for operation 'Create'."
},
"requestId": "2c36cc6d-383c-44f8-8609-2ac3e3efc862",
"date": "2019-05-27T06:15:26"
}
}
The documentation that I have been using https://learn.microsoft.com/en-us/graph/api/group-post-members?view=graph-rest-1.0&tabs=javascript
You are using graph.windows.net endpoint, so you should refer to azure ad graph api.
POST https://graph.windows.net/myorganization/groups/b4bda672-1fba-4711-8fb1-5383c40b2c14/$links/members?api-version=1.6
{
"url": "https://graph.windows.net/myorganization/directoryObjects/3eb6055a-baeb-44d4-a1ea-2fee86d8891b"
}
The document you referred to is microsoft graph api. The endpoint should be https://graph.microsoft.com.
You can use Microsoft Graph explorer to call these apis.

Get all root sites listed in share point Admin center using graph api beta

I need all root sites listed in share point Admin center shown in image
For that i am using Graph api like follows,
var settings = {
"async": true,
"crossDomain": true,
"url": "https://graph.microsoft.com/beta/sharepoint/sites",
"method": "GET",
"headers": {
"authorization": "Bearer token",
"cache-control": "no-cache",
"postman-token": "3116b007-e574-5ad4-aedd-3b35fbf76b61"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
But it gives output as follows,
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#sharePoint/sites",
"value": [
{
"createdDateTime": "2017-02-18T13:03:01.263Z",
"description": "",
"id": "2422c3a2-3c51-40f1-8483-5454aead43c4,412bb897-c754-460a-962d-db22893a1649",
"lastModifiedDateTime": "2017-04-24T02:16:43Z",
"name": "",
"webUrl": "https://mps330124.sharepoint.com",
"root": {},
"siteCollection": {
"hostname": "mps330124.sharepoint.com"
},
"siteCollectionId": "2422c3a2-3c51-40f1-8483-5454aead43c4",
"siteId": "412bb897-c754-460a-962d-db22893a1649"
}
]
}
How can i achieve it Using graph api beta
Using the asterisk on the site search endpoint seems to work
https://graph.microsoft.com/v1.0/sites?search=*
returns
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites",
"value": [
{
"createdDateTime": "2017-09-15T01:11:50Z",
"description": "Let's capture our thoughts in this subsite blog.",
"id": "xyz.sharepoint.com,5a58bb09-1fba-41c1-8125-69da264370a0,5e9767b8-95bc-4bd1-aeb0-defabcdefabc",
"lastModifiedDateTime": "0001-01-01T08:00:00Z",
"name": "internalblogs",
"webUrl": "https://xyz.sharepoint.com/internalblogs",
"displayName": "Internal blog"
},
{
...
}]
}
There isn't a way to retrieve a full list of site collections via Microsoft Graph. That functionality is "admin only" in the SharePoint API and has not been made available via Microsoft Graph.
We're working on some changes to the SharePoint Sites API for Microsoft Graph that will be rolled out over the next few weeks to make it possible to search for a list of sites / site collections, but we still don't have plans to make available the ability to enumerate all sites / site collections via Microsoft Graph.
Watch the Change Log around the Build 2017 conference (May 10-12) to find our all the details.
There now seems to be a way to get a list of the top level site collections via the following request:
GET https://graph.microsoft.com/beta/sites?select=siteCollection,webUrl&filter=siteCollection/root%20ne%20null
The following page documents this (update September 19th): https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/site_list
My own test though didn't bear any fruit, because the API returns a Cannot enumerate sites error. An alternative approach would be to use the search query parameter (docs updated September 20th):
GET https://graph.microsoft.com/beta/sites?search=contoso&select=siteCollection,WebUrl&filter=siteCollection/root ne null
But this only provides the siteCollection for the root :/ with a list of all sites and their webUrl of the other siteCollection's (like the default ones /sites & /teams) but not the actual url/hostname of the siteCollection they belong to. Though that could be extracted from the webUrl path component.
What you are getting is not an error.
If you follow the siteCollectionId with the URL https://graph.microsoft.com/beta/sharepoint/sites/2422c3a2-3c51-40f1-8483-5454aead43c4/sites you get a list of the sites in that site collection.

creating subscription with Microsoft Graph API error

I'm trying to create a subscription to receive notification about changes to Office365 Calendar. I have already worked with Outlook Notitication API but having a problem with Microsoft Grap API
I try to create a subscription using Http Post to https://graph.microsoft.com/beta/subscriptions with header and body:
Header: Content-Type: application/json; Authorization : Bearer {accessToke}
Body:
{
"resource": "me/calendars",
"notificationUrl": "sample notification url",
"changeType": "Created",
}
In my notification url, i've setup to send a response with the value of validation token when receveving a validation request
Finally, the result i received:
{
"error": {
"code": "ExtensionError",
"message": "There was an error processing a storage extension.",
"innerError": {
"request-id": "6c563931-511d-415d-9c04-c07f25d45b1f",
"date": "2016-03-20T08:10:32"
}
}
}
I wonder what I'm doing wrong or that's a internal error of MS Grap API. Can anyone help me? Thank in advance
The correct resource to use for calendar events is "me/events". We'll try to get a better error message in future.

Resources