4

I have a workflow which creates a site when an entry is made to a list. I need to activate one of the features at that newly created site using REST API. How can this be done?

2

Have you looked at feature stapling? I don't know all requirements, but the feature stapling is another way which can solve your issue.

  • Feature Stapling ,I think will not be a feasible option because we have to alter each site templet ONET.xml file manually. And if customer is not technically sound ,and simply create a template for its site and used it to create a site will surely not have that feature activated. – user27178 Oct 12 '15 at 7:06
1

The REST URL you can use is this one:

http://sitecollection/site/_api/web/features/add(featureId,force,featdefScope)

Additional information can be found here: http://msdn.microsoft.com/en-us/library/office/jj245237(v=office.15).aspx

If you really want to use REST and you have multiple successive features that need to be activated in order. Be sure to nest each REST action in the success eventhandler of each ajax call.

In other words

function ActivateFeatures() { 
   var feature1 = "/site/_api/web/features/add(" + featureId1 + ", false)";
   var feature2 = "/site/_api/web/features/add(" + featureId2 + ", false)";
   var feature3 = "/site/_api/web/features/add(" + featureId3 + ", false)";

   $.get(feature1, function() {
       $.get(feature2, function() {
          $.get(feature3);
       });
   });
}

But I don't recommend using REST. The best way to do this is following Alexander's advice and using a feature stapler.

1
function activateFeature() {
$.ajax({
    url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/features/add('7e2e2482-9007-4db3-8a7f-9bccd986ec4e')",
    type: "POST",
    headers: {
        "Accept": "application/json;odata=verbose",//return data format.
        "X-RequestDigest": $("#__REQUESTDIGEST").val()
    },
    success: function (data) {

    },
    error: function (err) {
        alert("Error: " + JSON.stringify(err));
    }
});

Make a post call on the endpoint web(to activate feature at web level) or site(to activate feature at site collection level) by just passing feature guid in the add method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.