Good afternoon. Love the module and using it often. I am running into an error with the body of a POST request function wherein the API I am interacting with (distech) requires the body to be a ‘jsonArray’ and no matter how I format the body, it’s being sent as a ‘json Object’.
The format is something like this:
Body: |
[
{
key: value,
key: value,
key: value
},
{
key: value,
key: value,
key: value
},
{
key: value,
key: value,
key: value
}
]
If I submit like above, the exception comes from the module saying json strings must begin with ‘{‘
Thank you!
Your body isn't valid JSON as your array (the value) needs to be assigned to a key. I don't know what they're expecting, so could be something like this:
{
key: [
{
key: value,
key: value,
key: value
},
{
key: value,
key: value,
key: value
},
{
key: value,
key: value,
key: value
}
]
}
That would then be a ‘json object’ though, and it needs to be a ‘json array’
Oh, I think I see what you're saying....they want it to be formatted without the external object and pass just the array.
Would something like this work assuming your json object is named jsonObj:
jsonArr = jsonObj['key']
I haven't used the module, but didn't know if you could just pass a variable as the body.
Otherwise, your body looks like it would be OK in terms of how it's formatted.
It's possible the module itself is expecting it to begin with curly braces as a validation check. (Have you tried just tacking on the front/back opening/closing curly braces to see if it will take it?
I have. The configuration is written in YAML. I’ve tried several combinations and anything formatted as a class json Object returns an error from the targeted API which says essentially “json object could not be formatted as json array”. So I assume it’s something to do with the module and was hoping a fix might be a simple matter. Fingers crossed.
As I’m writing this it’s occurred to me that I haven’t tried submitting it in a YAML sequence, which might allow coercion into a json array… something like
Body:
- key0:value
key1:value
key2:value
- key0:value
key1:value
key2:value
Again, fingers crossed haha. Will try tmm
Update: (next morning)
No dice. If there is a quick edit that can allow json Arrays to be passed into a body of a request, that is without the required '{', that would be incredible!
So my java is not amazing so don't judge haha, but i can confirm that editing Body.java located here:
like so
and rebuilding the module unsigned did indeed solve the problem. I expected some other dependencies to cause issues but this worked beautifully.