Alright script masters: I am trying to use the qu...
# suitescript
m
Alright script masters: I am trying to use the query module to return results. I am using .asMappedResults(). When I stringify the variable and log it, it shows up as a stringified array of results. But as soon as I pass it to my back end with the Http module, an empty object is passed to my server. Any ideas what I am doing wrong?
e
Will need to see the relevant code
m
e
SuiteScript side looks fine. Does your endpoint perhaps expect a specific
Content-Type
header or similar?
m
the other strange thing is if I pass it mappedResults[0] it will pass the first object in the array like normal.
i will give it a try
e
Would typically expect maybe
Content-Type: application/json
Interesting; so it works with
JSON.stringify(mappedResults[0])
?
m
i dont even have to stringify it
e
But sending the Array without stringifying doesn't work?
m
nope
e
odd
m
very
a
is it? if the body starts with [ instead of { then it wont parse will it?
a
Can you pass a hard coded array of objects (simple one) to your end point?
e
An Array is a valid top-level JSON structure
a
Maybe your end point is expecting an Object and not an array of objects, normally it should work as @erictgrubaugh mentioned, but not sure if your endpoint side code is doing something non standard.
m
When I wrap the stringified in []
content type to json did not help
alright i think i got this figured out
this passes as a string just fine
makes sense if the body is expecting JSON object
👍 1
a
you're welcome 😛
👏 1
m
lol definitely guys thank you! Led me in the right direction!
😉 1
r
@erictgrubaugh @alien4u While an array is a valid JSON object, I have noticed with APIs such as
Renderer.addCustomDataSource()
that NetSuite complains when sending an array (object) which starts with
[
. Pass the same array as
{"arr": [...]}
and it succeeds. Perhaps they have some self-built object validation or else Java built-ins are interpreting JSON badly.
2