cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Activate Site Feature - SharePoint Server Publishing (is this possible to do this automatically in O365)

Hi,

The question posed is as follows: Is it possible to Activate Site Feature - SharePoint Server Publishing in the O365 environment using workflow, a web service or a combination of workflow/web service or any other way?

The use case for the above requirement is as follows. We have a parent site with many project sub sites that are automatically created from a custom site template as projects are registered at the parent  Site level. These project sub sites are created by the Nintex workflow which uses the action Office 365 create site. It would seem that it would be standard for someone to want to automate the Activation of SharePoint Server Publishing feature without involving a human administrator to perform this functionality on hundreds, and maybe 1 or 2 thousand of sub sites.

I have done some reading/research but I don't have a clear answer for this this requirement in the O365 context.

Firstly is it possible to do? If so, how can one go about implementing this solution.

Looking forward to the discussions/comments.

Reply
21 Replies
Workflow Hero

Re: Activate Site Feature - SharePoint Server Publishing (is this possible to do this automatically in O365)

Hi Duane Stavropoulos​,

I don't think that we are able to activate / deactivate the feature via existing SharePoint web services.

Unfortunately, now we do not have any action to activate SharePoint features.

Or you can put your request through Customer Feedback for Nintex

Thanks

0 Kudos
Accept as Solution Reply
Not applicable

Re: Activate Site Feature - SharePoint Server Publishing (is this possible to do this automatically in O365)

Hi KuanChiang Lui

Thanks for the information, I have put my request through on Cutomer feedback. If there are any fellow Nintex community members who would like to see the support of activate/deactivation of site features, please go to the Customer Feedback for Nintex: Activate/De-activate site feature (Automation) e.g. SharePoint Publishing – Customer Feedback for Ni... and vote for the change

Thanks,

Duane

0 Kudos
Accept as Solution Reply
Not applicable

Re: Activate Site Feature - SharePoint Server Publishing (is this possible to do this automatically in O365)

This is actually possible through the REST web services. Your exact scenario is the same as ours. We have a site collection root site that is used to automatically provision multiple subsites as Project sites. When these project sites are provisioned, we have sandbox solution features that we created as well as the out-of-the-box "Site Feed" feature that needs to be activated.

The REST service that allows us to accomplish this is a little wonky in its documentation but it works.

https://<url to your destination site>/_api/web/features/add(featureId=guid'15a572c6-e545-4d32-897a-bab6f5846e18',force=false,featdefScope=2)

The Guid above for the feature is actually the Site Feed feature. You can get the GUID of the feature you wish to activate by going to the Activate Features page in SharePoint and using Developer Tools to inspect the button that activates that feature.

The featDefScope is the confusing part. You might need to play with it a bit to get it working since it doesn't match up with the documentation here: https://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.spfeaturedefinitionscope.aspx

but it is going to be a number, not the string.

This is going to be a POST as well, so you'll need the contextinfo of the destination site in the headers of the request.

Accept as Solution Reply
Not applicable

Re: Activate Site Feature - SharePoint Server Publishing (is this possible to do this automatically in O365)

Hi Aaron Prince​ (and any other interested parties )

I really appreciate your post!

I have a few questions (I am a newbie, so please forgive me if I'm asking really basic stuff).

1. If I put the full HTTP request, as per your example, then can I set leave the request header and Content as blank (i.e. not setup/initialise the dictionaries RequestheadersHttp and RequestContent variables?

2. I went to this link: https://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.spfeaturedefinitionscope.aspx

My concern with playing around is that I can't afford to enable publishing on ALL sub sites. From the enum above it would seem that it should be indexed from 0-3. It seems like your requirement and ours is the same, i.e. enable publishing per sub-project site after it is created so I could test with index 2 if there is no/minimal risk of enabling features on other sites.

Also does any authentication need to be done before making this call or as part of this call? If so how does one do this? I'm currently getting the followign Response Status Code: (REST HTTP Post) "Unauthorized"

Details of REST HTTP Post Parameters (logged as debug):

Did you do your implementation on O365?

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Activate Site Feature - SharePoint Server Publishing (is this possible to do this automatically in O365)

Oops I think I have overlook to this issue. Thanks to Aaron


The correct url should be

http://yoursiteurl/_api/web/features/add(featureId,force,featdefScope)
0 Kudos
Accept as Solution Reply
Not applicable

Re: Activate Site Feature - SharePoint Server Publishing (is this possible to do this automatically in O365)

Thanks KuanChiang Lui

I'm using the following configuration:

Call HTTP Web Service

Address: https://yoursiteurl/_api/web/features/add(94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb,false,2)

Request Type: HTTP Post

I have captured some debug after running the service which still gives the error "Unauthorized"

0 Kudos
Accept as Solution Reply
Not applicable

Re: Activate Site Feature - SharePoint Server Publishing (is this possible to do this automatically in O365)

Hi Duane,

Yes, I'm doing this on O365. A couple things regarding your configuration:

I'm using the following configuration:

You have a typo in the Accept value. There's a minus sign before the equals. It should read "application/json;odata=verbose".

Call HTTP Web Service

Address: https://yoursiteurl/_api/web/features/add(94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb,false,2)

Request Type: HTTP Post

Here, the address should actually include the words: featureId=guid' before the guid and the apostrophe ' after the guid. Then it should contain the word: force= before "false" and featDefScope= before the number representation of the scope.

https://yoursiteurl/_api/web/features/add(featureId=guid'94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb',force=false,featDefScope=2)

Ensure that your request is set up with that URL.

Before this web request is allowed through, you must first send a web request to get the formdigestvalue of the destination web site. It is required to do this if you're sending a request as a POST. You can get the context info by sending another POST request to:

https://destinationsiteurl/_api/contextinfo

Then use a Get Item From Dictionary Action, configured the following way:

That output variable, FormDigestValue, will be used in our Headers of the request we send to activate the feature. The header key is "X-RequestDigest" and the value will be your FormDigestValue.

Finally, in your web request to activate the feature, you can omit the variables for Request Content and Response Headers. These are not necessary to perform the web request and end up just taking up variable space in the workflow. You're free to inspect them if you like, however. They're just not required.

In regards to this affecting multiple sites, no - this will only affect the site on which you run the web request. It's a single site activation. The scopes are for the feature itself. If it's a web scoped feature, I've seen it work with both 0 and 2 even though it doesn't match up well with documentation.

Hopefully I answered all your questions. I know I had a heck of a time with this one when I was first trying to figure it out - mainly because the documentation on it from MSDN isn't completely correct. Or maybe I'm just misinterpreting it.

Accept as Solution Reply
Not applicable

Re: Activate Site Feature - SharePoint Server Publishing (is this possible to do this automatically in O365)

Hi Aaron Prince​,

Thanks for your detailed feedback.

In order to enable the site feature, it seems that there are two main actions that need to be done:

1. (HTTP POST) https://destinationsiteurl/_api/contextinfo

2. (HTTP POST) https://yoursiteurl/_api/web/features/add(featureId=guid'94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb',force...)

Q1. I would like to confirm that these are all the steps the site features?

Below I have summarised my setup of 1. and 2. I'm now getting an "unauthorised" error with the first post. Futher I would like to confirm my configuration of the two posts. Thanks for your patience.

1. (HTTP POST) https://destinationsiteurl/_api/contextinfo

In the case of 1. I have followed the following process:

a. Build Dictionary:

b. Configure HTTP POST:

I then log the response:

Response Status Code [Unauthorized]; Request Headers HTTP [{"accept":"application\/json;odata=verbose","content-type":"application\/json;odata=verbose"}]; Response Content [{"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access denied. You do not have permission to perform this action or access this resource."}}}];

I then removed the Request Header (I thought that the Request Header that I setup may be an issue) - However, I received the same log response.

I'm interested to know:

Q2. Why my configuration strings "application/json;odata=verbose" are returned as "application\/json;odata=verbose" and is this correct?

Q3. Whether the configuration of the HTTP Post: https://destinationsiteurl/_api/contextinfo is incorrect - what am I missing?

In regards to the rest of the implementation:

I do a get on the RESTContextInfoResponse (which failed above) - so not expecting this to work:

According to the Nintex documentation the configuration should be (http://help.nintex.com/en-US/O365/Default.htm#O365WorkFlow/Workflow Actions - STD/Get an Item from a Dictionary.htm%3FTocPath%3DNintex%2520Workflow%2520for%2520Office%2520365%7CActions%7C_____34)

However, I can't understand that we are using a nested dictionary here, and I'm not sure how nintex is interpreting the result, which is set to GetContextWebInformation

Q4. Please provide some insight here .

2. (HTTP POST) https://yoursiteurl/_api/web/features/add(featureId=guid'94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb',force...)

a. Before the feature enablement post I add the key X-RequestDigest and output as RequestHeadersHttp

b. Finally I configure the HTTP POST: https://yoursiteurl/_api/web/features/add(featureId=guid'94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb',force...)

0 Kudos
Accept as Solution Reply
Not applicable

Re: Activate Site Feature - SharePoint Server Publishing (is this possible to do this automatically in O365)

Since I was not able to get the the HTTP POST) https://destinationsiteurl/_api/contextinfo to work using the Call HTTP Web Service, I tried another method described in another post on the Nintex community which explained how to do contextinfo post using a Web Request (REF: How to execute a REST API request with Nintex Workflow )

Following this method allowed me to receive the following XML:

<?xml version="1.0" encoding="utf-8"?><d:GetContextWebInformation xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:type="SP.ContextWebInformation"><d:FormDigestTimeoutSeconds m:type="Edm.Int32">1800</d:FormDigestTimeoutSeconds><d:FormDigestValue>0xE8A8FD57C970345D35D1A0941725E2CD21EA011979F1AEBF50E7B4530F11B069302DF6F48CC8B09301846341C1578E980D78BD5067F7B7031A025ECE32FE83EC,13 Jul 2015 10:19:48 -0000</d:FormDigestValue><d:LibraryVersion>16.0.4208.1223</d:LibraryVersion><dSmiley FrustratediteFullUrl>https://sparza.sharepoint.com/sites/retailops</dSmiley FrustratediteFullUrl><dSmiley FrustratedupportedSchemaVersions m:type="Collection(Edm.String)"><d:element>14.0.0.0</d:element><d:element>15.0.0.0</d:element></dSmiley FrustratedupportedSchemaVersions><d:WebFullUrl>https://sparza.sharepoint.com/sites/retailops/development/107</d:WebFullUrl></d:GetContextWebInformation>

Which I was able to extract the FormDigestValue and build up the Dictionary to send to the HTTP Web Service:

{"accept":"application\/json;odata=verbose","content-type":"application\/json;odata=verbose","X-RequestDigest":"0xE8A8FD57C970345D35D1A0941725E2CD21EA011979F1AEBF50E7B4530F11B069302DF6F48CC8B09301846341C1578E980D78BD5067F7B7031A025ECE32FE83EC,13 Jul 2015 10:19:48 -0000"}

However I still got the "Unauthorized" Error. It may be that one should not mix HTTP Web Service calls with Web Requests?

0 Kudos
Accept as Solution Reply