Search code examples
restformstack

How to POST array data in Formstack


I'm using the Advanced Rest Client Chrome extension to POST a Formstack Submission to a specified form and am defining the fields "latitude", "longitude", and "ContactID". This is what I am passing to it and recieving back.


Headers:
Host: www.formstack.com
Authorization: Bearer (my key)

Payload:
latitude=33&longitude=23&data[ContactID]=a112SSb23v


The response:

{
id: "(this submission id)"
message: "<p>The form was submitted successfully.</p>"
timestamp: "2014-10-28 11:30:35"
user_agent: "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)     Chrome/38.0.2125.104 Safari/537.36"
remote_addr: "( the remote_addr)"
payment_status: ""
form: "( the form id)"
latitude: "33"
longitude: "23"
data: [0]
pretty_field_id: "(the pretty_field_id)"
data: [0]

As you can see, data is empty, despite having set one of its fields in the Payload.

This is the response I get for "data" when I manually edit ContactID on the Submission and do a GET. Note that the field is a numeric ID instead of the name "ContactID".

data: [1]
    0:  {
        field: "28290796"
        value: "a112SSb23v"
    }}

I can pass data to latitude/longitude/etc. quite easily because they are just one field on the Submission but I am having trouble passing to data, which is an array of fields.
I have structured my Payload according to the Formstack documentation http://developers.formstack.com/v2.0/docs/form-id-submission-post, but the value is not being set.
So my question is: How can I POST to a field that is held within an array?

Note:
I have also used the numeric ID (28290796) associated with the field ContactID (as well as multiple other permutations) but still no such luck.


Solution

  • I figured it out through trial and error.
    Apparently I wasn't following the documentation closely enough!!!

    To POST to a field held within the "data" array, you must use "field_" + (the numeric id of your field)

    EX: The numeric ID of my field "ContactID" is 28290796.
    So, to create a submission with this field as a certain value we type: field_28290796=certainValue