PATCHing a Document using Domino Data Service

Talk about frustrating – in a week full of slow progress and CORS cross domain hell I found this little annoyance after hours of staring and curing – once again the power of trial and error triumphs over my stupidity again.

The problem

I have a Domino Data Service running on the server and I want to update a document

This is the imaginary URL

returning the imaginary data just fine


and I am trying up to update it using a simple AJAX call

  data : {'marky':'newfields'},
  type: 'PATCH',	
  contentType: "application/json", 

Unfortunately I get this big old ugly error….
“text”:”Bad Request”,
“message”:”Error while parsing the JSON content”,
“data”:” Error while parsing the JSON content\r\n\tat\r\n\tat\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(\r\n\tat java.lang.reflect.Method.invoke(\r\n\tat org.apache.wink.server.internal.handlers.InvokeMethodHandler.handleRequest(\r\n\tat

bunch – o – useless Java Stack Trace which never helped anyone…….\r\n\tat\r\nCaused by: Error when parsing JSON stream\r\n\tat\r\n\tat\r\n\t… 65 more\r\nCaused by: Encountered \” \”approved \”\” at line 1, column 1.\r\nWas expecting one of:\r\n \”false\” …\r\n \”null\” …\r\n \”true\” …\r\n <INTEGER_LITERAL> …\r\n <FLOATING_POINT_LITERAL> …\r\n <STRING_LITERAL> …\r\n \”{\” …\r\n \”[\” …\r\n \”(\” …\r\n \r\n\tat\r\n\tat\r\n\tat\r\n\tat\r\n\t… 66 more\r\n”

The solution

So I googled around and I found that the error is caused because the is expecting a string as input – once I found that the solution was simple – send a string and not an object…

  data : '{"marky":"newfields"}', // Notice this is now a string not an object
  type: 'PATCH',	
  contentType: "application/json", 

PATCHing of a document makes a lot of sense for many reasons – mostly because of reduction in bandwidth – the example code works nicely – but you have to update the web site document to allow the PATCH method.

Be aware that using code like this you are also exposing all your data to having any old fool like me breaking your field based workflow and filling your documents full of crap data if they so chose to.

My suggestion would be to use your own REST service written with your own protections in it 🙂

Once again my stupidity is boundless and as I already discovered on multiple occasions,  JSON is a string and not an object.




10 thoughts on “PATCHing a Document using Domino Data Service

  1. Thanks for clearing this up Mark. I didn’t have the time to look into these services but after this I just stick with my own rest api code.

  2. Ah one of the nice things about using AngularJS is you can just pass the scope model and it will convert to the correct data types under the covers.

    For your CORS requests did you spot you need to respond to 3 HTTP request codes? 200, 206, 204

    When I blogged about it I missed off 204 which is needed for preflight Options.

    I just wish they would sort out authentication requests probably – have an option to not return a HTTP 200 when using session based authentication, instead return 401.

    • Mark – the above was done without cross domain – the CORS preflight PATCH is what is kicking my butt right now – I get a login response without the credentials being sent – most frustrating. I will email you and then one of us can finish that blog post of yours 🙂

  3. Haven’t tried this, but you might be able to use JSON.stringify on your data, something like this?

    var dataObj={ };

    data: JSON.stringify(dataObj),

    • Yes I have seen that used as an example as well – well ok I have once I started to find the answers I was looking for 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s