Post Form data from function including array

Hi
I am trying to use an API and POST multipart/form-data. I am using the example from the API docs which includes an array. When I try to post this the error is Arrays are not supported. I am using a function block to pass in the data.

The function code is

msg.payload = { "customer_id": 153618000000549022,"invoice_number": "INV-00003","date": "2019-06-19", "line_items": [ {"item_id": 982000000030049,"name": "Hard Drive","item_order": 1}] };
msg.headers = {'content-type':'multipart/form-data'};
return msg;

Any suggestions appreciated

Which API docs are you referring to?

The form data library we use does not support array types. Are you sure you want to be using multipart/form-data and not application/x-www-form-urlencoded?

Hi Nick

Thanks for the reply. The API docs are here and I am trying to Create and Invoice.

https://www.zoho.com/invoice/api/v3/#Invoices_Create_an_invoice

I have contacted support and they have responded as follows

If you look at the POST call you're making to create invoice, you are passing the JSONString as a query parameter. Instead of that, you need to pass it as form-data.

Thanks for the help

Hi Nick

Thanks for the reply. The API docs are here and I am trying to Create and Invoice.

https://www.zoho.com/invoice/api/v3/#Invoices_Create_an_invoice

I have contacted support and they have responded as follows

If you look at the POST call you're making to create invoice, you are passing the JSONString as a query parameter. Instead of that, you need to pass it as form-data.

Thanks for the help

You appear to have repeated your post. Please don’t

Their docs show they expect the form-data to have a single property called JSONString with its value being the JSON encoded object.

That suggests the following would work:

var data = { "customer_id": 153618000000549022,"invoice_number": "INV-00003","date": "2019-06-19", "line_items": [ {"item_id": 982000000030049,"name": "Hard Drive","item_order": 1}] };

msg.headers = {
     'content-type':'multipart/form-data'
}
msg.payload = {
    JSONString: JSON.stringify(data)
}
return msg;

Apologies, I just noticed that I should have replied to Nicks advice

Thanks Nick, That worked I only had to change the numbers to strings

You can edit posts... No need to repost content just to tag someone in.

1 Like