const { AuthConfig } = require('node-sp-auth-config');
const { create } = require('sp-request');
(async () => {
const { siteUrl, authOptions } = await new AuthConfig().getContext();
const spr = create(authOptions);
const digest = await spr.requestDigest(`${siteUrl}`);
const res = await spr.post(`${siteUrl}/_api/web/lists/getByTitle('MyList')/items(1)`, {
headers: {
'X-RequestDigest': digest,
'X-HTTP-Method': 'DELETE',
'IF-MATCH': '*'
}
});
console.log(res.statusCode, res.statusMessage);
})().catch(console.warn);
${site}/_api/web/lists/getByTitle('Holiday')/items(${response.body.d.results[0].ID})
; spr.post(deleteUrl, { headers }).then(response => {
console.log(response.statusCode);
})
Here you have the script in case you want to test it from chrome: var reqUrl= "https://XXXX.sharepoint.com/_api/web/siteusers/getbyid(170)";
var body={ '__metadata':{ 'type': 'SP.Data.UserInfoItem' }, 'Title':'Active3','EMail': 'xxxx@xxx.es' }
var _payloadOptions = {
method: "POST",
body: undefined,
headers: {
credentials: "include",
Accept: "application/json; odata=verbose",
"Content-Type": "application/json; odata=verbose"
}
};
//Get RequestDigest First
fetch("https://XXXX.sharepoint.com/_api/contextinfo",_payloadOptions).then(r=>r.json())
.then(r=>
{
_payloadOptions.headers["X-RequestDigest"]=r.d.GetContextWebInformation.FormDigestValue
_payloadOptions.headers["IF-MATCH"]="*"
_payloadOptions.body=JSON.stringify(body);
_payloadOptions.method="MERGE";
// Make REST API Call to update list item without increamenting version.
fetch(reqUrl
,_payloadOptions).then(function(r){
console.log(r)
}
).then(r=>console.log(r))
})
Hey @DardoJav,
Please try with auth configurator to avoid incorrect creds payload:
import { AuthConfig as SPAuthConfigurator } from 'node-sp-auth-config';
import { ISPPullOptions, ISPPullContext, Download as IDownload } from 'sppull';
new SPAuthConfigurator().getContext().then((context) => {
const Download: IDownload = require('sppull');
const sppull = Download.sppull;
const context: ISPPullContext = {
siteUrl: context.siteUrl,
...context.authOptions
} as any;
const options: ISPPullOptions = {
spRootFolder: 'Shared%20Documents',
dlRootFolder: './Downloads/Documents'
};
sppull(context, options);
}).catch(console.log);
This works for me:
const { AuthConfig } = require('node-sp-auth-config'); const { create } = require('sp-request'); (async () => { const { siteUrl, authOptions } = await new AuthConfig().getContext(); const spr = create(authOptions); const digest = await spr.requestDigest(`${siteUrl}`); const res = await spr.post(`${siteUrl}/_api/web/lists/getByTitle('MyList')/items(1)`, { headers: { 'X-RequestDigest': digest, 'X-HTTP-Method': 'DELETE', 'IF-MATCH': '*' } }); console.log(res.statusCode, res.statusMessage); })().catch(console.warn);
ok, so I have an issue with this code - and it must be a config setting. If I run this, I get prompted for all my dettails (url, type, username etc)
however, I get a 401
if I browse to the site in chrome, and enter the same username, password I get logged on
what am I missing ? I really would appreciate some help here, my eyes are bleeding from all the googling ;)