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

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

Related

Deleting a SharePoint Team Site using Power Automate

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}

How to Update properties of a OneDrive item using REST API?

I am trying to update the properties of a OneDrive item using SharePoint REST API.
OneDrive item web URL:
https://vx13-my.sharepoint.com/personal/alexw_vx13_onmicrosoft_com/Documents/SrcDir/File-To-Update.txt
Mainly looking to updating following fields: Author, Created_x0020_By, Editor, Modified_x0020_By, Modified, Created
I tried using Graph API:
Request:
Method: PATCH |
URL: https://graph.microsoft.com/v1.0/sites/vx13-my.sharepoint.com,eab581b1-a945-4d23-9c8e-ec67bb74a42d,32fa1468-54b6-40d6-abbd-f775c4c3932b/drives/b!sYG16kWpI02cjuxnu3SkLWgU-jK2VNZAq733dcTDkyvIAAMdpSy_Sryiw8ARQ8Gv/root:/SrcDir/File-To-Update.txt:/listItem/fields |
Header:
Content-Type: application/json |
Accept: application/json;odata=verbose |
Body:
{
"Created": "2019-02-01 10:25 AM",
"Modified": "2020-01-27 11:25 AM",
"Modified_x0020_By": "3",
"Created_x0020_By": "3",
"Author": "Alex Wilber",
"Editor": "Alex Wilber"
}
It is giving failure response as:
{"code": "accessDenied", "message": "Field 'Created' is read-only"}
Through CSOM API using ValidateUpdateListItem() its working & successfully updating the property fields of OneDrive items.
But is there any way to update property fields of OneDrive item through REST API?
By default, these properties are Readonly by and cannot be edited.
You need to set the ReadOnlyField to false to update these fields. I used to answer the same question here: https://learn.microsoft.com/en-us/answers/questions/221106/rest-api-to-create-item-with-custom-created-by-and.html
For Created By column:
Url: /_api/web/lists/getbytitle('Mylist')/fields/getbytitle('Created By')
Body:
{
"__metadata": { "type": "SP.FieldUser"},
"ReadOnlyField": false
}
For Created column:
Url: /_api/web/lists/getbytitle('Mylist')/fields/getbytitle('Created')
Body:
{
"__metadata": { "type": "SP.FieldDateTime"},
"ReadOnlyField": false
}
Using SharePoint REST API,
a work around to update the Properties of OneDrive item using method ValidateUpdateListItem()
Get the list-item-id of the file
GET https://vx13-my.sharepoint.com/personal/alexw_vx13_onmicrosoft_com/_api/web/GetFileByServerRelativePath(decodedurl='/personal/alexw_vx13_onmicrosoft_com/Documents/SrcDir/File-To-Update.txt')/listitemallfields/fieldvaluesastext?$select=Id
Update Author, Editor, Created & Modified fields of list item using ValidateUpdateListItem
POST https://vx13-my.sharepoint.com/personal/alexw_vx13_onmicrosoft_com/_api/web/Lists/GetByTitle('Documents')/items(<list-item-id>)/ValidateUpdateListItem()
Content-Type:application/json
Accept:application/json;odata=verbose
Body:
{
"formValues":
[
{
"FieldName": "Created",
"FieldValue": "2019/02/01 10:25 AM"
},
{
"FieldName": "Modified",
"FieldValue": "2020/01/27 11:25 AM"
},
{
"FieldName": "Author",
"FieldValue": "[{'Key':'i:0#.f|membership|test_user_AK#vx13.onmicrosoft.com'}]"
},
{
"FieldName": "Editor",
"FieldValue": "[{'Key':'i:0#.f|membership|test_user_JV#vx13.onmicrosoft.com'}]"
}
],
"bNewDocumentUpdate": true
}
If you refer to the documentation here under the Properties section, you will notice certain fields are read only and you wont be able to update them using Graph API.
For all other properties(e.g. name), follow this documentation to update.
Being said that, you can always request for a feature by filling a User Voice so that it goes into our backlog.

node.js swagger x-ms-dynamic-value

I'm using swagger with node.js. I want to use x-ms-dynamic-values to return values to my parameter dynamically.
Basically the first parameter will have a URL then the node.js endpoint will make a get request to that URL and pull back lets say questions, Each URL can have a different amount of questions and the questions can also vary. The get request can get a json response with amount of questions on the page. In my next parameter I want to be able to select a question based on that response.
This is where the x-ms-dynamic-values will come in to play, But I'm nearly 100% sure there are no examples of this being used with node.js only thing I could find was c# example which i will link under this.
So basically my questions is, can anyone provide my with a little example of the node.js I may be able to work from ?
example of the swagger code :
"paths":{
"/api/contacts/{name}":{
"get":{
"tags":[
"DynamicSchemas"
],
"summary":"Get Contact Info",
"description":"Gets contact info of the specified type",
"operationId":"GetContactInfo",
"consumes":[
],
"produces":[
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters":[
{
"name":"name",
"in":"path",
"required":true,
"type":"string",
"x-ms-summary":"Contact Name"
},
{
"name":"contactType",
"in":"query",
"description":"Try either \"Phone\" or \"Email\"",
"required":true,
"type":"string",
"x-ms-summary":"Contact Type"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/ContactInfo"
}
},
"400":{
"description":"Invalid type specified"
},
"default":{
"description":"OK",
"schema":{
"$ref":"#/definitions/ContactInfo"
}
}
}
Api Example: https://github.com/nihaue/TRex/tree/master/Source

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.

HTTP request / Service bus - application/x-www-form-urlencoded not supported error

I've got a really simple Logic app:
HTTP request (works as end-point web hook for Slack)
Send request from Slack (URI) to Service Bus queue
I haven't made any changes in Logic App but Send message action suddenly started reporting this error:
Decoding as string is not supported for content envelope of type
'application/x-www-form-urlencoded'.
Send message is defined like that:
"Send_message": {
"inputs": {
"body": {
"Label": "#{triggerBody()}"
},
...
I see only difference in request outputs:
BEFORE
Headers
{
"Accept": "*/*",
"User-Agent": "Slackbot,1.0,(+https://api.slack.com/robots)",
"Content-Type": "application/x-www-form-urlencoded"
...
}
Body
{
"$content-type": "application/x-www-form-urlencoded",
"$content": "dG9r..."
}
NOW
Headers
{
"Accept": "*/*",
"User-Agent": "Slackbot,1.0,(+https://api.slack.com/robots)",
"Content-Type": "application/x-www-form-urlencoded"
...
}
Body
{
"$content-type": "application/x-www-form-urlencoded",
"$content": "dG9r...",
"$formdata": [
{
"key": "token",
"value": "..."
},
{
"key": "team_id",
"value": "..."
},
{
"key": "trigger_word",
"value": "!"
},
...
]
}
$formdata is now a part of the output of Request as JSON array consisting of all query parameters.
Does anyone have any ideas? I would greatly appreciate any help to make it work again.
Edit: West Europe fixed and working
Yes, in the effort to have native support for x-www-form-urlencoded data in the runtime there was a bug that was recently released. We are rolling back and patching now. Can you send me an email so we can target your region for a fix, and share a workaround? Apologies in advance - as a general rule we never want to ship anything that will break existing logic apps. In this case adding some new metadata around form-data no longer allowed people to stringify x-www-form-urlencoded data (which is what you are doing here).

Resources