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();

Wednesday, March 8, 2017

Create database and content using psql





This post is related to https://hemantrohtak.blogspot.com/2016/03/is-entity-framework-best-performing.html


Sunday, February 26, 2017

Start/Stop/Get details for Windows Services

If you are busy with multiple assignments and cater needs from multiple projects, or may be own a laptop with very little resources, you may want to manipulate windows services active on your laptop by Windows PowerShell.
For example, you may keep handy a .csv targeting one assignment, when you start working on that assignment simply stop other bulky windows services and activate the one you are interested in.

Some helpful commands:


#Get-Service | select-object  status  -unique
#Get-Service | where {$_.status -eq "Running"} 

# get all windows services running:
Get-Service | select Name, CanPauseAndContinue, CanShutdown, CanStop, DisplayName, MachineName, ServiceName, ServiceHandle, Status, ServiceType, StartType, Site, Container, @{Name=’RequiredServices’;Expression={[string]::join(“;”, ($_.RequiredServices.Name))}} ,  @{Name=’DependentServices’;Expression={[string]::join(“;”, ($_.DependentServices.Name))}} ,    @{Name=’ServicesDependedOn’;Expression={[string]::join(“;”, ($_.ServicesDependedOn.Name))}} | Export-Csv c:\gm\servs.csv;

#After analysis of output say, you want to start 3 of them and stop 2, but leave one untouched still be in the csv, create a csv something like:
#(consider the dependencies listed in output above to decide order)
#"Name","Start","Stop"
#"MSSQL$HK2012SQL","TRUE","FALSE"
#"SQLAgent$HK2012SQL","TRUE","FALSE"
#"postgresql-x64-9.5","TRUE","FALSE"
#"wuauserv","FALSE","TRUE"
#"wlidsvc","FALSE","TRUE"
#"RpcSs","FALSE","FALSE"

import-csv "C:\gm\input.csv" | foreach-object { write-host $_.Name; if([bool]::Parse($_.Start)){ Start-Service $_.Name}; if([bool]::Parse($_.Stop)){ Stop-Service $_.Name};}

sample commands at :  bitbucket.org/hemantup/orm/src/HEAD/Scripts/services.txt

But if you are more into security and want control over what is happening over your laptop above mentioned might not be sufficient.
You might need to to deep dive into processes like :

Get-Process | Export-csv "c:\gm\pr.csv"

Friday, February 17, 2017

LLBLGenPro Lite with PostgreSQL and .Net

In this example I used:

LLBLGenPro Lite Version 5.1 (5.1.2) RTM - LITE  Build Date 24-Jan-2017, Licensee: LITE user
Npgsql -Version 3.1.10
CsvHelper -Version 2.16.3
log4net -Version 2.0.7
Visual Studio 2012 with Package Manager Console Host Version 2.8.60318.667

Few tips:

1. Generic part of adapter source code and DB Specific part ( Projects LLBLGenProLite51DBSpecific & LLBLGenProLite51Generic) were created following "LLBLGen Pro Runtime Framework v5.1 Documentation" documentation at llblgen.com/Documentation/5.1/LLBLGen%20Pro%20RTF/index.htm
bitbucket.org/hemantup/orm/src/HEAD/LLBLGenProLite51/LLBLGenProLite51.llblgenproj is the saved project of LLBLGenPro.exe which may be used to regenerate the classes later, if need be.
llblgen.com/Documentation/5.1/LLBLGen%20Pro%20RTF/Tutorials%20And%20Examples/tutorial_createproject.htm

2. The only tweak I had to do to generate the source code (on the top the instructions as mentioned in online help guide "LLBLGen Pro Runtime Framework v5.1 Documentation):
a) Put Npgsql.dll in C:\Program Files (x86)\Solutions Design\LLBLGen Pro v5.1\
b) Some of you might also have to put DbProviderFactories entry under LLBLGenPro_x86.exe.config.
Otherwise you may get error:
Exception details:
=====================
Message: Failed to find or load the registered .Net Framework Data Provider.
Source: System.Data
Stack trace: 
   at System.Data.Common.DbProviderFactories.GetFactory(DataRow providerRow)
   at SD.LLBLGen.Pro.DBDriverCore.DBDriverBase.GetDbProviderFactory()
   at SD.LLBLGen.Pro.DBDriverCore.ConnectionDataBase.get_FactoryName()
   at SD.LLBLGen.Pro.Gui.Controls.WizardPages.MetaDataRetrievalWizard_Step_ConnectionData.<LoadDriverAndConnectionControl>b__16_1()
   at SD.LLBLGen.Pro.Gui.Classes.ApplicationIdleDispatcher.PerformWork()
   at SD.LLBLGen.Pro.Gui.Classes.ApplicationIdleDispatcherSingleton.Application_Idle(Object sender, EventArgs e)
   at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
   at SD.LLBLGen.Pro.Gui.Classes.GuiController.PerformAddMetaDataFromDatabaseAction()
   at SD.LLBLGen.Pro.Gui.Controls.ProjectExplorer._mainBarManager_ItemClick(Object sender, ItemClickEventArgs e)
   at DevExpress.XtraBars.BarItem.OnClick(BarItemLink link)
   at DevExpress.XtraBars.BarButtonItem.OnClick(BarItemLink link)
   at DevExpress.XtraBars.BarItemLink.OnLinkClick()
   at DevExpress.XtraBars.BarButtonItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
   at DevExpress.XtraBars.ViewInfo.BarSelectionInfo.UnPressLink(BarItemLink link)
   at DevExpress.XtraBars.Controls.CustomLinksControl.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at DevExpress.XtraBars.Controls.CustomControl.WndProc(Message& msg)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Inner exception: <null>

3. In the Console project I created, I had to make DbProviderFactories entry in app.config in addition to installing Npgsql.

For other details, you may refer to comments in bitbucket.org/hemantup/orm/src/HEAD/LLBLGenProLite51/LLBLGenProLite51Console/Program.cs in sample code.



Working sample code is available at bitbucket.org/hemantup/orm/src/HEAD/LLBLGenProLite51/






This post is related to https://hemantrohtak.blogspot.com/2016/03/is-entity-framework-best-performing.html



Thursday, February 16, 2017

Symbiotic_Data_Provider_PostgreSql_x64 with PostgreSQL and .Net

In this example I used:
Symbiotic_x64 -Version 4.0.4.1
Symbiotic_Data_Provider_PostgreSql_x64 -Version 2.0.0
Npgsql -Version 3.1.10
CsvHelper -Version 2.16.3
log4net -Version 2.0.7
test_table.cs using Symbiotic Code Generator

Working sample code is available at bitbucket.org/hemantup/orm/src/HEAD/SymbioticDataProviderPostgreSql2/





Wednesday, February 15, 2017

Uni.ORM with PostgreSQL and .Net

Uni.ORM with PostgreSQL and .Net

In this example I used:

Npgsql -Version 3.1.10

CsvHelper -Version 2.16.3

log4net -Version 2.0.7

Uni.Extensions -Version 1.1.8 (  if you use Uni.Extensions 1.1.9, along with Uni.ORM 1.4.4, it will give error Field not found: 'Uni.Extensions.UniExtensions.stringType'.)

Uni.ORM -Version 1.4.4

Working sample code is available at

bitbucket.org/hemantup/orm/src/HEAD/UniORM144/
bitbucket.org/hemantup/orm/src/HEAD/Scripts/apps/10/



Probably you need to be careful about the active sessions with this ORM:







I got below mentioned error, if used more than 20 execution cycles with above said custom utility


Npgsql.NpgsqlException was unhandled
  HResult=-2147467259
  Message=The connection pool has been exhausted, either raise MaxPoolSize (currently 100) or Timeout (currently 15 seconds)
  Source=Npgsql
  ErrorCode=-2147467259
  StackTrace:
       at Npgsql.ConnectorPool.WaitForTask(Task task, NpgsqlTimeout timeout)
       at Npgsql.ConnectorPool.Allocate(NpgsqlConnection conn, NpgsqlTimeout timeout)
       at Npgsql.NpgsqlConnection.OpenInternal()
       at Npgsql.NpgsqlConnection.Open()
       at Uni.Orm.UniOrm.NewConnection()
       at Uni.Orm.UniOrm.ExecuteScalar(CommandType commandType, String schema, String package, String commandText, Options options, Object[] args)
       at Uni.Orm.UniOrm.ExecuteScalar[T](CommandType commandType, String schema, String package, String commandText, Options options, Object[] args)
       at Uni.Orm.UniOrm.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)
       at CallSite.Target(Closure , CallSite , Object , String , String , String , Options , Object[] )
       at Uni.Orm.UniOrm.Count(String schema, String table, String where, Options options, Object[] args)
       at UniORM144.UniORM144Test.Main(String[] args) in c:\891\orm\orm\UniORM144\Program.cs:line 114
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:






This post is related to https://hemantrohtak.blogspot.com/2016/03/is-entity-framework-best-performing.html

Tuesday, February 14, 2017

i-nercya EntityLite with PostgreSQL and .Net

In this example I used:
Npgsql -Version 3.1.10
EntityLite -Version 1.12.1
DataLayer.cs  from hemantrohtak.blogspot.com/2017/02/generate-datalayer-for-i-nercya.html
CsvHelper -Version 2.16.3
log4net -Version 2.0.7

Working sample code is available at bitbucket.org/hemantup/orm/src/HEAD/InercyaEntityLite1121/





This is related to https://hemantrohtak.blogspot.com/2016/03/is-entity-framework-best-performing.html