Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
    and yeah, you can do a lot with CEWP still

    @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:Text xml:lang="en-US">Authentication Failure</S:Text>
    <psf:error xmlns:psf="http://schemas.microsoft.com/Passport/SoapServices/SOAPFault">
    <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>
    at OnlineUserCredentials.postToken (C:\Users\MEDCPham\Documents\CloneServer\node_modules\node-sp-auth\lib\s
    at C:\Users\MEDCPham\Documents\CloneServer\node_modules\node-sp-auth\lib\src\auth\resolvers\OnlineUserCrede
    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, {

         var headers = options.headers;  
        headers['Accept'] = "application/json;odata=verbose";  
         url: url,   
             headers: headers,  
           encoding: null
            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

    sorry im just some random dude but on this link it says you need a domain property. I dont know anything about what the domain property is supposed to be
    username: 'administrator',
    password: '[password]',
    domain: 'sp'
    you only have username and password
    all you are doing is download a excel sheet from a document library?
    why not just link to the sheet and SP should download it automatically to the computer
    the other thing is that the error message says that MFA is required
    also, you dont have the requestprom() function defined in that code you linked, but the API method in that example is request.get()
    also, try putting a catch() inbetween the two .then()s just saying .catch(error => console.log(error)) and also put that after the last .then() as well
    here is some thread i found
    Hi there, is anyone available?
    Hello, hope everybody doing great. Maybe this is a simple error for someone but I'm not really sure why I'm getting a 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');
    }, (err) => {
    Andrew Koltyakov

    @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?

    @koltyakov I have updated my url and the error is the same. Forgive my noobness as this is my first time to work with NodeJS and SharePoint, but how do I now if it's NTLM auth provider? One of my teammate just share me a username, password and the url like https://company.com/sites/test.
    Andrew Koltyakov
    When you login manually, are you entering login password in a basic popup dialog, or you're navigated to a login page?
    Is in On-Prem of SharePoint Online?
    Generally you just know what auth strategy to use based on what is configured. It can be different options (https://github.com/s-KaiNet/node-sp-auth/wiki).
    @koltyakov Ah yes, when I visit 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.
    Andrew Koltyakov

    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:

    • FBA
    • ADFS

    The page there you were redirected, what does it contain in the URL? E.g. is there /adfs/ls in the url?

    It's likely ADFS, so this article https://github.com/s-KaiNet/node-sp-auth/wiki/ADFS-user-credentials-authentication
    for ADFS, you need not only username and password but relyingParty and adfsUrl
    Andrew Koltyakov
    as a hint - adfsUrl is where you're redirected when logging in, relyingParty can be found as a parameter in the url
    @koltyakov Ohh yeah! you are right when I enter the username and click the Next button my URL contains /adfs/ls?client-request-id=42.... and that's the only time that I can enter my password.
    Andrew Koltyakov
    wait a sec, entering username then next? adfs page is usually contain both username/pass on the same form and redirected to right away
    the next step is a common way for AAD when before resolving a username it's not known how to authenticate
    are you sure it's not SPO?
    anyways node-sp-auth-troubleshoot and trying different options is for the rescue
    Ralf Brennscheidt
    Is SP-Online supported with MFA ? Didn't found anything in the wiki/docs related to MFA
    Andrew Koltyakov
    With MFA, these node-sp-auth strategies can be used:
    Ralf Brennscheidt
    Craig The BabelFish
    Hi all, newbie here. I'm trying to use spsave for NodeJS but running into some issues. I've tested spauth on its own and it's working (response includes a cookie), but running spsave with my URL is giving me GotError: Unexpected token < in JSON at position 2 in <full URL here>. This is with SharePoint online in our domain. I've tried every form of the URL I can think of (https://<company>.sharepoint.com/sites/<team folder>, https://<company>.sharepoint.com/:f:/s/<team folder> etc) and still no luck
    Would greatly appreciate any pointers! Thanks
    Craig The BabelFish
    Using https://<company>.sharepoint.com/sites/<team folder>, I'm getting:
    [18:17:52] spsave: Error occured:
    [18:17:52] spsave: Response code 403 (Forbidden)
    [18:17:52] spsave: {"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access denied. You do not have permission to perform this action or access this resource."}}}
    But I am set to "Owner" for group membership in SharePoint
    My NodeJS code:
    var coreOptions = {
    siteUrl: 'https://<company>.sharepoint.com/sites/<team folder>/',
    var creds = {
    username: '<username>',
    password: '<password>',
    // online: true
    var fileOptions = {
        folder: 'Test',
        fileName: 'file.txt',
        fileContent: 'hello world'
    spsave(coreOptions, creds, fileOptions)
    Andrew Koltyakov

    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.

    Craig The BabelFish
    Hi @koltyakov, thank you for the suggestions. I will check with the SP admin if custom scripts are disabled

    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!>

    If I put the siteUrl as 'https://<company>.sharepoint.com/' with folder 'sites/<team folder>/Test' spsave apparently works, and says file.txt successfully uploaded to that URL. But the file is not actually there
    Andrew Koltyakov
    An example of site url is https://contoso.sharepoint.com/sites/a-site <- valid, https://contoso.sharepoint.com/sites/a-site/folder-path <- invalid
    The API calls are constructed as ${siteUrl}/_api/... and won't be correct with a folder placed in there. The folder path should be in "folder" prop in fileOptions.
    Craig The BabelFish
    Thanks again. With that form of the URL and folder set, I'm getting the 403 forbidden. Looks like it might be the disabled custom scripts
    Craig The BabelFish
    So it turns out that custom scripts was already enabled, and my siteUrl was correct. But for the folder I had to prefix it with Shared%20Documents/<folder name>, since my new folder is under Documents. Glad to have this resolved after a day of attempts, and thanks again @koltyakov
    Can you suggest what is the best way to handle a retry strategy if ever the 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!');
            }, err => {
                if (err.statusCode === 404) {
                    console.log('Not found!');
                } else {
    Marten Meijboom
    Hi, I am creating an excel file using excel4node, which returns a node buffer. I then want to upload this to SharePoint. When I do this the Excel file in SharePoint is corrupted.
    This is my code:
    Oh... uploaded the images first
    I was wondering if you have any experience with such a situation, and, if there is a way for me to see if this is a mistake with my use of excel4node or spsave
    Marten Meijboom
    Managed to figure out that the created Excel file is not corrupt before uploading to Sharepoint