×Overview

Passing data in

Often, you will want to start a flow with some answers prefilled, or will need to reach outside of the formsort world to get some data you need to build robust flows.

Passing answers via URL search parameters

The easiest way to set answers in a flow from outside is to set them in the url search parameters in the URL to the flow, using the variable names as keys

For example, if I have a variable first_name, I could pass a first name into a flow by appending ?first_name=Hélène to the URL of a flow. If you're passing multiple answers at once, separate the answers with an ampersand, for example ?first_name=Hélène&last_name=Wilson.

Answers passed with the wrong type, or to non-existent variable names, are ignored when loading the flow.

Passing in answers that are not collected within the flow

You may find that you need to pass in data that isn't collected within the questions themselves. For example, you may track what source a user comes from using a ?utm_source= parameter, that you may want to either pass on when redirecting at the end of the flow, or use within the flow.

To allow acceptance of variables not used in the flow, access the Schema tab and complete Add external variable... at the bottom.

Answers API (derived or computed answers)

Often, you will want to calculate a new answer based on the answers provided within a flow. For example, given a zip code, you may want to find the closest store to that location, or fetch pricing for a product the user may be interested in purchasing. This data lives in your own systems, and would be tedious to recreate in formsort or keep in sync, since your system is the source of truth.

This is also possible using Add external variable..., when you also enable Is this variable computed from an API. Then, you will be allowed to specify a URL (in which you can use templated variables) that will be fetched whenever all the dependent answers are collected. If you implement a JSON GET endpoint at that URL, you will have access to that answer within formsort.

Result accessor

Let's say we're fetching some data from a url https://example.com/api/v1/closest_store?zipcode={{zipcode}}.

The API result, depending on how we implement it, might look something like this:

{
  "ok": true,
  "store": {
    "name": "Bob's Burgers", 
    "employeeCount": 4
  }
}

The result accessor is the way we would access the piece of data we need using Javascript syntax.

So, if we wanted to define a derived answer named closest_store_name, we could use the result accessor store.name.

Note that it's possible to access within arrays using array indexes. So if your API result looks like:

{
  "prices": [
    {
      "product": "Apple",
      "price_usd": 1
    },
    {
      "product": "Banana",
      "price_usd": 2
    }
  ]
}

You can access the first price with prices[0].price_usd.

If the API fails to load, or the result does not have the correct variable type at the accessor path, the answer will not be set.

Choices API

A related API is the Choices API, which allows for dynamically fetching the list of choices provided to the user in a select question. If you wanted to have the user pick between nearby stores, you might want to use this API, by checking Load choices dynamically? on any select question.

The expected shape of the returned JSON looks like:

[
  {
    label: "",
    value: "",
  }
]

If you'd like to display images on the select options (for example when using the button style), you may also pass the imageUrl attribute for each chioce.

[
  {
    label: "",
    value: "",
    imageUrl: "http://example.com/image.png",
  }
]
Previous
« Conditions and Logic

Contact
  • hello@formsort.com
  • Jobs
  • Security
Resources
  • Formsort Inc
    © 2020