14
Technologies Creang subsites and change master page using REST API from SharePoint Designer Workflow WinWire Technologies Inc. 2350 Mission College Boulevard, Suite 925, Santa Clara, California, 95054 Email : [email protected] SharePoint Designer Workflow Pg.1 Copyright© 2016 WinWire Technologies

Creating subsites and change master page using REST API ... · Creating subsites and change master page using REST API from SharePoint Designer Workflow WinWire Technologies Inc

  • Upload
    vominh

  • View
    239

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Creating subsites and change master page using REST API ... · Creating subsites and change master page using REST API from SharePoint Designer Workflow WinWire Technologies Inc

Technologies

Creating subsites and change master page using REST API from

SharePoint Designer Workflow

WinWire Technologies Inc.2350 Mission College Boulevard,

Suite 925, Santa Clara, California, 95054Email : [email protected]

SharePoint Designer Work�ow

Pg.1 Copyright© 2016 WinWire Technologies

Page 2: Creating subsites and change master page using REST API ... · Creating subsites and change master page using REST API from SharePoint Designer Workflow WinWire Technologies Inc

Pg.2 Copyright© 2016 WinWire Technologies

In SharePoint 2013 Workflows newly introduced the Call http web service activity to implement the REST API calls. Using this activity we can create a SharePoint site and change the master pages.

In this example I have given a form (Out of box List form) to request a new site. I wanted to solve this using a SharePoint list with an attached workflow as a site request form.

1. Enable app permissions for Workflow2. Grant full control permission to workflow3. Create a list for Request sites4. Create a workflow that creates a site when new item is created

1. Under Settings button2. Select Site settings3. Select Manage site features4. Click Activate on Workflows can use app permissions

1. Click on the Settings button2. Go to Site Settings3. Under Users and Permissions, select Site app permissions4. Copy the client section of the App Identifier. This is the identifier between the last “|” and the “@” sign.

Enable app permissions Workflow

To Grant full control permission to workflow following below steps with site owner permissions.

Grant full control permission to workflow

SharePoint Designer Work�ow

Page 3: Creating subsites and change master page using REST API ... · Creating subsites and change master page using REST API from SharePoint Designer Workflow WinWire Technologies Inc

Pg.3 Copyright© 2016 WinWire Technologies

5. Navigate to the appinv.aspx page to Grant permission to an app in the site. http://{hostname}/{site}/_layouts/15/appinv.aspx

6. Paste the client id in the App Id field and click Lookup

You will see complete details of the workflow app id.

SharePoint Designer Work�ow

Page 4: Creating subsites and change master page using REST API ... · Creating subsites and change master page using REST API from SharePoint Designer Workflow WinWire Technologies Inc

Pg.4 Copyright© 2016 WinWire Technologies

7. Paste the following Permissions Request XML to grant full control permission <AppPermissionRequests> <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" /> </AppPermissionRequests>

8. Click Create. Then you will be asked for Trust it or not.

SharePoint Designer Work�ow

Page 5: Creating subsites and change master page using REST API ... · Creating subsites and change master page using REST API from SharePoint Designer Workflow WinWire Technologies Inc

1. Go to Site Contents2. Click on Add an app3. Click on Custom list4. Give the new list a name like “Request site” and click OK We do not need any more fields for this Example.

Create a list for requesting sites

1. Go to Site Contents2. Click on Request site list3. Click on List in the top menu to open list settings4. Click on Workflow Settings in the toolbar, then click Create a Workflow in Share Point Designer

Create the workflow

9. Click Trust It

Pg.5 Copyright© 2016 WinWire Technologies

SharePoint Designer Work�ow

Page 6: Creating subsites and change master page using REST API ... · Creating subsites and change master page using REST API from SharePoint Designer Workflow WinWire Technologies Inc

Request Headers

Pg.6 Copyright© 2016 WinWire Technologies

5. Click Allow if you get a security warning6. Enter a name for your workflow and click OK

7. Rename the Stage to “Creating Site”8. To achieve site creation using REST API, we need to define some parameters for this purpose we have to create some Dictionary actions in workflow. As this example I have created below dictionary actions

a) Request Headersb) Meta Datac) Request Parametersd) REST parameters

• Add a Build Dictionary action for request headers• Name the output variable “RequestHeader”• Click on {…} 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

SharePoint Designer Work�ow

Page 7: Creating subsites and change master page using REST API ... · Creating subsites and change master page using REST API from SharePoint Designer Workflow WinWire Technologies Inc

Meta Data• Add a new Build Dictionary action for Meta Data• Name the output variable “MetaData”• Add string variable named type with value SP.WebInfoCreationInformation

• Click OK to confirm all open dialog boxes

Pg.7 Copyright© 2016 WinWire Technologies

•Add a new string variable named Accept with the value application/json;odata=verbose and click OK

• Click OK

SharePoint Designer Work�ow

Page 8: Creating subsites and change master page using REST API ... · Creating subsites and change master page using REST API from SharePoint Designer Workflow WinWire Technologies Inc

Request Parameters

Pg.8 Copyright© 2016 WinWire Technologies

• Add a new Build dictionary action for Request parameters• Name the output variable named RequestParameters• Add below variables to RequestParameters directory

SharePoint Designer Work�ow

• Click OK in all open dialogs to save RequestParameters dictionary variables

Pg.8 Copyright© 2016 WinWire Technologies

Page 9: Creating subsites and change master page using REST API ... · Creating subsites and change master page using REST API from SharePoint Designer Workflow WinWire Technologies Inc

REST Parameters• Add a new Build dictionary action• Name thw output variable named RESTparameters• Add a variable named parameters type Dictionary• To add value Click the fx button to add the RequestParameters variable from workflow variables and parameters

9. Add App Step (Provide impersonating to the User)10. In App step add Call http web service action11. Click on … to add the web service URL under Enter the HTTP web service URL section12. Enter the URL (use your own site and add /_api/web/webinfos/add to it)13. Select HTTP Post in Specify HTTP method dropdown

• Click OK to close all open dialogs

Pg.9 Copyright© 2016 WinWire Technologies

SharePoint Designer Work�ow

Page 10: Creating subsites and change master page using REST API ... · Creating subsites and change master page using REST API from SharePoint Designer Workflow WinWire Technologies Inc

14. Click on OK15. Select the Call HTTP web service action16. Click on Advanced Properies in the toolbar17. Set RequestHeaders to variable RequestHeder and set RequestContent to variable RESTparameters

18. Click OK to close dialog19. In Stage: Creating Site set Transition to stage to go to End of Workflow20. Click Publish

21. Click OK in the next dialog:

22. Click Create site just below the Create site tab:

Pg.10 Copyright© 2016 WinWire Technologies

SharePoint Designer Work�ow

Page 11: Creating subsites and change master page using REST API ... · Creating subsites and change master page using REST API from SharePoint Designer Workflow WinWire Technologies Inc

Changing a site’s master page using REST via SharePoint Designer Workflow

To changing the existence customized master page to subsites created with my provisioning workflow.

So, we’re going to want to build a few dictionary variables:

MetadataMasterPage

23. Check Start workflow automatically when an item is created

24. Click Publish in the toolbar and confirm if you get any warning.25. That’s it! Go ahead and run your workflow and SharePoint REST API will create the sub site.

Pg.11 Copyright© 2016 WinWire Technologies

SharePoint Designer Work�ow

Page 12: Creating subsites and change master page using REST API ... · Creating subsites and change master page using REST API from SharePoint Designer Workflow WinWire Technologies Inc

Pg.12 Copyright© 2016 WinWire Technologies

SharePoint Designer Work�ow

2. RequestHeadersMasterPage

3. JSONMasterPage

Page 13: Creating subsites and change master page using REST API ... · Creating subsites and change master page using REST API from SharePoint Designer Workflow WinWire Technologies Inc

Note: There’s two master pages in SharePoint i.e. the Site Master & System Master. See the image below to figure out which one is which:

(Also note that you have to include both in your dictionary variable even if you’re just setting one to a different value)

4. Now all you have to do is create an App Step and include a “Call HTTP web ser-vice action” within it. The URL is going to be http://yoursiteurl /_api/web and the HTTP method will be POST.

Pg.13 Copyright© 2016 WinWire Technologies

SharePoint Designer Work�ow

Page 14: Creating subsites and change master page using REST API ... · Creating subsites and change master page using REST API from SharePoint Designer Workflow WinWire Technologies Inc

5. Click the OK button, then right click the workflow action and select properties.

6. Then Click OK.7. Click Publish in the toolbar and confirm if you get any warning.

That’s it! Go ahead and run your workflow and SharePoint REST API will change the site master page.

• RequestHeaders = Variable:RequestHeadersMasterPage• RequestContent = JSONMasterPage• ResponseHeaders = new Dictionary, call is ResponseHeadersMasterPage

Pg.14 Copyright© 2016 WinWire Technologies

SharePoint Designer Work�ow