Forum Discussion

Arun C's avatar
Arun C
Copper Contributor
Jun 30, 2017

Activate Site Feature through REST API

I'm trying to activate site level feature by using REST API in SharePoint Hosted App. I've given full control at Site Collection & Site level with App only Calls. But I'm getting "Access Denied Error" with 403 status. 

function bindButtonClick() {

            var featuresURI = hostUrl + "/_api/web/features/add('a7a2793e-67cd-4dc1-9fd0-43f61581207a')"; 
                $.ajax({
                    url: featuresURI,
                    method: 'POST',
                    headers: {
                        "Accept": "application/json;odata=verbose",
                        "X-RequestDigest": $("#__REQUESTDIGEST").val()
                    },
                    success: function (data) {
                        console.log("Feature Activated");
                    },
                    error: function (data) {
                        console.log("error: " + JSON.stringify(data));
                    }
                });
            }

Error:

Failed to load resource: the server responded with a status of 403 (Forbidden)
error: {"readyState":4,"responseText":"{\"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.\"}}}","status":403,"statusText":"Forbidden"}

 

4 Replies

    • Arun C's avatar
      Arun C
      Copper Contributor

      Hi Pieter Veenstra,

       

      Thanks for your comment..

      I've tried the same within SHA, But still facing issues.s

      Code:

      $pnp.sp.crossDomainWeb(addinweb, hostweb).get().then(function (success) {
              success.web.features.add("a7a2793e-67cd-4dc1-9fd0-43f61581207a").then(r =>
              {
                  console.log(r);
              }).catch(function (err)
              {
                  console.log(err);
              });
          }).catch(function (err) {
              console.log(err);
          });

       

      I'm getting error 

      TypeError: Cannot read property 'features' of undefined

       

      • Does instead of 

         

        $pnp.sp.crossDomainWeb(addinweb, hostweb).get().....

        maybe somethign like this work:

         

        $pnp.sp.crossDomainWeb(addinweb, hostweb).features........

Resources