Comments (13)
Hi @gitbrent
Thank you so much for your help, it works for me 👍
and this is my code maybe it will be helpful for someone else.
const user = {
"FirstName1": userData[0].Firstname,
"Lastname": userData[0].Lastname,
"Birthdate": userData[0].Birthdate,
"Address": userData[0].Address,
"Zip": userData[0].ZIP,
"City": userData[0].City,
"Country": userData[0].Country,
"Mail": userData[0].Mail,
"Phone": userData[0].Phone,
"Position": userData[0].Position,
"Location1": userData[0].Location,
"Title": userData[0].Salutation,
"AcceptTerm": userData[0].AcceptTerm,
"Comments1": userData[0].Comments,
};
sprLib.nodeConfig({ nodeEnabled: false });
sprLib.rest({ url: '_api/contextinfo', type: 'POST' })
.then(arr => {
let strReqDig = arr[0].GetContextWebInformation.FormDigestValue;
return sprLib.list({ name: 'User', requestDigest: strReqDig }).create(user);
})
.then(obj => {
console.log('Item created!');
});
from sprestlib.
Hi @Wireliner,
Thanks for opening an issue.
It appears the JSON body
object isn't being encoded correctly... Can you check the dev tools (F12) Network tab to see what's being passed to SP?
from sprestlib.
Hi @gitbrent ,
Looks like no payload is being passed. Btw I use sp-rest-proxy for development (2nd picture).
from sprestlib.
@Wireliner,
Can you check the same script/payload on SharePoint page and with sp-rest-proxy
?
Is there a difference? Feel free to post related issues to proxy's project if there is a different behavior on SP page and Local page talking to the proxy.
from sprestlib.
Privet @koltyakov,
After running script on Sharepoint I get a different error and again don't see payload being passed to SP.
It might be worth to mention that I ran script not from SP *.aspx page, but from custom angular5 html (example, sites/ngapp/dev/index.html#/app). Maybe now it is a RequestDigest value problem?
from sprestlib.
Does SpRestLib
wrap digests?
@Wireliner please try refreshing the page. The error is common when you navigate back and forth in browsers history and then execute POST with the wrong digest.
from sprestlib.
@koltyakov refreshed the page, same error.
not sure if SpRestLib wraps digests ... I am quite new to SP, but my custom POST call to add item using REST api works fine, just wanted to take advantage of simplicity of SpRestLib.
from sprestlib.
Hi @Wireliner,
SpRestLib does pass the security token/digest value - it's one if the last items under the "Request Headers" section:
However, this depends upon the SP page having the __REQUESTDIGEST
form element. Normally, you'd embed an app in an .aspx page within a Webpart, where this token will always be present. Check for the token via $('#__REQUESTDIGEST').length
etc.
Your second post's screencap shows the URL being used as:
http://localhost:4200/_api/list/getbytitle[...]
So the issue there may be due to an incorrect value. Perhaps, use the baseUrl variable:
sprLib.list({ name:'Employees', baseUrl:'/sites/wireline' })
from sprestlib.
@gitbrent thanks for clear explanation. I see now that the problem maybe is that I use my custom ".html" page and not ".aspx" page, so digest value could not be retrieved in this case. What I do is get FDV by calling to "_api/contextinfo".
from sprestlib.
Hi @Wireliner,
Thanks for the follow-up, that's really helpful.
The library currently only looks for the FDV via the __REQUESTDIGEST
form element, but that leaves people who use the _api/contextinfo
without an avenue to auth via SpRestLib...
I'll create a new option to pass the FDV value in the next release.
from sprestlib.
Thanks for your help @Wireliner!
from sprestlib.
Good day!
When I try to create an item in a list I get the following error (it is the same errors for Wireliner) :
and there is my code:
sprLib.list({ name: 'UserData', baseUrl: '/sites/SiteDev/SharePoint-Hosted-AddIn-Alight'})
.create({
__metadata: { type: "SP.Data.UserDataListItem" },
"Firstname": userData[0].Firstname,
"Lastname": userData[0].Lastname,
"Location": userData[0].Location,
"Address": userData[0].Address,
"City": userData[0].City,
"Country": userData[0].Country,
"Zip": userData[0].Zip,
"Phone": userData[0].Phone,
"Birthdate": userData[0].Birthdate,
"Comments": userData[0].Comments,
"Mail": userData[0].Mail,
"Position": userData[0].Position,
})
PS: for my example I used "Office UI Fabric React"
Regards,
from sprestlib.
Hi @lazhar0bacha,
Since you're also encountering authentication issues, i created a whole new section to cover this in the README. Hopefully, this will really help when errors like this come up.
Check out the SharePoint Authentication Notes section and let me know if that helps...
from sprestlib.
Related Issues (20)
- sprLib.site().groups() fails on SP2013 HOT 3
- Demo doesn't work from sub-folder off sitepages HOT 1
- SP Rest API support for adding Groups HOT 2
- sprLib.list().cols() alignment with sprLib.list().items() returned column names HOT 4
- New issue with Response Header... HOT 1
- Incorrect example in documentation on method .recycle() file HOT 1
- Incorrect request parameter when using only one queryNext option HOT 2
- Batch Requests Support HOT 2
- SP.Folder does not return data related to current site
- how at queryfilter do (and) Condition filter ? HOT 1
- sprLib.folder().add() requires requestDigest / security token HOT 1
- $expand available? HOT 2
- sprLib.file(somefile).checkout is not a function
- cols() error on SP2016
- file upload cannot set overwrite to false
- Error when updating item using JSON.stringify
- Site Collection/Subsite sprLib.site(siteUrl).create()
- Example fail to upload on SP 2019
- Column Modified by cannot be loaded (400) The query to field 'Editor' is not valid.
- SpRestLib queryFilter
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sprestlib.