# Address

Unlike most answers, a default address answer value is stored as an `object`, since it contains multiple parts.

```
{
  "my_address": {
    "address_1": "213 Main St",
    "address_2": "Apt 17",
    "city": "Kansas City",
    "state": "MO",
    "postal_code": "64116"
  }
}
```

{% hint style="info" %}
Need only the town / city? See the [Region](/adding-questions-and-content/question-reference/region.md) question type.
{% endhint %}

If you would like to access one of the parts of the address in a string [template](/core-concepts/formsort-quickstart-guides/template-your-variables.md), you may use the `get` template function.

Given the above example, a template like:

```
Great, your postal code is {{my_address | get 'postal_code'}}.
```

Would render:

```
Great, your postal code is 64116
```

### Use Single Field

When this option is enabled, Formsort will provide a single input field for the user address, rather than distinct input fields for street address, city, state, and zip.&#x20;

<figure><img src="/files/n4tvFLmkXstec9j4rbxZ" alt=""><figcaption><p>Single field address vs default address components</p></figcaption></figure>

The payload for a single field address is a little different than the default, since the data type is considered `string` instead of an address `object`. This means the address details will come in as one `"raw"` property in the address object.&#x20;

```
{
  "my_address": {
    "raw": "213 Main St., Apt 17, Kansas City, MO 64116"
  }
}
```

### International addresses <a href="#international-addresses" id="international-addresses"></a>

If you enable **International?**, then responders will be allowed to choose the country of their address. The saved address will contain the `country` that was selected.

```
{
  "my_international_address": {
    "address_1": "Strahovské nádvoří 301",
    "city": "Praha",
    "postal_code": "118 00"
    "country": "Czech Republic"
  }
}
```

#### Default <a href="#default" id="default"></a>

When international addresses are enabled, you can set a default country using Default country.

## Setting Address via URL parameter

If you'd like to pass an address into the flow for your user, here is an example of the syntax required for the address component at the top of this section. Notice each `[field]` corresponds to an object key from the example.&#x20;

You can set all the address fields, or just the fields you have (or want to use).&#x20;

#### Default address component syntax:&#x20;

`https://your-flow-url.com?my_address[address_1]=213+Main+St&my_address[address_2]=Apt+17&my_address[city]=Kansas+City&my_address[state]=MO&my_address[postal_code]=64116`

#### Single-field address component syntax:

Since the Single-Field address string will require commas, you may have to URL encode the address before passing it in as a value for the parameter.&#x20;

`https://your-flow-url.com?my_address[raw]=123%20Main%20St%2C%20Apt%2017%20Kansas%20City%2C%20MO%2C%2064116`

{% hint style="info" %}
See [URL Parameters](https://docs.formsort.com/handling-data/passing-data-in/url-parameters) for more information on passing answers in to a flow.&#x20;
{% endhint %}

## Autocomplete using Google Places API <a href="#autocomplete-using-google-places-api" id="autocomplete-using-google-places-api"></a>

Addresses are sometimes tedious to type, so you can use the [Google Places API](https://developers.google.com/places/web-service/get-api-key) to auto-complete addresses, by providing your API key.&#x20;

{% hint style="info" %}
If you are restricting referrers and/or embedding your Formsort flow, make sure to add `flow.formsort.com` (which is where your flow will be hosted) to the list of allowed referrers in the Google API console, **in addition** to any custom domains on which you are hosting your flows.

Whitelisting `flow.formsort.app` may be necessary for use of the Places API in the Live Preview as well!&#x20;
{% endhint %}

When enabled, the address answer will also contain a `raw` field which stores the raw string that was entered by the user.

```
{
  "my_address": {
    "raw": "213 Main St., Apt 17, Kansas City, MO 64116",
    "address_1": "213 Main St",
    "address_2": "Apt 17",
    "city": "Kansas City",
    "state": "MO",
    "postal_code": "64116"
  }
}
```

## Validating form addresses with USPS <a href="#validating-form-addresses-with-usps" id="validating-form-addresses-with-usps"></a>

{% hint style="info" %}
This feature is only available for addresses in the United States.
{% endhint %}

Enabling **Validate addresses (US only)?** activates the [USPS Addresses API](https://developers.usps.com/addressesv3), which verifies that entered addresses are valid U.S. mailing addresses. Before using this feature, you must configure the USPS integration.\
Follow the guide [here ](/integrations/integration-reference/usps.md)to get started.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.formsort.com/adding-questions-and-content/question-reference/address.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
