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 ;)
User credentials (NTLM)
btw
@koltyakov I got this error. My project wants to download the excel file and read it, but at some point it does not work and the account is error , This excel file I was shared by a member of the company, please help me :
(node:20972) UnhandledPromiseRejectionWarning: Error: <S:Fault>
<S:Code>
<S:Value>S:Sender</S:Value>
<S:Subcode>
<S:Value>wst:FailedAuthentication</S:Value>
</S:Subcode>
</S:Code>
<S:Reason>
<S:Text xml:lang="en-US">Authentication Failure</S:Text>
</S:Reason>
<S:Detail>
<psf:error xmlns:psf="http://schemas.microsoft.com/Passport/SoapServices/SOAPFault">
<psf:value>0x800434D4</psf:value>
<psf:internalerror>
<psf:code>0x800434D4</psf:code>
<psf:text>AADSTS50076: Due to a configuration change made by your administrator, or because you moved t
o a new location, you must use multi-factor authentication to access ''.</psf:text>
</psf:internalerror>
</psf:error>
</S:Detail>
</S:Fault>
at OnlineUserCredentials.postToken (C:\Users\MEDCPham\Documents\CloneServer\node_modules\node-sp-auth\lib\s
rc\auth\resolvers\OnlineUserCredentials.js:148:19)
at C:\Users\MEDCPham\Documents\CloneServer\node_modules\node-sp-auth\lib\src\auth\resolvers\OnlineUserCrede
ntials.js:48:25
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use node --trace-warnings ...
to show where the warning was created)
(node:20972) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by thr
owing inside of an async function without a catch block, or by rejecting a promise which was not handled with .
catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections
=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:20972) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise
rejections that are not handled will terminate the Node.js process with a non-zero exit code.
My Code :
function getExcelData() {
spauth.getAuth(url, {
username:username,
password:password
})
.then(function(options){
var headers = options.headers;
headers['Accept'] = "application/json;odata=verbose";
requestprom.get({
url: url,
headers: headers,
encoding: null
}).then(function(listresponse){
fs.writeFile('./public/excel.xlsx', listresponse , 'binary', function(err){
if (err) console.log(err)
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
console.log('File saved.')
// function logic
Invalid parameter
error every time I execute the below code. Can someone help me pin point what I missed here? const url = 'https://company.com/sites/test/Lists/Cleanup';
spauth.getAuth(url, {
username: `domain\\my_user_name`,
password: `my_password`
}).then((value) => {
console.log('Connected to Sharepoint');
console.log(value);
}, (err) => {
console.log(err);
});
@klaydze your site url leads to a list but not SPWeb. Can you try https://company.com/sites/test instead of https://company.com/sites/test/Lists/Cleanup.
Are you also sure that NTLM auth provider is used?
username
, password
and the url
like https://company.com/sites/test
.
https://company.com/sites/test
then it will redirect me to a login page where I can input the username
and password
provided. And also, when I'm successfully logged in, when I hit https://company.com/sites/test/_api/lists
I will return some data in xml. BTW, this is On-Prem
also.
for troubleshooting can suggest this https://github.com/koltyakov/node-sp-auth-troubleshoot
you could try different options quickly and see if any works
for on-prem could be:
The page there you were redirected, what does it contain in the URL? E.g. is there /adfs/ls in the url?
var fileOptions = {
folder: 'Test',
fileName: 'file.txt',
fileContent: 'hello world'
};
spsave(coreOptions, creds, fileOptions)
.then(function(){
console.log('saved');
})
.catch(function(err){
console.log(err);
});
Hi @Babelfish112_twitter,
No permissions usually means "no permissions".
In SPO and when you know you have permissions, e.g. is admin, it's also can be a result of disabled custom scripts.
This is a good article on the topic how to enable custom scripts: https://www.koskila.net/how-to-enable-custom-scripts-for-a-sharepoint-online-site-collection/
Or using M365Cli: spo site classic set --url https://<company>.sharepoint.com/sites/<site> --noScriptSite false
Another thing which might be is than you're providing siteUrl with a wrong path not to the SPWeb but folder.
As for the URL, I am a bit confused what I am meant to use.
In SP, I am browsing the folder and the URL in the browser is https://<company>.sharepoint.com/sites/<team folder>/Shared%20Documents/Forms/AllItems.aspx?newTargetListUrl=<LONG HTML-formatted STRING!>