JSON child objects within a RestRequest body
I have a working API call in Postman that gets data from another application using a filter. Using the C# code that Postman outputs works, but doesn't seem to include the filter object within my json body. So with the example below:
C# code
JSON Body in Postman
When run in Postman, I correctly get 3 results returned that match the filter arguments. When run in C# I get 18,000 results as the filter object doesn't appear to be passed correctly and it's only getting the source/field values.
I'm assuming I need to do something else to wrap the filter object within the json body object so that it's parsed correctly but I haven't been able to work out what that syntax should be
3 Replies
It looks like your filter object should just be a simple class or record containing (optional) strings; artist and title
If you want to make it generic and let whatever consumes the filter do mapping, a dictionary of string keys and string values would also work
The API that consumes the filter isn't in C# and just needs the JSON body as I have it in Postman, but for whatever reason the way I'm adding it to the RestRequest in C# is not producing the same result.
Are you able to show me an example of what that dictionary method would look like?
I think just making something along the lines of this might be easiest: {
"source": "non-archived",
"fields": ["type", "title", "tags", "cuepoints", "data"],
"filter": { "artist": "Dr. Peacock", "title": "Medication" }
}