SharePoint 2013 Workflows does not have any actions for creating a SharePoint sites, but you can solve this using the «call http web service» action and SharePoint REST API.
I wanted to give the users a form to order new sites in an easy way without being a site owner. I wanted to solve this using a SharePoint list with an attached workflow as a site order form. I am doing this proof of concept on my lab-site http://intranet.wingtip.com.
- Enable Workflow can use app permissions
- Create a list for ordering sites
- Create a workflow that creates a site when new item is created
- Grant full control permission to workflow (needed for workflow to create site)
Enable Workflow can use app permissions
- Under Settings button
- Select Site settings
- Select Manage site features
- Click Activate on Workflows can use app permissions
Create a list for ordering sites
- From your site – click Site Contents
- Click Add an app
- Click Custom list
- Give the new list a name like «Order project site» and click OK
We do not need any more fields for this proof of concept.
Create the workflow
- Click Order project site in the left menu to open your list
- Click List in the top menu to open list settings
-
Click Workflow Settings in the toolbar, then click Create a Workflow in SharePoint Designer
- Click Allow if you get a security warning
-
Enter a name for your workflow and click OK
- Rename the Stage to «Creating request header»
- Add a Build Dictionary action
-
Name the output variable «RequestHeader»:
- Click this to add variables to the dictionary
- Click Add
-
Add a string variable named content-type with the value application/json;odata=verbose and click OK
-
Add a new string variable named Accept with the value application/json;odata=verbose and click OK
-
Click OK
- Click Stage in the toolbar to create a new step
- Rename the stage to Creating Request Body
- In Stage: Creating request header set Transition to stage to Go to Creating Request Body
- In Stage: Creating Request Body add a new Build Dictionary action
- Set output to a new variable MetaData
-
Add string variable named type with value SP.WebInfoCreationInformation
- Click OK to confirm all open dialog boxes
- Add a new Build dictionary action
- Set output to a new variable named RequestHeader
- Add these variables to RequestHeader:
Name | Type | Value |
Url | String | Currentitem: TitleClick the fx button to add the Title of the current list item: |
Title | String | Currentitem: TitleClick the fx button to add the Title of the current list item: |
Description | String | Currentitem: TitleClick the fx button to add the Title of the current list item: |
Language | Integer | 1033 |
WebTemplate | String | sts#0 |
UseUniquePermissions | String | false |
__metadata | Dictionary | Variable: MetaDataClick the fx button to add the previous created MetaData variable: |
- Click OK in all dialog boxes to save RequestHeader dictionary variable
- Add a new Build dictionary action
- Set output to new variable named RESTparameters
-
Add a variable named parameters type Dictionary
with the value of the previous created RequestHeader - Click OK to close all open dialogs
- Add a new Stage and rename it to Creating Site
- Set Transition to stage in Creating Request Body to go to Creating Site
- In Stage: Creating Site add App Step
- In App step add Call http web service action
- Click this to add the web service URL
-
Enter the URL (use your own site and add /_api/web/webinfos/add to it) and select HTTP Post as HTTP method:
- Click OK when done
- Select the Call HTTP web service action
- Click Advanced Properies in the toolbar
-
Set RequestHeaders to variable RequestHeder and set RequestContent to variable RESTparameters:
- Click OK to close dialog
- In Stage: Creating Site set Transition to stage to go to End of Workflow
- Click Publish
-
Click OK in the next dialog:
-
Click Create site just below the Create site tab:
-
Check Start workflow automatically when an item is created
- Click Publish in the toolbar and confirm if you get any warning.
Grant full control permission to workflow
The following steps must be completed by a user that is a site owner. These actions require that a workflow has been published to the site.
- Click on the Settings button
- Go to Site Settings
- Under Users and Permissions, select Site app permissions
- Copy the client section of the App Identifier. This is the identifier between the last «|» and the «@» sign.
Example:
- Navigate to the Grant permission to an app page. This must be done by browsing to appinv.aspx in the site.
http://{hostname}/{site}/_layouts/15/appinv.aspx
Example:
- Paste the client id in the App Id field and click Lookup
Example:
Example:
You will see complete details of the workflow app id. - Paste the following Permissions Request XML to grant full control permission
1: <AppPermissionRequests>
2: <AppPermissionRequest
3: Scope="http://sharepoint/content/sitecollection"
4: Right="FullControl" />
5: </AppPermissionRequests>
Example:
- Click Create. You will then be asked for consent. Verify that you are asked for consent to give workflow full control of the site. If you do not see full control consent request it probably means that there was an error in the permissions request XML.
Example:
- Click Trust It
Your list should now create a new site each time an item is added.
Thanks for the great guide, Roger!
Thanks so much! In the Permissions Request XML, users should replace the slanted quotation marks with straight ones, as this may throw an error.
Hi Roger I am facing issue while trying to do the exactly same as you have done in your POC.
RequestorId: 1b8a5b1a-b322-5921-0000-000000000000. Details: An unhandled exception occurred during the execution of the workflow instance. Exception details: System.NotSupportedException: CannotReadAsType=Cannot read ‘Microsoft.Activities.Dynamic.DynamicObject’ as ‘System.String’ type. at Microsoft.Activities.Dynamic.DynamicItem.ReadAs(Type type) at Microsoft.Activities.Dynamic.DynamicItem.ReadAs[T]() at Microsoft.Activities.Messaging.SendHttpRequest.AddHeader(String headerName, DynamicItem headerValue, Boolean isContentHeader, HttpRequestMessage requestMessage, IList`1& contentHeaders, Boolean& isEmptyValue) at Microsoft.Activities.Messaging.SendHttpRequest.SendRequest(NativeActivityContext context) at System.Activities.NativeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
Can you please help me out what is wrong I have done.
how did you solved these error plz post i am also getting same error
Hi Ravi
Could you be more specific on what errors you get?
Roger
Hi Roger,
I am able to solve the earlier error that I have posted. But when now I am calling the service to create the site getting the Forbidden access to call the service.
So my site creation is failed. I have given the full control permission to my workflow. Please help me out on this.
Regards,
Sumit
I got wrong quotation marks in «Permission Request» on my posting. I’ve tried to correct this. Also check the comment from Jamie.
Roger
I have tried the example, but giving me «BadRequest» on the response code !
Same for me. The complete Response is: {«error»:{«code»:»-1, Microsoft.Data.OData.ODataException»,»message»:{«lang»:»en-EN»»value»:»An unexpected ‘PrimitiveValue’ node was found when reading from the JSON reader. A ‘Start-Object’ node was expected».»}}}
Tilbaketråkk: Create a SharePoint Site (SPWeb) using REST in SPD 2013 Workflow | SharePointRyan.com
Tilbaketråkk: Create a SharePoint Site (SPWeb) using REST in SPD 2013 Workflow - The Microsoft SharePoint Blog
Did you intend to use RequestHeader twice as a variable?
Hello Roger,
thanks for your clear instructions! Should this also work in SharePoint 2013 Online?
Kind rgds,
Yvonne
Yes, it should, but I have not tested yet.
Hi Roger,
I’m having the same issue that Sumit was having earlier (the RequestorId issue). I’m using SharePoint Online. What could be causing this issue?
Thanks Roger, this is brilliant! I’ve been showing it in some of my talks and giving you full credit, with links to this article. I hope to extend on it at some point. You have demystified a very powerful yet poorly documented set of capabilities – thanks again!!
Thank you for your post, Is there a way to have the sub site created under a specific site. For example the workflow would be on the top level site and I already have three sites under the top level; company A, Company B, Company C. I want to fill out a form with info and one piece of info would be the Company that this sub site should go under (Company B). So the workflow runs and instead of adding the site under the home it adds it as a sub site under Company B. Is that possible and can you point me in the right direction if it is?
Thank you,
Hi
I would try to construct the HTTP Post URL using parameters/variables. The url should look like http://intranet.wingtip.com/nameofyoursubsite/_api/web/webinfos/add.
Roger
Hi, really good, been looking for this for a while. Im using sharepoint online, and I keep getting suspended during the workflow. with this error…..
RequestorId: 767ee3a2-9194-b6cc-0000-000000000000. Details: An unhandled exception occurred during the execution of the workflow instance. Exception details: System.NotSupportedException: CannotReadAsType=Cannot read ‘Microsoft.Activities.Dynamic.DynamicObject’ as ‘System.String’ type. at Microsoft.Activities.Dynamic.DynamicItem.ReadAs(Type type) at Microsoft.Activities.Dynamic.DynamicItem.ReadAs[T]() at Microsoft.Activities.Messaging.SendHttpRequest.AddHeader(String headerName, DynamicItem headerValue, Boolean isContentHeader, HttpRequestMessage requestMessage, IList`1& contentHeaders, Boolean& isEmptyValue) at Microsoft.Activities.Messaging.SendHttpRequest.SendRequest(NativeActivityContext context) at System.Activities.NativeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation) Exception from activity SendHttpRequest HttpPost Switch Sequence Microsoft.SharePoint.WorkflowServices.Activities.CallHTTPWebService Sequence Microsoft.SharePoint.WorkflowServices.Activities.AppOnlySequence Creating Site Sequence Flowchart Create Site.WorkflowXaml_6932297d_96fb_4989_abd6_854eed1bc385
Not sure where to go with this.
Thanks
I do have the exact same error. Roger, could you please give us any direction?
Hi Roger,
Do you know how to construct request body for SOAP message (its envelope) using Sharepoint Designer 2013? I tried to put its envelope in a variable in a dictionary, but I got Bad Request.
Thank you so much for your help.
Hi Bani
Usually you will get this if workflows does not have permissions on you site.
Roger
«Permission Request» what is that what was wrong in that.. i am getting unazthorized error. please help.
please provide me exact permission request XML
Hi Rahul
The quotation marks in wordpress editor might be wrong when you copy the xml-text, causing the unauthorized error.
Roger
I love it! Very useful! Thanks so much for posting this.
One question–how do I make the workflow use a custom site template?
Hi Tim
Thanks for Your feedback!
Custom site template will get a strange system name constructed of a guid/id + the name – you will need this to be able to use a custom template. You should be able to find the template name using PowerShell (I don’t remember the syntax right now, but if you can’t find it I’ll help you). I did this in JavaScript looping throug all names until I found my template and then using the system name for it to create my site. Should be possible to do the same in SharePoint Designer Workflow as well. I cannot Access my Development machine right now, but I can post the code later if you need it.
Roger
It’s hard to find well-informed people on this topic,
but you seem like you know what you’re talking about! Thanks
First of all thank you for this greate piece of work.
I got one question:
Is it possible to fill out contents on the new subpage within the workflow?
Example: In my project page and within a list, people apply for a new project page which is created by the list and your workflow. Within this list i have a running project number. Now that the workflow creates the new webpage/project page, i want to let this new number appear on the new page without giving manual tasks to the project leaders. Is this possible?
I know i could use the project title for it, but there is always a title and the project number running. Also i got a custom template running for each project page.
Hi DofDk
The running number (I assume it’s the ID Field in the list Your are talking about) is not available until you save the list item. You will be able to use the number in the workflow, but it is not available to display in the form at creation. You could alternatively add a custom Field in Your list With a default calculated value that would be visible in the form – but the complexity ensuring that the same value might be a risk.
Did this answer Your question – or did I misunderstand?
Roger
Hi Roger, first of all thank you that you still observing your blog 🙂
Well as i cannot attach any pictures in here i will try to explain in more details;
I have a project page, within this page i have an application form (list), people do entries like title, project manager etc. After they have filled out the form, a workflow is provind a running number which i called project number (number column in the list). After they have Applied and the project number is provided by the workflow, they need to initate the workflow to create the project page.
I used your workflow to publish the project page and it also locates with help of the project number the new website to the right URL. What i want to know is: On my project page template i got several fields, one of them is called project number. Can i get your described workflow to pre-fill this field called project number in the new webpage? I simply want to use provided contents to pre-fill the new webpage without doing it manually.
This is the part im hanging right now, beside that i cannot get groups and uniqe permissions to run with the same workflow that creates the project page to lower manual work to a minimum.
FINALLY!!!
I’ve followed at least 10 of these with no success (for a slight different need than here but same calls etc…). Not sure if it was something here or a combination, but I was here when it WORKED! So thank you!
I was beginning to seriously doubt this would work…
First of all thank you for this greate piece of work.
I got one problem:
I have followed all these steps but I always get BadRequest in the responsecode. Does anybody know what can be wrong ?
Sigmundur, if you haven’t figured this out yet try emailing yourself the ResponseContent as well as the ResponseCode. I was getting BadRequest and it was because I had a bad parameter in my RequestHeader dictionary.
hey roger,
iam not sure if these article is watched by you at all, but imo the question from matthewmcd back in 2013 is a good one. if i go through your guide step by step, the action under point 22. brings me an error, that this variable already exists.
Regards
I’m getting an issue where most of the time this works great, but for some users it returns an InternalServerError «the URL is already in use» — even though it’s not, and the site was still created. Has anyone seen this before, and know how I can fix it? It’s making error handling a nightmare for me.
Hello,
Did you fix this error? I am stucked at this point. Till now it was creating subsites properly, but suddenly it stopped.
May be issue with template that we already created?
How do you inherit the root site top link bar?
Hi Roger
I’m so glad that you wrote this blog. I had no mistakes when entering and also the release of the app was without fault. Only when the workflow start, there was the following Errors:
An unhandled exception occurred during the execution of the workflow instance. Exception details: System.NotSupportedException: CannotReadAsType=Cannot read ‘Microsoft.Activities.Dynamic.DynamicObject’ as ‘System.String’ type.
Can you tell me what I’ve overlooked?
Best regards
Byers
Step 19: should be
«Add string variable named type with value SP.WebInfoCreation»
instead of
«Add string variable named type with value SP.WebInfoCreationInformation»
I discovered later SP.WebInfoCreationInformation is right (msdn.microsoft.com/en-us/library/office/jj164022.aspx)
Thanks great blog article but there are two errors in your process. You use two of the same variable RequestHeaders
Hi, can I know if i want to create a document library, what should i change?? 🙂 Thank you.
You can use the same method. You will have to find basic REST API commands here: https://msdn.microsoft.com/en-us/library/office/jj164022.aspx
Tilbaketråkk: Create a SharePoint Site (SPWeb) using REST in SPD 2013 Workflow | SPUG