Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

Error in list('listname').create({data}) #9

Closed
rachidio opened this issue Jan 5, 2018 · 5 comments
Closed

Error in list('listname').create({data}) #9

rachidio opened this issue Jan 5, 2018 · 5 comments
Assignees
Labels
authentication SharePoint authentication integration integration with other angular, node, webpack, etc. question
Milestone

Comments

@rachidio
Copy link

rachidio commented Jan 5, 2018

Hello,
I am facing the same problem as discussed on issue #5, I am using SpRestLib in a Sharepoint hosted app, into the default.aspx page, when making GET calls no problem, but when I call list('listname').create({data}),
with data as JSON object {name:"test", ...}, I get an error about page validation etc, in devtools I noted that there is no X-RequestDigest nor Payload in the post call.
image

How can I resolve the issue as there is no solution mentioned in the previous discussion #5 ?
Thanks in advance

@gitbrent gitbrent added authentication SharePoint authentication question labels Jan 5, 2018
@gitbrent gitbrent self-assigned this Jan 5, 2018
@gitbrent
Copy link
Owner

gitbrent commented Jan 5, 2018

Hi @ra6hi9,

Good timing - I just finished updating this information in the README this evening. :-)

Check out the requestDigest option in the List Options section.

Providing a value to that option will result in the X-RequestDigest header being populated and sent to SP enabling CRUD operations.

@rachidio
Copy link
Author

rachidio commented Jan 6, 2018

Thanks brent,
This new option is very helpful, but this resolve only a part of the issue, because even if I am making the create operation from a SharePoint .aspx page with $("#__REQUESTDIGEST").val() not empty, I am getting the same error (validation ...)
After I did some debugging I found the source of the issue:

// Detect Node.js
var NODEJS = ( typeof module !== 'undefined' && module.exports );
...
...
if ( NODEJS ) {
objAjaxQuery.headers["Cookie"] = APP_OPTS.nodeCookie;
delete objAjaxQuery.headers["X-RequestDigest"]; //<----
...

The X-RequestDigest header is removed if the code is executed in NODE context, but this code is also executed in Browser context, because NODEJS variable is not undefined, can you correct me if I misunderstood something.

Thanks

@gitbrent
Copy link
Owner

gitbrent commented Jan 8, 2018

Hi @ra6hi9

Yes, Angular and other types of applications may be detected as Node.js apps, so i've created a flag that will you enable to specify browser mode:

NODE Options

sprLib.nodeConfig({ nodeEnabled:false });

That should enable X-RequestDigest to pass as normal.

gitbrent pushed a commit that referenced this issue Jan 8, 2018
gitbrent pushed a commit that referenced this issue Jan 8, 2018
@gitbrent gitbrent added the integration integration with other angular, node, webpack, etc. label Jan 8, 2018
@gitbrent gitbrent added this to the 1.4.0 milestone Jan 9, 2018
@rachidio
Copy link
Author

I think this condition in inverted:

sprLib.nodeConfig({ nodeEnabled:false });
....
if ( NODEJS && !APP_OPTS.nodeEnabled ) {

if nodeEnabled == false -> APP_OPTS.nodeEnabled == false -> NODEJS && !APP_OPTS.nodeEnabled == true

Thank you

@rachidio
Copy link
Author

The inverted condition issue is resolved in the last commits 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
authentication SharePoint authentication integration integration with other angular, node, webpack, etc. question
Projects
None yet
Development

No branches or pull requests

2 participants