Friday, April 5, 2019

SharePoint REST API's

SharePoint2016(onPreim)

Introduction

This collection of API's can be used to communicate with SharePoint 2016 (on-premise ) via REST API's with form digest or using Bearer Token with SharePoint Online. This collection is tried on Document Library with Major version available(only). Calling party is assumed to have GUIDs of the taxonomies.One more important thing to highlight, under "Send Metada data without version update 1st time after upload" and "Send modifier without version update", I have used adusername [without even domain name] to refer to SharePoint user. You may also leverage email address. But in any case, this user must be validated for presence by "Ensureuser" REST call before consuming in  any of the dependent API’s.


Authentication

In case of onperim we are using Formdigest for authentication. with SharePoint Online, you may create a SharePoint addin app and authrize with bearer token.


POST 01.01 GetFormDigest

https://servernamehidden:3434/sites/hkDev/_api/contextinfo

Extract FormDigest token from SharePoint 2016 with username and password. Authorization:NTLM (along with username and password). use FormDigestValue from the response as a header (X-RequestDigest) for future calls, when expires, get a new value from here.

Headers

acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.

sample code

var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/contextinfo', 'headers': { 'accept': ' application/json;odata=verbose' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); req.end();
POST 01.02 RefreshFormDigest
https://servernamehidden:3434/sites/hkDev/_api/contextinfo

Refreshes FormDigest with previous FormDigest as an input in the header.

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.

var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/contextinfo', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); req.end();
GET 02.01 Get SP Group from SP
https://servernamehidden:3434/sites/hkDev/_api/web/sitegroups?$filter=Title eq 'Excel Services Viewers'&$select=Id,Title

Extracts a SPGroup from a site identified by Title or LoginName.

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.

Params

$filterTitle eq 'Excel Services Viewers'
you could use Title or LoginName in the filter
$selectId,Title
in this sample I am selecting only id and title

var https = require('https'); var options = { 'method': 'GET', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/sitegroups?$filter=Title%20eq%20%5C'Excel%20Services%20Viewers%5C'&$select=Id%2CTitle', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = ; req.write(postData); req.end();
POST 02.02 Ensureuser

https://servernamehidden:3434/sites/hkDev/_api/web/ensureuser

Checks whether the specified login name belongs to a valid user in the site. If the user doesn't exist, adds the user to the site. pass json body like { "logonName": "i:0#.w|domain\aduserloginname" }

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.
Content-Typeapplication/json
The Content-Type entity header is used to indicate the media type of the resource.

Body

raw (application/json)
{ "logonName": "i:0#.w|domainnamehidden\\loginadidhidden" }

var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/ensureuser', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000', 'Content-Type': 'application/json' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = "{ \"logonName\": \"i:0#.w|domainnamehidden\\\\loginadidhidden\" }"; req.write(postData); req.end();

GET 02.03 Get User from web

https://servernamehidden:3434/sites/hkDev/_api/web/siteusers?$filter=substringof('domainnamehidden\loginadidhidden',LoginName)&$select=Id,LoginName,Email

Extract a user’s properties from the site identified by loginName. Say, loginName property for user is "i:0#.w|domainnamehidden\\loginadidhidden".
I could user filter which says give me the users which contain a string value "domainnamehidden\loginadidhidden"

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.

Params

$filtersubstringof('domainnamehidden\loginadidhidden',LoginName)
substringof works fine in the filter, endswith not supported in SP.
$selectId,LoginName,Email
selected only few properties here

sample code

var https = require('https'); var options = { 'method': 'GET', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/siteusers?$filter=substringof(%5C'domainnamehidden%5C%5Cloginadidhidden%5C'%2CLoginName)&$select=Id%2CLoginName%2CEmail', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = ; req.write(postData); req.end();


POST 02.04 Add USer to SP Group

https://servernamehidden:3434/sites/hkDev/_api/web/SiteGroups(@grpid)/users?@grpid=4



Adds user in a SP Group. pass Login name in the body.

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.
Content-Typeapplication/json
The Content-Type entity header is used to indicate the media type of the resource.

Params

@grpid4
You may get group id from "02.01 Get SP Group from SP"

Body

raw (application/json)
{

    "LoginName": "i:0#.w|domainnamehidden\\loginadidhidden"
}



var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/SiteGroups(@grpid)/users?@grpid=4', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000', 'Content-Type': 'application/json' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = "{\r\n\r\n \"LoginName\": \"i:0#.w|domainnamehidden\\\\loginadidhidden\"\r\n}"; req.write(postData); req.end();



POST 02.05 Remove user from SP Group

https://servernamehidden:3434/sites/hkDev/_api/web/SiteGroups(@grpid)/users/removebyid(@usrid)?@grpid=4&@usrid=22

Remove a user identified by @usrid from an SP Group identified by @grpid.

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.

Params

@grpid4
You may get group id from "02.01 Get SP Group from SP"
@usrid22
you may get userid from "02.02 Ensureuser"

var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/SiteGroups(@grpid)/users/removebyid(@usrid)?@grpid=4&@usrid=22', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); req.end();


POST 03.00 Try Dirty Upload


https://servernamehidden:3434/sites/hkDev/_api/web/lists/getByTitle(@doclibname)/RootFolder/folders(@folderunderl1)/files/add(url=@filnme,overwrite=@ovrt)?@doclibname='hemantSample'&@folderunderl1='hemFolder'&@filnme='hemanttestfile1.txt'&@ovrt='true'
send file in single call. Won't work well with large files. Pass binary in the body.

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
content-length49
length of file stream
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.
Content-Typeapplication/octet-stream
The Content-Type entity header is used to indicate the media type of the resource.

Params

@doclibname'hemantSample'
in this sample, I used getByTitle to get the SPDocLib.
@folderunderl1'hemFolder'
This is a level 1 folder inside the document library.
@filnme'hemanttestfile1.txt'
This is intended file name and url in the target folder. Input file name could be anything while extracting binary on the local machine. but this filename is unique in a folder.
@ovrt'true'
if a file exists already, overwrite, if versioning is enabled in the document library, the next version is created.

Body

file


var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/lists/getByTitle(@doclibname)/RootFolder/folders(@folderunderl1)/files/add(url=@filnme,overwrite=@ovrt)?@doclibname=%5C'hemantSample%5C'&@folderunderl1=%5C'hemFolder%5C'&@filnme=%5C'hemanttestfile1.txt%5C'&@ovrt=%5C'true%5C'', 'headers': { 'Accept': ' application/json;odata=verbose', 'content-length': '49', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000', 'Content-Type': 'application/octet-stream' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = ; req.write(postData); req.end();

POST 04.00 Delete File

https://servernamehidden:3434/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)?@fileurl='/sites/hkDev/hemsample/hemFolder/hemanttestfile1.txt'
Deletes a file

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-HTTP-MethodDELETE
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.

Params

@fileurl'/sites/hkDev/hemsample/hemFolder/hemanttestfile1.txt'
getfilebyserverrelativeurl needs file url like relative to the web application.

var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)?@fileurl=%5C'%2Fsites%2FhkDev%2Fhemsample%2FhemFolder%2Fhemanttestfile1.txt%5C'', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-HTTP-Method': 'DELETE', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = ; req.write(postData); req.end();



GET 05.01 Check if file exists

https://servernamehidden:3434/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)?@fileurl='/sites/hkDev/hemsample/hemFolder/hemanttestfile1.txt'
If file doesn't exist expect 500 response

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.

Params

@fileurl'/sites/hkDev/hemsample/hemFolder/hemanttestfile1.txt'
getfilebyserverrelativeurl needs file url like relative to the web application.
var https = require('https'); var options = { 'method': 'GET', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)?@fileurl=%5C'%2Fsites%2FhkDev%2Fhemsample%2FhemFolder%2Fhemanttestfile1.txt%5C'', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = ; req.write(postData); req.end();



POST 05.02 CreateDummyFile

https://servernamehidden:3434/sites/hkDev/_api/web/lists/getByTitle(@doclibname)/RootFolder/folders(@folderunderl1)/files/add(url=@filnme,overwrite=@ovrt)?@doclibname='hemantSample'&@folderunderl1='hemFolder'&@filnme='hemanttestfile3.txt'&@ovrt='true'
while chunk upload, if there is no previous version at this path, create a dummy file

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
content-length49
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.
Content-Typeapplication/octet-stream
The Content-Type entity header is used to indicate the media type of the resource.

Params

@doclibname'hemantSample'
in this sample I used getByTitle to get the SPDocLib.
@folderunderl1'hemFolder'
This is a level 1 folder inside the document library.
@filnme'hemanttestfile3.txt'
This is intended file name and url in the target folder. Input file name could be anything while extracting binary on local machine. but this filenme is unique in a folder.
@ovrt'true'
if file exist already, overrite, if version is enabled in document library, next version is created.


var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/lists/getByTitle(@doclibname)/RootFolder/folders(@folderunderl1)/files/add(url=@filnme,overwrite=@ovrt)?@doclibname=%5C'hemantSample%5C'&@folderunderl1=%5C'hemFolder%5C'&@filnme=%5C'hemanttestfile3.txt%5C'&@ovrt=%5C'true%5C'', 'headers': { 'Accept': ' application/json;odata=verbose', 'content-length': '49', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000', 'Content-Type': 'application/octet-stream' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = ; req.write(postData); req.end();


POST 05.03 Checkout (caution, you will get two versions in case of new file)

https://servernamehidden:3434/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/CheckOut()?@fileurl='/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'
Checkout an existing file OR the dummy one just created. You may want to check out a file to make sure that no one changes it before you update it. After your update, you should check the file back in so that others can work with it.

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.

Params

@fileurl'/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'
getfilebyserverrelativeurl needs file url like relative to the web application.


var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/CheckOut()?@fileurl=%5C'%2Fsites%2FhkDev%2Fhemsample%2FhemFolder%2Fhemanttestfile3.txt%5C'', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = ; req.write(postData); req.end();


POST 05.04 Chunk upload Start 1 send first chunk

https://servernamehidden:3434/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/startupload(uploadId=@hemsession)?@fileurl='/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'&@hemsession='6d8e4933-fd7f-4ac3-aa96-be3a0a5c9527'
start sending file stream step 1. pass binary in the body.

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.
Content-Typeapplication/octet-stream
The Content-Type entity header is used to indicate the media type of the resource.

Params

@fileurl'/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'
getfilebyserverrelativeurl needs file url like relative to  the web application.
@hemsession'6d8e4933-fd7f-4ac3-aa96-be3a0a5c9527'
something like a guid to bind together startupload, continue upload (multiple may be) and finish upload.

Body

file

var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/startupload(uploadId=@hemsession)?@fileurl=%5C'%2Fsites%2FhkDev%2Fhemsample%2FhemFolder%2Fhemanttestfile3.txt%5C'&@hemsession=%5C'6d8e4933-fd7f-4ac3-aa96-be3a0a5c9527%5C'', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000', 'Content-Type': 'application/octet-stream' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = ; req.write(postData); req.end();


POST 05.05 Continue Upload2


https://servernamehidden:3434/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/continueupload(uploadId=@hemsession, fileOffset=@offf)?@fileurl='/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'&@hemsession='6d8e4933-fd7f-4ac3-aa96-be3a0a5c9527'&@offf=49
send second chunk step 2. pass binary in the body.

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.
Content-Typeapplication/octet-stream
The Content-Type entity header is used to indicate the media type of the resource.

Params

@fileurl'/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'
getfilebyserverrelativeurl needs file url like relative to the web application.
@hemsession'6d8e4933-fd7f-4ac3-aa96-be3a0a5c9527'
something like a guid to bind together startupload, continue upload (multiple may be) and finish upload.
@offf49
fileOffset in case of continue upload and finish upload only

Body

file


var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/continueupload(uploadId=@hemsession, fileOffset=@offf)?@fileurl=%5C'%2Fsites%2FhkDev%2Fhemsample%2FhemFolder%2Fhemanttestfile3.txt%5C'&@hemsession=%5C'6d8e4933-fd7f-4ac3-aa96-be3a0a5c9527%5C'&@offf=49', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000', 'Content-Type': 'application/octet-stream' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = ; req.write(postData); req.end();

POST 05.06 Continue Upload3

https://servernamehidden:3434/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/continueupload(uploadId=@hemsession, fileOffset=@offf)?@fileurl='/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'&@hemsession='6d8e4933-fd7f-4ac3-aa96-be3a0a5c9527'&@offf=98
send third chunk step 3. pass binary in the body.

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.
Content-Typeapplication/octet-stream
The Content-Type entity header is used to indicate the media type of the resource.

Params

@fileurl'/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'
getfilebyserverrelativeurl needs file url like relative to the web application.
@hemsession'6d8e4933-fd7f-4ac3-aa96-be3a0a5c9527'
something like a guid to bind together startupload, continue upload (multiple may be) and finish upload.
@offf98
fileOffset in case of continue upload and finish upload only

Body

file

var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/continueupload(uploadId=@hemsession, fileOffset=@offf)?@fileurl=%5C'%2Fsites%2FhkDev%2Fhemsample%2FhemFolder%2Fhemanttestfile3.txt%5C'&@hemsession=%5C'6d8e4933-fd7f-4ac3-aa96-be3a0a5c9527%5C'&@offf=98', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000', 'Content-Type': 'application/octet-stream' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = ; req.write(postData); req.end();

POST 05.07 Continue Upload4





https://servernamehidden:3434/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/continueupload(uploadId=@hemsession, fileOffset=@offf)?@fileurl='/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'&@hemsession='6d8e4933-fd7f-4ac3-aa96-be3a0a5c9527'&@offf=147
send forth chunk step 4, and so on till last chunk. pass binary in the body.

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.
Content-Typeapplication/octet-stream
The Content-Type entity header is used to indicate the media type of the resource.

Params

@fileurl'/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'
getfilebyserverrelativeurl needs file url like relative to the web application.
@hemsession'6d8e4933-fd7f-4ac3-aa96-be3a0a5c9527'
something like a guid to bind together startupload, continue upload (multiple may be) and finish upload.
@offf147
fileOffset in case of continue upload and finish upload only

Body

file


var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/continueupload(uploadId=@hemsession, fileOffset=@offf)?@fileurl=%5C'%2Fsites%2FhkDev%2Fhemsample%2FhemFolder%2Fhemanttestfile3.txt%5C'&@hemsession=%5C'6d8e4933-fd7f-4ac3-aa96-be3a0a5c9527%5C'&@offf=147', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000', 'Content-Type': 'application/octet-stream' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = ; req.write(postData); req.end();

POST 05.08 Finish Upload
https://servernamehidden:3434/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/finishupload(uploadId=@hemsession, fileOffset=@offf)?@fileurl='/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'&@hemsession='6d8e4933-fd7f-4ac3-aa96-be3a0a5c9527'&@offf=196
send last chunk step 5. pass binary in the body.

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.
Content-Typeapplication/octet-stream
The Content-Type entity header is used to indicate the media type of the resource.

Params

@fileurl'/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'
getfilebyserverrelativeurl needs file url like relative to the web application.
@hemsession'6d8e4933-fd7f-4ac3-aa96-be3a0a5c9527'
something like a guid to bind together startupload, continue upload (multiple may be) and finish upload.
@offf196
fileOffset in case of continue upload and finish upload only

Body

file

var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/finishupload(uploadId=@hemsession, fileOffset=@offf)?@fileurl=%5C'%2Fsites%2FhkDev%2Fhemsample%2FhemFolder%2Fhemanttestfile3.txt%5C'&@hemsession=%5C'6d8e4933-fd7f-4ac3-aa96-be3a0a5c9527%5C'&@offf=196', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000', 'Content-Type': 'application/octet-stream' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = ; req.write(postData); req.end();

POST 05.09 Send Metada data without version update 1st time after upload

https://servernamehidden:3434/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/listitemallfields/validateupdatelistitem?@fileurl='/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'
send atleast mandatory fields please, step 6. body contains JSON of formValues and bNewDocumentUpdate. bNewDocumentUpdate needs to be true to avoid ++version. checkincomments can also be passed in body if file was checkedout.

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.
Content-Typeapplication/json;odata=verbose
The Content-Type entity header is used to indicate the media type of the resource.

Params

@fileurl'/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'
getfilebyserverrelativeurl needs file url like relative to the web application.

Body

raw ( application/json;odata=verbose)
{
    "formValues": [
        {
            "__metadata": {
                "type": "SP.ListItemFormUpdateValue"
            },
            "FieldName": "hk1_hk2_hk3",
            "FieldValue": "4_1318_896|8c843e5f-2289-4559-b5d4-8eba4ed04885;5_1319_896|384161b9-0f7d-4985-bfa2-400adf8dc3bd;1_1320_896|0e44c06a-dfac-422b-b0d4-c4f94e20f0a1;2_1321_896|fe57e512-8b13-47d2-8fd8-96f47c923a4f;"
        },
        {
        "__metadata": {
                "type": "SP.ListItemFormUpdateValue"
            }, 
            "FieldName": "hemcreator",
            "FieldValue":"[{'Key': 'dummyuser1'}]"
        }
        ,
         {
        "__metadata": {
                "type": "SP.ListItemFormUpdateValue"
            }, 
            "FieldName": "Author",
            "FieldValue":"[{'Key': 'dummyuser2'}]"
        }
        ,
         {
        "__metadata": {
                "type": "SP.ListItemFormUpdateValue"
            }, 
            "FieldName": "Editor",
            "FieldValue":"[{'Key': 'dummyuser3'}]"
        }
        ,
        {
        "__metadata": {
                "type": "SP.ListItemFormUpdateValue"
            },
            "FieldName": "prjnme",
            "FieldValue": "hk_blog"
        }
    ],
  
    "bNewDocumentUpdate": true
}

var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/listitemallfields/validateupdatelistitem?@fileurl=%5C'%2Fsites%2FhkDev%2Fhemsample%2FhemFolder%2Fhemanttestfile3.txt%5C'', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000', 'Content-Type': ' application/json;odata=verbose' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = "{\r\n \"formValues\": [\r\n {\r\n \"__metadata\": {\r\n \"type\": \"SP.ListItemFormUpdateValue\"\r\n },\r\n \"FieldName\": \"hk1_hk2_hk3\",\r\n \"FieldValue\": \"4_1318_896|8c843e5f-2289-4559-b5d4-8eba4ed04885;5_1319_896|384161b9-0f7d-4985-bfa2-400adf8dc3bd;1_1320_896|0e44c06a-dfac-422b-b0d4-c4f94e20f0a1;2_1321_896|fe57e512-8b13-47d2-8fd8-96f47c923a4f;\"\r\n },\r\n {\r\n \"__metadata\": {\r\n \"type\": \"SP.ListItemFormUpdateValue\"\r\n }, \r\n \"FieldName\": \"hemcreator\",\r\n \"FieldValue\":\"[{'Key': 'dummyuser1'}]\"\r\n }\r\n ,\r\n {\r\n \"__metadata\": {\r\n \"type\": \"SP.ListItemFormUpdateValue\"\r\n }, \r\n \"FieldName\": \"Author\",\r\n \"FieldValue\":\"[{'Key': 'dummyuser2'}]\"\r\n }\r\n ,\r\n {\r\n \"__metadata\": {\r\n \"type\": \"SP.ListItemFormUpdateValue\"\r\n }, \r\n \"FieldName\": \"Editor\",\r\n \"FieldValue\":\"[{'Key': 'dummyuser3'}]\"\r\n }\r\n ,\r\n {\r\n \"__metadata\": {\r\n \"type\": \"SP.ListItemFormUpdateValue\"\r\n },\r\n \"FieldName\": \"prjnme\",\r\n \"FieldValue\": \"hk_blog\"\r\n }\r\n ],\r\n \r\n \"bNewDocumentUpdate\": true\r\n}"; req.write(postData); req.end();


POST 05.10 Send modifier without version update

https://servernamehidden:3434/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/listitemallfields/validateupdatelistitem?@fileurl='/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'
if the file was checked out, this is needed - to fix Editor ( we want to store actual editor, since we are using service account). Reason being checkout was done by Service account, not the actual user. And hence modifier is changed to service user after sending metadata in the last call.

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.
Content-Typeapplication/json;odata=verbose
The Content-Type entity header is used to indicate the media type of the resource.

Params

@fileurl'/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'
getfilebyserverrelativeurl needs file url like relative to the web application.

Body

raw ( application/json;odata=verbose)
{
    "formValues": [
      
         {
        "__metadata": {
                "type": "SP.ListItemFormUpdateValue"
            }, 
            "FieldName": "Editor",
            "FieldValue":"[{'Key': 'dummyuser3'}]"
        }
       
    ],
  
    "bNewDocumentUpdate": true
}

var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/listitemallfields/validateupdatelistitem?@fileurl=%5C'%2Fsites%2FhkDev%2Fhemsample%2FhemFolder%2Fhemanttestfile3.txt%5C'', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000', 'Content-Type': ' application/json;odata=verbose' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = "{\r\n \"formValues\": [\r\n \r\n {\r\n \"__metadata\": {\r\n \"type\": \"SP.ListItemFormUpdateValue\"\r\n }, \r\n \"FieldName\": \"Editor\",\r\n \"FieldValue\":\"[{'Key': 'dummyuser3'}]\"\r\n }\r\n \r\n ],\r\n \r\n \"bNewDocumentUpdate\": true\r\n}"; req.write(postData); req.end();


GET 06.01 Get File Metadata ListItemAllFields

https://servernamehidden:3434/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/ListItemAllFields?@fileurl='/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'

get metadata for the file.

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.

Params

@fileurl'/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'
getfilebyserverrelativeurl needs file url like relative to the web application.

var https = require('https'); var options = { 'method': 'GET', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/ListItemAllFields?@fileurl=%5C'%2Fsites%2FhkDev%2Fhemsample%2FhemFolder%2Fhemanttestfile3.txt%5C'', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); req.end();


GET 06.02 Get File Metadata select specific in ListItemAllFields

https://servernamehidden:3434/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/ListItemAllFields?@fileurl='/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'&$select=Title,hk1_hk2_hk3

get specific metadata for the file.

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.

Params

@fileurl'/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'
getfilebyserverrelativeurl needs file url like relative to the web application.
$selectTitle,hk1_hk2_hk3
limit selection to two properties here.
var https = require('https'); var options = { 'method': 'GET', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/ListItemAllFields?@fileurl=%5C'%2Fsites%2FhkDev%2Fhemsample%2FhemFolder%2Fhemanttestfile3.txt%5C'&$select=Title%2Chk1_hk2_hk3', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); req.end();


GET 06.03 Get File Stream

https://servernamehidden:3434/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/$value?@fileurl='/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.

Params

@fileurl'/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'
getfilebyserverrelativeurl needs file url like relative to the web application.
var https = require('https'); var options = { 'method': 'GET', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)/$value?@fileurl=%5C'%2Fsites%2FhkDev%2Fhemsample%2FhemFolder%2Fhemanttestfile3.txt%5C'', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); req.end();


GET 06.04 Get Previous Versions

https://servernamehidden:3434/sites/hkDev/_api/web/getfilebyserverrelativeurl('/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt')/versions?@fileurl='/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.

Params

@fileurl'/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'
getfilebyserverrelativeurl needs file url like relative to the web application.

var https = require('https'); var options = { 'method': 'GET', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/getfilebyserverrelativeurl(\'/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt\')/versions?@fileurl=%5C'%2Fsites%2FhkDev%2Fhemsample%2FhemFolder%2Fhemanttestfile3.txt%5C'', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); req.end();

POST 06.05 Checkin (just in case needed)

https://servernamehidden:3434/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)//CheckIn(comment=@comm,checkintype=@typ)?@fileurl='/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'&@comm='some comments here plz'&@typ=0
The following example shows how to check in a file

Headers

Acceptapplication/json;odata=verbose
The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Verbose JSON is not the default OData format. To receive responses in Verbose JSON, the client MUST explicitly ask for them.
X-RequestDigest0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000
use FormDigestValue from the response of "01.01 GetFormDigest", if expires (401 error), get a new value.

Params

@fileurl'/sites/hkDev/hemsample/hemFolder/hemanttestfile3.txt'
getfilebyserverrelativeurl needs file url like relative to the web application.
@comm'some comments here plz'
checkin comments
@typ0
MinorCheckIn (0) , MajorCheckIn(1) or OverwriteCheckIn(2)


var https = require('https'); var options = { 'method': 'POST', 'hostname': 'servernamehidden', 'path': '/sites/hkDev/_api/web/getfilebyserverrelativeurl(@fileurl)//CheckIn(comment=@comm,checkintype=@typ)?@fileurl=%5C'%2Fsites%2FhkDev%2Fhemsample%2FhemFolder%2Fhemanttestfile3.txt%5C'&@comm=%5C'some%20comments%20here%20plz%5C'&@typ=0', 'headers': { 'Accept': ' application/json;odata=verbose', 'X-RequestDigest': '0xA1XX411AXXAA0XX0X1101011AX11XX11AXXA1X11X1X114X11011AX410142X01X2131XXXX1AX23101411AX1X1X31XA3X0XX4XX131XX1141X111XX1XX1XX1110X4,03 Apr 2011 14:40:01 -0000' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = ; req.write(postData); req.end();

No comments:

Post a Comment