Code Monkey home page Code Monkey logo

Comments (6)

koltyakov avatar koltyakov commented on May 27, 2024

Hi Bruce,

You probably have an error in the item data type. It likely to be "SP.Data.DemandesListItem".
Also, I've found out that POST request body was not treated in proxy, has applied some changes.
Could you please check if ver. 1.1.10 will work for you?

P.S. POST requests won't work the same as on a SharePoint page. E.g. X-RequestDigest is requested automatically by the lib, but on a real SharePoint page should be provided explicitly within ajax request. So it's better to check such request setup in the real environment.

from sp-rest-proxy.

brucelane avatar brucelane commented on May 27, 2024

Hi, no better with { '__metadata': { 'type': 'SP.Data.DemandesListItem' }, 'Title': 'Test' } in 1.1.10
I get a 404 in the console:

jquery.min.js:4 POST http://localhost:8080/%7B%20'__metadata':%20%7B%20'type':%20'SP.Data.DemandesListItem'%20%7D,%20'Title':%20'Test'%20%7D 404 (Not Found)

Response error:

{
  "readyState": 4,
  "responseText": "Cannot POST /%7B%20'__metadata':%20%7B%20'type':%20'SP.Data.DemandesListItem'%20%7D,%20'Title':%20'Test'%20%7D\n",
  "status": 404,
  "statusText": "Not Found"
}

Now I know it's normal I have to run it on the sharepoint server!

from sp-rest-proxy.

brucelane avatar brucelane commented on May 27, 2024

When I run it on the sharepoint server I get:

Uncaught SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at HTMLButtonElement.<anonymous> (script.js:59)
    at HTMLButtonElement.dispatch (jquery.min.js:3)
    at HTMLButtonElement.r.handle (jquery.min.js:3)

from sp-rest-proxy.

koltyakov avatar koltyakov commented on May 27, 2024

Bruce,

It looks like you are doing something wrong withing your request.
Data object shouldn't go to the URL string. It should be a list items endpoint provided as an URL.

It works for me in embedded client page:

and with a $.ajax call:

$.ajax({
   url: '/_api/web/getList(\'/sites/dev01/Lists/Custom02\')/items', 
         // endpoint should be correct one with the exception of the web url
         // which is injected with the proxy automatically from the context setup
   method: 'POST',
   contentType: "application/json;odata=verbose",
   data: JSON.stringify({
       "__metadata": { "type": "SP.Data.Custom02ListItem" },
       "Title": "Created from proxy"
   }),
   success: function(d) { console.log(d); }, 
   error: function(e) { console.log(e.responseText); }
});

and on SharePoint page too:

As you can see, request on the SP page should have some additional setup to include digest, etc., which can be omitted during querying too the proxy.

from sp-rest-proxy.

brucelane avatar brucelane commented on May 27, 2024

yes it works!!!!
thank you so much!
now I have to find the way to call it from my ReactJS app

from sp-rest-proxy.

koltyakov avatar koltyakov commented on May 27, 2024

Always welcome, cheers!

from sp-rest-proxy.

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.