Giter VIP home page Giter VIP logo

Comments (13)

lazharbacha avatar lazharbacha commented on September 26, 2024 1

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.

gitbrent avatar gitbrent commented on September 26, 2024

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?

screen shot 2017-11-28 at 23 32 39

from sprestlib.

Jandos22 avatar Jandos22 commented on September 26, 2024

Hi @gitbrent ,

Looks like no payload is being passed. Btw I use sp-rest-proxy for development (2nd picture).

issue5

issue5_console

from sprestlib.

koltyakov avatar koltyakov commented on September 26, 2024

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

Jandos22 avatar Jandos22 commented on September 26, 2024

Privet @koltyakov,

After running script on Sharepoint I get a different error and again don't see payload being passed to SP.

1

2

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.

koltyakov avatar koltyakov commented on September 26, 2024

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.

Jandos22 avatar Jandos22 commented on September 26, 2024

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

gitbrent avatar gitbrent commented on September 26, 2024

Hi @Wireliner,

SpRestLib does pass the security token/digest value - it's one if the last items under the "Request Headers" section:

screen shot 2017-11-29 at 20 38 31

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.

Jandos22 avatar Jandos22 commented on September 26, 2024

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

gitbrent avatar gitbrent commented on September 26, 2024

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.

gitbrent avatar gitbrent commented on September 26, 2024

Thanks for your help @Wireliner!

from sprestlib.

lazhar0bacha avatar lazhar0bacha commented on September 26, 2024

Good day!

When I try to create an item in a list I get the following error (it is the same errors for Wireliner) :
git1

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.

gitbrent avatar gitbrent commented on September 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.