1

I want to send this JSON string with RestSharp as a parameter:

{"filter":[{"date_modified":{"$dateBetween":["2017-10-13","2017-10-13"]}}]}

Ideally I'd like to do something like this:

request.AddParameter("filter","[{"date_modified":{"$dateBetween":["2017-10-13","2017-10-13"]}}]");

But does obviously not work. But how can I solve it?

Edit: I have tried sending in the json string through a REST client so I know it works.

Regards, Erik

Erik
  • 13
  • 6
  • 1
    does not work because...? You didn't say what the error is. But I guess maybe the internal quote marks? You can escape them with a backslash. – ADyson Oct 13 '17 at 11:39
  • The api does not recognice it. Which leads me to believe it is not serializing it correctly. I have tried the backslashes but it produces the same result. – Erik Oct 13 '17 at 11:43
  • The code you provide cannot compile because you do not escape the `"` – Deblaton Jean-Philippe Oct 13 '17 at 11:47
  • Have you considered adding the json to the body rather than passing it as a parameter in the url? Perhaps this: https://stackoverflow.com/questions/31937939/restsharp-post-a-json-object has some information you can use. – kkirk Oct 13 '17 at 11:48
  • Deblaton: I wrote this on the fly in the post. But the backslashes are there in the actual code. – Erik Oct 13 '17 at 12:03
  • @kkirk I tried doing that but then the api just ignored it. – Erik Oct 13 '17 at 12:04
  • @Erik How are you trying to read the body in the API? Have you tried something like await Request.Content.ReadAsStringAsync() or using the [FromBody] attribute on a method parameter to get the body? What have you tried so far? – kkirk Oct 13 '17 at 12:11
  • I'm working with SugarCRMs API so that part I can't really affect I'm afraid. – Erik Oct 13 '17 at 12:23
  • I know there are issues with handling collections when using the default serialiser. Consider using JSON.NET serialiser, there is a separate package for this. We will add it to the core repository later. – Alexey Zimarev Oct 16 '17 at 17:52

0 Answers0