Set Web properties of a site using SharePoint rest api - sharepoint

From Microsoft SharePoint documentation i can get web properties of a site using this request: "http:///_api/web/" (refer: https://msdn.microsoft.com/en-us/library/office/dn499819.aspx).
There are some properties which are R/W.
When i try to create these R/W properties i get 200 OK response but the properties value remain unchanged.
eg. property_name - SaveSiteAsTemplateEnabled.
initially it's value is True
initial get response:
{
"odata.metadata": "https://druvainternal.sharepoint.com/sites/testsharepoint/subsite1copy/_api/$metadata#Edm.Boolean",
"value": true
}
Then when i try to change its value using post call or merge call.
request:
"post"
endpoint - _api/web/SaveSiteAsTemplateEnabled
body = {"value":False}
The response i get is:
{"odata.metadata":"https://druvainternal.sharepoint.com/sites/testsharepoint/subsite1copy/_api/$metadata#Edm.Boolean","value":true
}
whose value is still True.
Am i sending the right request? In documentations it's not mentioned about how to set these properties.

Since Web.SaveSiteAsTemplateEnabled property is a property of Web class, you need to construct a request to update a Web resource for that matter.
The following example shows how to update SPWeb.SaveSiteAsTemplateEnabled property:
Endpoint Url: [web url]/api/web
Method: POST
Headers:
"X-HTTP-Method":"MERGE"
"If-Match":"*"
Data:
{"SaveSiteAsTemplateEnabled":false,"__metadata":{"type":"SP.Web"}}

Related

How to submit "form-data" in ADF "Web" activity POST call

I am trying to move data from a RESTFul API running on my on-prem application to ADB with ADF. I have installed self-paced IR in my private network to run the activity/pipeline. Now in one of my
API requires form-data to submit in POST call. Equivalent Postman looks like below
How to perform the same in ADF (As I will be running in self-paced IR dataflow is not applicable)? I am trying with "Web" Activity but dont know how to pass form data in it.
You are unable to pass form data in your ADF's Web Activity as you have selected incorrect method in Web activity:
You can select POST method from the dropdown as such:
After this you will get a place to add request body.
Also to get same effect of selecting form-data in postman, you can set 2 cookies as:
Content-Length: length of your request body in bytes
Content-Type: multipart/form-data; boundary= some value as boundary
Content-Type header reference

Azure Build Pipeline - Pause and Enable DefinitionQueueStatus change REST API

We have many dozens of build pipelines and we want to pause and resume (re-enable) build pipelines from a simple webapp interface as we are making config changes frequently. Here is the MS doc explaining this API:
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/update%20build?view=azure-devops-rest-5.0#definitionqueuestatus
From this documentation, it appears I need to hit the REST API and change/toggle the DefinitionQueueStatus -- however, this documentation only shows a sample for a build specific operation, whereas I want to pause then re-enable the entire build pipeline. What is the proper way to make this call?
I'm using fetch - and I've tried many dozen formats in the call - the 'ourorg' and 'ourproject' are correct (we use this call structure for many other calls), but all fails for this call below. I grabbed the 'definitionID' from the URL I can visibly see when in the Azure devops portal on the specific build pipeline page, and I'm using it for the {buildID} as I don't know what else to put there. Any guidance to help here is appreciated - I don't need to use fetch btw - any working sample will help here:
fetch(https://dev.azure.com/our_org/our_projectname/_apis/build/builds/definitionId=1593?retry=true&api-version=5.0 {
method: 'PATCH ',
credentials: 'same-origin',
body: 'DefinitionQueueStatus: "Enabled"'
}).then(function(response) {
console.log(response);
})
It seems that the body is incorrect in your post. Here is sample about how to use POSTMAN to access Azure DevOps Services REST APIs.
Generate the PAT, and then record the token, it is important to use to authorization, please see this document.
Create a new request in POSTMAN, it is recommended to put the request in a collection for Azure DevOps Services REST API;
Select the authorization as Basic Auth, you can input the username as any value, and the password as the token which is generated in step1.
Basic Auth
Set the REST API which you want to use,and select the request method type(GET,POST,FETCH ....), here you use https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}?api-version=5.0.
In the Body tab, you can set the request body as raw in json format, and input the value as following:
{
"buildNumber":"#20190607.2",
"buildNumberRevision":1,
"definition":
{
"id":1,
"createdDate":null,
"queueStatus":"paused"
}
}
Everthing is ready now, you can send the request, if sccuess, you will get the response from the REST API.
In your post, the body content is incorrect, the Request Body should meet the format in the REST API document. The DefinitionQueueStatus is a type in definitions. In addition, if you send the request with parameter retry, you will get the message The request body must be empty when the retry parameter is specified..

azure logic app & http step response

I have 2 HTTP actions, one after another in a logic app, how do I read the response from a previous HTTP action in the second HTTP action?
First HTTP call (REST) returns a response in JSON format -
{
"authResult": {
"isPasswordExpired": true,
"authToken": "cxxcxcxc",
"message": "Login Successful"
}
}
I want to send authtoken from the result in second http action as authorization header.
As Derke Li mentioned that we could use exression or Parse Json to do that. I also do a demo about how to use the Parse JSON action.
1.Add the Parse Json action after the first Http action
2.Add the parse content and click on the button "Use sample payload to generate schema" and that will pop a new window. Paste in your "authResult" json. As seen in the below image.
3.Then we could pick the token from the dynamic content.
4.We could check the result.
There are two ways you can do this.
Use expression to directly reference the property. #body('NameOfFirstHTTPAction')?['authResult']?'[authToken]
Add a "Parse JSON" action in between the two HTTP action, and provide a sample response of the first HTTP action to generate a schema. Then, in the second HTTP action, you will see authToken as a token from the dynamic content picker for you to reference.

OneNote API intermittently returns HTTP 400 when querying O365 SharePoint SiteId

My code calls the OneNote API to resolve a SharePoint Online site URL to a SiteCollectionId and SiteId. We get a bearer token, set the HTTP auth header and issue a GET request to:
https://www.onenote.com/api/v1.0/myorganization/sitecollections/FromUrl(url='https://mytenantxyz.sharepoint.com/sites/copynotesite')
For approx a week, it has been returning the expected response, similar to:
{
"#odata.context": "https://www.onenote.com:576/api/v1.0/$metadata#Microsoft.OneNote.Api.SiteMetadata",
"siteCollectionId": "111e03ac-468c-4a28-9aab-543098ef49bb",
"siteId": "555d72a0-f82f-4e4c-ae8a-17ef0ea04f32"
}
However, today it has decided to return the following in approx 9 out of 10 requests:
{
error": {
"code" : “20158”,
"message": "Unable to get SiteMetadta for the url specified in the request.",
"#api.url": "http://aka.ms/onenote-errors#C20158"
}
}
The Microsoft docs (link) explain error 20158 as:
"Unable to get metadata for the site URL specified in the request. Check the format of the supplied URL. Supported formats include https://domain.sharepoint.com/site-a and https://domain.com/sites/site-a. (SharePoint support is in Preview.)"
I was unaware that this was in preview any more (I thought it was GA), but anyway it doesn't explain why it intermittently works for exactly the same input (same URL and bearer token).
Could it just be a bug in the OneNote API or SharePoint API that it must call under the covers?
Please refer to the blog - http://blogs.msdn.com/b/onenotedev/archive/2015/06/11/and-sharepoint-makes-three.aspx
We added the FromUrl method so you can pass in an absolute site URL and get the site collection and site IDs. You should make this call only when needed, and then store the values (site collection and site IDs) for future use in your requests to the OneNote API.
this however does not answer intermittency. Please share the X-correlationId header with us for a failing request so that we can help further.

Calling multipart/form-data REST service in Azure Logic Apps

I have made a workflow using Http Listener and Http actions in Azure Logic Apps. Listener is to catch POST request and Http action has details of my api which is hosted over azure web app. Request is multipart/form-data type and posts a file along with 3 other string values.
My problems are
If I'm explicitly setting content type header as multipart/form-data in Http action, it is not passing any boundary to api controller and my api is giving error "request was rejected because no multipart boundary was found".
If I'm trying to pass #triggers().outputs.body.ContentType as header of my http action, I'm getting this error:
{"code":"InvalidTemplate","message":"Unable to process template
language expressions in action 'http' inputs at line '1' and column
'11': 'Error converting value \"multipart/form-data;
boundary=----WebKitFormBoundaryi3knGy6dh92BdKdr\" to type
'Microsoft.WindowsAzure.ResourceStack.Common.Collections.InsensitiveDictionary`1[System.String]'.
Path 'headers'.'."}
Please help, how can I pass content type and boundary both to my api using Http action?
The headers object in the Logic app definition is a JSON object with keys and values. Specifically, if you want to pass the content-type header like above your object definition in the code view would look like:
"MyAction" : {
"type" : "http",
"inputs" : {
"headers" : {
"Content-type" : "#triggerBody().ContentType"
},
"body" : … rest of properties here …
Hopefully this is why your API isn't getting the boundary either.

Resources