# Post Form data from function including array

**URL:** <https://discourse.nodered.org/t/post-form-data-from-function-including-array/12429>\
**Category:** General\
**Created:** [20 June 2019 12:32 UTC](https://discourse.nodered.org/t/post-form-data-from-function-including-array/12429 "2019-06-20T12:32:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)\
**Post date:** [20 June 2019 12:32 UTC](https://discourse.nodered.org/t/post-form-data-from-function-including-array/12429/1 "2019-06-20T12:32:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [20 June 2019 14:32 UTC](https://discourse.nodered.org/t/post-form-data-from-function-including-array/12429/2 "2019-06-20T14:32:22Z")

</div>

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`?

---

<div class="post-metadata">

**Author:** ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)\
**Post date:** [20 June 2019 15:18 UTC](https://discourse.nodered.org/t/post-form-data-from-function-including-array/12429/3 "2019-06-20T15:18:15Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)\
**Post date:** [21 June 2019 11:49 UTC](https://discourse.nodered.org/t/post-form-data-from-function-including-array/12429/4 "2019-06-21T11:49:12Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [21 June 2019 12:05 UTC](https://discourse.nodered.org/t/post-form-data-from-function-including-array/12429/5 "2019-06-21T12:05:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [21 June 2019 12:21 UTC](https://discourse.nodered.org/t/post-form-data-from-function-including-array/12429/6 "2019-06-21T12:21:44Z")

</div>

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:

```auto
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;

```

---

<div class="post-metadata">

**Author:** ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)\
**Post date:** [21 June 2019 14:46 UTC](https://discourse.nodered.org/t/post-form-data-from-function-including-array/12429/7 "2019-06-21T14:46:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)\
**Post date:** [21 June 2019 16:14 UTC](https://discourse.nodered.org/t/post-form-data-from-function-including-array/12429/8 "2019-06-21T16:14:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [21 June 2019 16:28 UTC](https://discourse.nodered.org/t/post-form-data-from-function-including-array/12429/9 "2019-06-21T16:28:39Z")

</div>

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