## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
mctoastus
@mctoastus

Hey!
I just started out using your amazing package.
Now im having a problem:
I wanted to go through your samples, and it worked fine till i wanted to create a list item.

Here is my Code: https://i.imgur.com/bxYWB1g.png

I get the following Error: HTTPError: Response code 400 (Bad Request)
at EventEmitter.<anonymous> (C:\Users\mathe\source\repos\CryptoChat\node_modules\sp-request\node_modules\got\dist\source\as-promise.js:118:31).

Also im really new to nodejs (?and rest?). So if i want for example to read out the number of list items for example. Where can i find the headers i need for that etc?

Im happy for every response!
Sincerly Matheo

Andrew Koltyakov
@koltyakov
KaianFerreira
@KaianFerreira
Hello.
I am working on a project that uploads files to a folder that is on the sharepoint. The only way to login is through a link that I open and enter a password. How do I do this authentication via node-sp-auth?
Obe Lahnkara
Greetings all. I've been trying to setup Sharepoint authentication in Node.js, and despite trying several different methods (node-sp-auth, pnpjs) I'm having all kinds of errors. on the node-sp-auth side, I keep getting an 'invalid argument' error from my type2message response, despite using what i think are the correct credentialoptions. PnP isn't working either, 'cannot read property filter of undefined' and honestly I'm not even sure about the nature of this error. if i'm using Sharepoint On-Prem 2013, where I normally log in automatically with AD, what's the proper library and credential options to use to get the form digest for POST requests?
Andrew Koltyakov
@koltyakov
@Oberothton_twitter, you can node-sp-auth for authentication in on-prem, there are no other alternatives in Node.js, at least I don't know about such. The simplest way of consuming the API without caring too much about headers and digest is PnPjs. With node-sp-auth it can authenticate to on-prem as well. pnp-auth simplifies binding auth fetch client to PnPjs.
As you experience authentication issues while node-sp-auth supports NTLM&NTLM2, that means that your environment configured with different authentication or auth parameters are provided incorrectly. I'd suggest troubleshooting with this helper repo first.
Obe Lahnkara
can pnp not authenticate on-prem on its own? because I've been trying to use it and keep getting some kind of deeply nested json endpoints filter error I don't understand. Meanwhile, I cloned and ran your troubleshooter using the NTLM creds I was before (which should still be the correct domain name, user, password)
=== Error ===
Error: Invalid argument
at Object.decodeType2Message (C:\Users\XXX\Documents\ReactTesting\node-sp-auth-troubleshoot\node_modules\node-ntlm-client\lib\ntlm.js:62:9)
at C:\Users\XXX\Documents\ReactTesting\node-sp-auth-troubleshoot\node_modules\node-sp-auth\lib\src\auth\resolvers\OnpremiseUserCredentials.js:40:35
at async C:\Users\XXX\Documents\ReactTesting\node-sp-auth-troubleshoot\index.js:22:24
Andrew Koltyakov
@koltyakov
What’s the version of Node.js? The latest node-sp-auth update requires at least 10.19.
Are you sure, your environment is NTLM? But not ADFS or something else? Can it be a mixed auth?

can pnp not authenticate on-prem on its own?

Sure thing, no.

Andrew Koltyakov
@koltyakov
Also, what’s the finger print of username/domain? Should be 1) username: john@contoso.com, domain: omitted; 2) username: contoso\john, domain: omitted, 3) username: john, domain: contoso
However, messing up with creds format would end up with incorrect username and password. So it’s something else.
Obe Lahnkara
it should be NTLM, that's what was used on a C# script i saw used to connect to this SP site @koltyakov
and i'm on node 14.4
Obe Lahnkara
ok i got it
did some debugging w troubleshooter and established a connection
now what? do i just copy the private.uat into my credential Options
?
Andrew Koltyakov
@koltyakov
What was the issue?
Obe Lahnkara
incorrect formatting of sharepoint url
i'm loading the urls from an external list in a module and noticed i typed them as http instead of https
edited that in credentialOptions and now i can query the digest perfectly
Andrew Koltyakov
@koltyakov
Cool, happy coding!
Obe Lahnkara
and to you!
Obe Lahnkara
how do i delete a list item using sp-request? setting X-HTTP-Method to DELETE and setting url to _api/web/lists/getByTitle('Holiday')/items({ID}) doesnt seem to work
i'm getting a 200 response but the item doesn't delete
Obe Lahnkara
@koltyakov sorry for ping but ^do you know how to do this?
Andrew Koltyakov
@koltyakov
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), {
'X-RequestDigest': digest,
'X-HTTP-Method': 'DELETE',
'IF-MATCH': '*'
}
});

console.log(res.statusCode, res.statusMessage);

})().catch(console.warn);
Obe Lahnkara
spr.requestDigest(site).then(digest => {
console.log(url);
'X-RequestDigest': digest,
'X-HTTP-Method': 'DELETE',
'IF-MATCH': '*'
};
spr.get(url).then(response => {
let deleteUrl = ${site}/_api/web/lists/getByTitle('Holiday')/items(${response.body.d.results[0].ID});
                    spr.post(deleteUrl, { headers }).then(response => {
console.log(response.statusCode);
})
this doesn't work for me. Strange.
Obe Lahnkara
doubly strange is upon execution i still receive a 200 OK response, which should mean the record is deleted, yet its not?
Andrew Koltyakov
@koltyakov
Are you sure you aren’t deleting something else? ;D
Obe Lahnkara
i log the url after selecting the IDs and they seem to match the ids as seen in sharepoint, but maybe (i'm /very/ new to sharepoint lol)
Obe Lahnkara
it suddenly works now
not sure why exactly haha
Khanis Anthony K
@khanisak

hi guys, im new on sharepoint.
im try to create sharepoint webpart with sharepoint framework.

Can we call microsoft graph api on localhost workbench?

Andrew Koltyakov
@koltyakov
Yes, you can, but got to create and configure AAD App Registration with redirect URI and some other none trivial things. So it's easier to run serve mode and debug a webpart on SharePoint page, so you can just use a default client ID.
mctoastus
@mctoastus
Hi @koltyakov, a month ago i had a question. You told me to add something to the code.
After doing that i get the following error:
Error is: HTTPError: Response code 415 (Unsupported Media Type)
Andrew Koltyakov
@koltyakov
@mctoastus what's the endpoint? The resource should obviously support the requested content type otherwise 415 is expected as the server can't resolve what to return.
mctoastus
@mctoastus
If u mean what i want to access with the word endpoint, im trying to access sharepoint.
Here is my code:
https://i.imgur.com/snN1kyE.png
Andrew Koltyakov
@koltyakov
mctoastus
@mctoastus
Oh my god... hahaha
mctoastus
@mctoastus
Mhm now it gives me a 400 (Bad Request) Error..
Bruno Naibert
@bruno-naibert
Hello, I have a problem when trying to download a folder with images from sharepoint using sppull, what will it be?
Andrew Koltyakov
@koltyakov
Auth connected. Please make sure, that the auth strategy and creds are correct.
Looks that the environment's strategy is not NTLM but something else.
The simplest way to troubleshoot is https://github.com/koltyakov/node-sp-auth-troubleshoot
Bruno Naibert
@bruno-naibert
I'll try that. But as I just want to get the path / URL of the images, without having to download them all, I would like to know if you have any more viable alternative? My initial plan would be to download all files in the same structure as the library and with Node.Js scan the folders and files on my computer to get only the URL / Path.
Andrew Koltyakov
@koltyakov
I'd suggest PnPjs. But you have to have at least some understanding of what is SharePoint REST API.
With REST, obviously, you can request a list/library and get metadata, filter only images, etc.
ankitsaraswat27
@ankitsaraswat27
Hello, I am getting this error
Access to XMLHttpRequest at 'https://waconafd.officeapps.live.com/apc/trans.gif?b320ab775852cec633df8395c6a55814' from origin 'https://abcd.sharepoint.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
2 replies