koltyakov / sppull

📎 Download files from SharePoint document libraries using Node.js without hassles
MIT License
46 stars 16 forks source link

Cannot read property 'firstChild' of undefined #32

Closed brunotdantas closed 5 years ago

brunotdantas commented 5 years ago

First of all, Thanks a Lot @koltyakov for building this library :).

About an error found when trying to download a single file from a folder.

Below the cmd history and error log:

c:\downloadSharepoint>node Download.js Downloading files: 1 out of 1 Error in operations.downloadFile: Cannot read property 'firstChild' of undefined Core error has happened TypeError: Cannot read property 'firstChild' of undefined at config_1.request.post.then.xmlResponse (c:\downloadSharepoint\node_modules\node-sp-auth\lib\src\utils\AdfsHelper.js:29:67) at tryCatcher (c:\downloadSharepoint\node_modules\bluebird\js\release\util.js:16:23) at Promise._settlePromiseFromHandler (c:\downloadSharepoint\node_modules\bluebird\js\release\promise.js:517:31) at Promise._settlePromise (c:\downloadSharepoint\node_modules\bluebird\js\release\promise.js:574:18) at Promise._settlePromise0 (c:\downloadSharepoint\node_modules\bluebird\js\release\promise.js:619:10) at Promise._settlePromises (c:\downloadSharepoint\node_modules\bluebird\js\release\promise.js:699:18) at _drainQueueStep (c:\downloadSharepoint\node_modules\bluebird\js\release\async.js:138:12) at _drainQueue (c:\downloadSharepoint\node_modules\bluebird\js\release\async.js:131:9) at Async._drainQueues (c:\downloadSharepoint\node_modules\bluebird\js\release\async.js:147:5) at Immediate.Async.drainQueues [as _onImmediate] (c:\downloadSharepoint\node_modules\bluebird\js\release\async.js:17:14) at runCallback (timers.js:705:18) at tryOnImmediate (timers.js:676:5) at processImmediate (timers.js:658:5)

How the code looks like:

var sppull = require("sppull").sppull;

var context = {
  siteUrl: "https://COMPANY.sharepoint.com/sites/IntegraoLinxxProtheus/",
  creds: {
    username: "email@companySite",
    password: "myPassword"
  }
};

var options = {
    spRootFolder: "Shared%20Documents/Produtos_hero/",
    dlRootFolder: "./Downloads/Contracts",
    strictObjects: [
        "/lista_produtos.csv" // Only responsive.master file from /subsite/_catalogs/masterpage
    ]
};

/*
 * All files will be downloaded from http://contoso.sharepoint.com/subsite/Shared%20Documents/Contracts folder
 * to __dirname + /Downloads/Contracts folder.
 * Folders structure will remain original as it is in SharePoint's target folder.
*/
sppull(context, options)
  .then(function(downloadResults) {
    console.log("Files are downloaded");
    console.log("For more, please check the results", JSON.stringify(downloadResults));
  })
  .catch(function(err) {
    console.log("Core error has happened", err);
  });
koltyakov commented 5 years ago

Hi @brunotdantas,

Thanks for using the library!

From a first glance it looks like authentication error. Can you check auth parameters?

This utility project can help troubleshooting auth.

brunotdantas commented 5 years ago

Thanks for the reply @koltyakov

Is important to mention that the auth mode selected was "SAML", should I use another one? Sorry for the lack of knowledge about sharepoit :/

I did as suggested but could see the same problem, please see below the results:

> node ./index.js "--env" "uat"

? SharePoint URL https://COMPANY.sharepoint.com/sites/IntegraoLinxxProtheus/Shared Documents/Produtos_hero/lista_pro
dutos.csv
? Authentication strategy User credentials (SAML)
? User name myEmail
? Password [hidden]
Connecting to site: https://COMPANY.sharepoint.com/sites/IntegraoLinxxProtheus/Shared Documents/Produtos_hero/lista_produtos.csv

=== Error ===
 TypeError: Cannot read property 'firstChild' of undefined
    at config_1.request.post.then.xmlResponse (c:\Temp\tstauth\node-sp-auth-troubleshoot\node_modules\node-sp-auth\lib\src\utils\AdfsHelper.js:29:67)
    at tryCatcher (c:\Temp\tstauth\node-sp-auth-troubleshoot\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (c:\Temp\tstauth\node-sp-auth-troubleshoot\node_modules\bluebird\js\release\promise.js:512:31)
    at Promise._settlePromise (c:\Temp\tstauth\node-sp-auth-troubleshoot\node_modules\bluebird\js\release\promise.js:569:18)
    at Promise._settlePromise0 (c:\Temp\tstauth\node-sp-auth-troubleshoot\node_modules\bluebird\js\release\promise.js:614:10)
    at Promise._settlePromises (c:\Temp\tstauth\node-sp-auth-troubleshoot\node_modules\bluebird\js\release\promise.js:694:18)
    at _drainQueueStep (c:\Temp\tstauth\node-sp-auth-troubleshoot\node_modules\bluebird\js\release\async.js:138:12)
    at _drainQueue (c:\Temp\tstauth\node-sp-auth-troubleshoot\node_modules\bluebird\js\release\async.js:131:9)
    at Async._drainQueues (c:\Temp\tstauth\node-sp-auth-troubleshoot\node_modules\bluebird\js\release\async.js:147:5)
    at Immediate.Async.drainQueues [as _onImmediate] (c:\Temp\tstauth\node-sp-auth-troubleshoot\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)

c:\Temp\tstauth\node-sp-auth-troubleshoot>
koltyakov commented 5 years ago

Away from a computer at the moment. Will take a look, what it might be. However, have no SPO environment configured with ADFS to check. As a workaround, can suggest trying On-Demand or Add-In Only auth.

brunotdantas commented 5 years ago

Thanks for the support @koltyakov but I was not able to test the way you suggested. I managed to create another solution for this but thanks a lot for the attention given. I'll close the ticket.