0

I need to change the name of a subsite when a field is filled into a list item. I found this helpful article about using REST API to update subsite information and have it somewhat working.

I get an 'OK' response code so its going through but it is not actually changing the site title.

Requests:     
RequestHeader: {"content-type":"application\/json;odata=verbose","Accept":"application\/json;odata=verbose","X-HTTP-Method":"MERGE"}
Metadata: {"type":"SP.Web"}
RequestContent: {"__metadata":"{\"type\":\"SP.Web\"}","Title":"New Site Title","Description":"Site updated from REST API","ServerRelativeUrl":"\/teams\/'SiteCollName'\/'SiteName'\/Old_Site_Title"}
RESTParameters: {"parameters":{"__metadata":"{\"type\":\"SP.Web\"}","Title":"New Site Title","Description":"Site updated from REST API","ServerRelativeUrl":"\/teams\/'SiteCollName'\/'SiteName'\/Old_Site_Title"}}

Responses:
ResponseContent: {"d":{"Title":"Old Site Title"}}
ResponseHeader: {"Transfer-Encoding":["chunked"],"X-SharePointHealthScore":["0"],"X-SP-SERVERSTATE":["ReadOnly=0"],"DATASERVICEVERSION":["3.0"],"SPClientServiceRequestDuration":["7"],"SPRequestDuration":["40"],"SPRequestGuid":["c4adad15-4f72-6f3c-b764-263d94a83a4a"],"request-id":["c4adad15-4f72-6f3c-b764-263d94a83a4a"],"MS-CV":["Fa2txHJPPG+3ZCY9lKg6Sg.0"],"Strict-Transport-Security":["max-age=31536000"],"X-FRAME-OPTIONS":["SAMEORIGIN"],"MicrosoftSharePointTeamServices":["16.0.0.7115"],"X-Content-Type-Options":["nosniff"],"X-MS-InvokeApp":["1; RequireReadOnly"],"Cache-Control":["max-age=0, private"],"Date":["Mon, 27 Nov 2017 18:14:59 GMT"],"P3P":["CP=\"ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI\""],"Server":["Microsoft-IIS\/8.5"],"X-AspNet-Version":["4.0.30319"],"X-Powered-By":["ASP.NET"]}

ResponseCode: OK

From the ResponseContent, the workflow is identifying the current Site Title so I'm on the right track as to what I'm changing.

I am using the HTTP Call Service in an App Step to send the request as a POST (also tried as a PUT, didn't make a difference).

What additional information am I missing to get the sub site to update?

If you have an alternative way to do this, I am very much open to that as well.

0

first you should use a header for update

var header = {
            "IF-MATCH": "*",
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),
            "X-HTTP-Method": "MERGE"
         }

Then declare your data

var stringData = "{ '__metadata': { 'type': 'SP.Web' }, 'Title': 'New title' }";

And then perform the request as usual using post

$.ajax({
    url: "http://your_site_url/_api/web",
    type: "POST",
    contentType: "application/json;odata=verbose",
    data: stringData,
    headers: header,
    success: function (data) {
        //success
    },
    error: function (err) {
        console.log(err);
    }
});
  • Thanks for the answer! I am using SharePoint Designer's workflow HTTP Call Service so I'm not actually putting any code in. The code shown is from an email to myself showing the variables of the request. If I were to put the above code in, where would it go? – anonymous Nov 30 '17 at 18:52

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.