0

Im trying to send a request to a dotnet core api using the nativescript background-http plugin and in the payload one of the properties represents an array. Im trying to send the array like this:

let params = [
                ..........
                ...invitees.map((v,i) => { name: `invitees.${i}.email`, value: v.email }),
                ...invitees.map((v,i) => { name: `invitees.${i}.name`, value: v.email })
            ]

Also tried it like this:

let params = [
                ..........
                ...invitees.map((v) => { name: `invitees.email`, value: v.email }),
                ...invitees.map((v) => { name: `invitees.name`, value: v.email })
            ]

Neither way works when i debug the api to see how it parses the payload. The rest of the properties which is a mix of primitive types, objects and files parse fine. Any idea on what should be the format? The array is of an object with two properties named name and email.

joey0xx
  • 73
  • 10
  • With your second code snippet while it loops through the params all the objects are going to have same name, so only the last value may hit the server. With first one, it may not be an Array of values, your dotnet api might have to read the values one by one as properties like `invitees.1.email` / `invitees.1.name`. I don't think sending an Array of values would be possible with this plugin. – Manoj Mar 18 '19 at 22:17

1 Answers1

0

Made it work like this:

let params = [
                ..........
                ...invitees.map((v,i) => { name: `invitees[${i}].email`, value: v.email }),
                ...invitees.map((v,i) => { name: `invitees[${i}].name`, value: v.email })
            ]
joey0xx
  • 73
  • 10