Hi,
I am trying to POST an array through the Post Agent. (For posting transactions to this API endpoint: /api/customers/bulk/v1 - https://developers.debitoor.com/api-reference#customers)
Unfortunately, the Huginn payload requires to be a hash.
I successfully post event like /api/customers/v1 with payload being a hash like this:
"payload": {
"name": "John Doe",
"paymentTermsId": "{{1 | as_object}}",
"countryCode": "DK"
}
But I cannot succeed in posting array like the one below:
[
{
"name": "John Doe",
"paymentTermsId": "{{1 | as_object}}",
"countryCode": "DK"
}
]
Any clues?
Hi @ameicler,
I wonder why this limitation exists, you can get around it by passing the payload as a string. Merging will not work in that case but the request should be send as specified:
{
"post_url": "https://example.com",
"expected_receive_period_in_days": "1",
"content_type": "application/json",
"method": "post",
"headers": {},
"emit_events": "false",
"no_merge": "true",
"output_mode": "clean",
"payload": "[{\"test\": 1}]"
}
Hi @dsander,
Thanks a lot for your answer!
It is working indeed with this payload and "content_type": "application/json":
[{"name":"John Doe", "paymentTermsId": 1, "countryCode":"DK"}]
--
Maybe app/models/agents/post_agent.rb can be changed to allow array for payload. From this:
if options['payload'].present? && %w[get delete].include?(method) && !options['payload'].is_a?(Hash)
errors.add(:base, "if provided, payload must be a hash")
end
if options['payload'].present? && %w[post put patch].include?(method)
if !options['payload'].is_a?(Hash) && options['content_type'] !~ MIME_RE
errors.add(:base, "if provided, payload must be a hash")
end
to this (I am not familiar with Ruby so this might not be the right format):
if options['payload'].present? && %w[get delete].include?(method) && (!options['payload'].is_a?(Hash) || !options['payload'].is_a?(array))
errors.add(:base, "if provided, payload must be a hash or an array")
end
if options['payload'].present? && %w[post put patch].include?(method)
if (!options['payload'].is_a?(Hash) || !options['payload'].is_a?(array)) && options['content_type'] !~ MIME_RE
errors.add(:base, "if provided, payload must be a hash or an array")
end
Anyhow, closing this issue as it seems solved
I think allowing to post arrays would be a nice addition.
I agree. With the workaround of payload as a string, it is actually not possible to pass interpolated liquid variable ( {{1 | as object}} to pass 1 as an integer for example or {{ country_code }} to retrieve variable from previous event called country_code).
Most helpful comment
I think allowing to post arrays would be a nice addition.