02-27-2025 10:28 PM
I am trying to format a request payload to be an array of objects, but it appears that the payload HTTP method defaults to formatting it as a hash such as
{
email: "exampleemail",
name: "John Jacob Jingleheimer Schmidt"
}
However, it needs to be enveloped in an array like as follows:
[
{
email: "exampleemail",
name: "John Jacob Jingleheimer Schmidt"
}
]
The payload HTTP method does not accept arrays, as this will throw an error. Is there a way to do this? What are your thoughts on this?
Solved! Go to Solution.
4 weeks ago
Found a solution to this - quite silly now that I think about it.
Since the payload method does not support an array as an argument, I looked at the SDK Reference > HTTP Methods docs yet again, and realized that I could also pass arguments directly within the verb methods such that:
request_payload = {"data" => {"email" => "exampleemail", "name" => "John Jacob Jingleheimer Schmidt"}}
arrayed_req_payload = [request_payload['data']]
post(url, arrayed_req_payload)
This successfully passed the arrayed payload into the request body. Thank you all for your help and contribution!
02-27-2025 10:47 PM
I just tested this and the HTTP request payload (specifically for a POST) will accept an array without issue. You may be encoding it incorrectly. Can you provide more details on the error you receive?
a month ago
I tried enveloping the hash in an array in the following manner:
request_payload = {"data" => {"email" => "exampleemail", "name" => "John Jacob Jingleheimer Schmidt"}}
arrayed_req_payload = [request_payload['data']]
post(url).payload(arrayed_req_payload || {})
But I get an error saying undefined method `to_hash' for [nil]:Array at line: xxx where the line is the payload method. It's as if it is trying to convert it to a hash.
a month ago
Ah, you're in the connector SDK. This is interesting...
Looking at the SDK docs, it does indeed look like it's trying to hash whatever you put inside payload. I recommend checking with support about this. Sorry I couldn't be more help!
a month ago
No worries! I appreciate you looking into this!