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!>
https://contoso.sharepoint.com/sites/a-site
<- valid, https://contoso.sharepoint.com/sites/a-site/folder-path
<- invalid${siteUrl}/_api/...
and won't be correct with a folder placed in there. The folder path should be in "folder" prop in fileOptions.
spr.requestDigest
or spr.post
have problem connecting to SP? await spr.requestDigest(baseUrl)
.then(async (digest) => {
const header = {
'X-RequestDigest': digest,
'Accept': 'application/json;odata=verbose',
'Content-Type': 'application/json;odata=verbose',
};
return spr.post(`${baseUrl}${itemsPath}`, {
json: true,
body: item,
headers: header
});
})
.then(res => {
console.log('Successfully inserted in Sharepoint!');
spItems.push(element);
}, err => {
if (err.statusCode === 404) {
console.log('Not found!');
} else {
console.log('error');
}
});