janhommes / o.js

o.js - client side oData lib.
https://janhommes.github.io/o.js/example/
MIT License
238 stars 57 forks source link

How to use batch in patch requests? #87

Closed sc-starman closed 5 years ago

sc-starman commented 5 years ago

I have tried batch() a couple of patch request but it produces a nonsense error like this:

0:
error: {code: "", message: "The input was not valid.", details: Array(1)}
__proto__: Object
1:
error: {code: "", message: "The input was not valid.", details: Array(1)}
__proto__: Object

I use this syntax to make a request: odata.o('http://localhost:5055/odata/').patch('userNotifications(1)', {state:'1'}).patch('userNotifications(1)', {state:'1'}).batch()

I have also tried this syntax that suggested in with no luck: odata.o('http://localhost:5055/odata/usernotifications/2').patch(data).batch('http://localhost:5055/odata/usernotifications/2').patch(data).save(function () { console.log('luck!') }); Error: o(...).patch(...).batch(...).patch is not a function

However I don't have any problem for a get request using the first one as: odata.o('http://localhost:5055/odata/').get('userNotifications').get('userNotifications').batch()

janhommes commented 5 years ago

So your first attempt should be right:

odata.o('http://localhost:5055/odata/').patch('userNotifications(1)', {state:'1'}).patch('userNotifications(1)', {state:'1'}).batch()

That should work, and the error seems to be a status from your odata server. Can you check what is send in the details of the error message?

btw.: patching two times the same resource might also be not the best idea :thinking:

sc-starman commented 5 years ago

Unfortunately, as I posted before the error was not clear at all: Screenshot (82) However, If I send a single request It would work as it should. --I did also test with two different resources but it doesn't change anything.

janhommes commented 5 years ago

sorry, I cannot help that much here. Can you post the plain Request/Respons?

The test for batching against the odata example implementation works for that case. I am really unable to reproduce such issues, as I cannot verify if it is a backend or frontend issue. If you provide me with an endpoint where you can reproduce it, I might be able to help. But atm I can just suggest debugging your backend to see if there is any more meaningfull error shown.