AddressDesk.

AddressDesk Documentation

Integrate address autocomplete, structured address fields, and address validation into your application using the AddressDesk REST API or JavaScript SDK.

01 / INTRODUCTION

Overview

AddressDesk provides two integration methods. Use the REST API when you want complete control over your user interface and HTTP requests. Use the JavaScript SDK when you want to attach autocomplete to an existing input or mount a complete address form into a page.

A

Address suggestions

Search as a user types and display matching address records with structured fields.

B

Address validation

Send address fields to the validation endpoint and process the returned result in your application.

C

Embeddable form

Mount a ready-made address form with autocomplete, validation, feedback messages, and callbacks.

Important distinction

A suggestion match or address-index match does not, by itself, establish that an address is deliverable. Treat each validation status according to your backend's documented contract.

02 / GET STARTED

Quick start

Set the API base URL and API key for your environment. The examples use shell variables so that credentials do not need to be embedded directly in every command.

1

Set your environment values

Replace the example host with your deployed API URL and provide a key authorized to call the address endpoints.

API_BASE="http://localhost:8000"
ADDRESSDESK_API_KEY="YOUR_API_KEY"
2

Search for an address

The suggest endpoint accepts a query, an optional country filter, and a result limit.

curl -G "$API_BASE/v1/addresses/suggest" \
  --data-urlencode "q=mar" \
  --data-urlencode "country=DE" \
  --data-urlencode "limit=6" \
  -H "Accept: application/json" \
  -H "X-API-Key: $ADDRESSDESK_API_KEY"
3

Validate structured address fields

Submit the street, house number, postal code, city, and country code to the validation endpoint.

curl -X POST "$API_BASE/v1/addresses/validate" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $ADDRESSDESK_API_KEY" \
  -d '{
    "street": "Marienplatz",
    "house_number": "1",
    "postal_code": "80331",
    "city": "München",
    "region": "Bayern",
    "country_code": "DE"
  }'
03 / AUTHENTICATION

Authentication

AddressDesk SDK requests send the API key using the X-API-Key request header. REST API calls should use the same header.

X-API-Key: YOUR_API_KEY
Accept: application/json
Header X-API-Key
Response format application/json
Unauthorized 401 / 403

The SDK adds Accept: application/json and X-API-Key automatically. Validation requests that use a JSON body also set Content-Type: application/json.

04 / REST API

Address suggestions

GET /v1/addresses/suggest

Returns address suggestions for the supplied query. The JavaScript SDK requests this endpoint when the configured input reaches the minimum character count.

Query parameters

ParameterRequiredDescription
qYesText used to find address suggestions.
countryNoCountry filter, such as DE, US, or CA.
limitNoMaximum number of suggestions requested by the client.

Request

curl -G "$API_BASE/v1/addresses/suggest" \
  --data-urlencode "q=mar" \
  --data-urlencode "country=DE" \
  --data-urlencode "limit=6" \
  -H "Accept: application/json" \
  -H "X-API-Key: $ADDRESSDESK_API_KEY"

JavaScript request

const params = new URLSearchParams({
  q: 'mar',
  country: 'DE',
  limit: '6'
});

const response = await fetch(
  API_BASE + '/v1/addresses/suggest?' + params,
  {
    headers: {
      Accept: 'application/json',
      'X-API-Key': API_KEY
    }
  }
);

if (!response.ok) {
  throw new Error('Request failed: ' + response.status);
}

const payload = await response.json();
const addresses = payload.results || [];

console.log(addresses);

Address suggestion fields

The SDK reads an array from payload.results. Each result should provide the fields needed by your UI and any configured form field mappings.

{
  "results": [
    {
      "id": "address-record-id",
      "label": "Marienplatz 1, 80331 München, Germany",
      "street": "Marienplatz",
      "house_number": "1",
      "postal_code": "80331",
      "city": "München",
      "region": "Bayern",
      "country_code": "DE"
    }
  ]
}
FieldUsage
idIdentifier for an address record, if available.
labelHuman-readable address displayed in the suggestions menu.
streetStreet name.
house_numberHouse or building number.
postal_codePostal or ZIP code.
cityCity or locality.
regionState, province, or region, when provided.
country_codeCountry code, such as DE.

The sample response illustrates the fields consumed by this SDK; the exact response is determined by your running API.

05 / REST API

Validate an address

POST /v1/addresses/validate

Submit structured address data for validation. The dashboard example and the address form send a JSON object containing the address fields.

Request headers

Accept: application/json
Content-Type: application/json
X-API-Key: YOUR_API_KEY

Request body

{
  "street": "Marienplatz",
  "house_number": "1",
  "postal_code": "80331",
  "city": "München",
  "region": "Bayern",
  "country_code": "DE"
}

Request with cURL

curl -X POST "$API_BASE/v1/addresses/validate" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $ADDRESSDESK_API_KEY" \
  -d '{
    "street": "Marienplatz",
    "house_number": "1",
    "postal_code": "80331",
    "city": "München",
    "region": "Bayern",
    "country_code": "DE"
  }'

Call the endpoint from JavaScript

const response = await fetch(
  API_BASE + '/v1/addresses/validate',
  {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
      'X-API-Key': API_KEY
    },
    body: JSON.stringify({
      street: 'Marienplatz',
      house_number: '1',
      postal_code: '80331',
      city: 'München',
      region: 'Bayern',
      country_code: 'DE'
    })
  }
);

if (!response.ok) {
  throw new Error('Validation request failed: ' + response.status);
}

const result = await response.json();
console.log(result);
Use the request schema expected by your backend

The standalone SDK's generic validate() method defaults to a body shaped like { "address": ... }. The embedded AddressDeskAddressForm overrides this and sends the flat address fields shown above. Configure validationBody or pass body when calling validate() if your backend requires a different schema.

06 / RESPONSES

Response format

Your backend determines the final validation response. The dashboard UI in this project expects a status, a message, and optional check details similar to this example.

{
  "status": "matched_in_address_index",
  "message": "Address matched in the address index.",
  "missing_fields": [],
  "checks": {
    "required_fields": "passed",
    "postal_code_format": "passed",
    "address_index_match": "matched"
  },
  "postal_deliverability": "not_checked"
}
Status or fieldMeaning in the dashboard
matched_in_address_indexAn exact address record was matched.
not_found_in_address_indexNo exact matching record was found.
incompleteOne or more required address fields are missing.
needs_reviewThe address needs further review.
checksPer-check outcomes, if returned by the API.
postal_deliverabilityPostal deliverability status, if your API provides it.

The embedded form considers a result explicitly invalid only when valid === false or is_valid === false. A response containing a different status does not automatically cause the form to reject the address. Use onInvalidAddress and your backend's response contract to implement stricter rules.

07 / JAVASCRIPT SDK

JavaScript SDK

The SDK exports two classes: AddressAutocomplete for attaching a suggestions menu to an existing input, and AddressDeskAddressForm for mounting a complete address form inside a target element.

CLASS

AddressAutocomplete

Adds suggestions, keyboard navigation, selection, mapped fields, and validation requests to an existing input.

AddressAutocomplete.init(options)
CLASS

AddressDeskAddressForm

Mounts a complete form with autocomplete, validation, built-in feedback, configurable labels, and submission callbacks.

AddressDeskAddressForm.mount(options)
Import path

Examples use ./addressdesk-sdk.js as a placeholder for the file containing your SDK. Change the import to match your project's actual file location or bundle output.

08 / SDK AUTOCOMPLETE

Attach autocomplete to existing fields

HTML

Provide an input for the search query and, optionally, other inputs to receive the selected address fields.

<label for="address-search">Address</label>
<input
  id="address-search"
  type="text"
  autocomplete="off"
  placeholder="Start typing an address"
/>

<label for="street">Street</label>
<input id="street" type="text" />

<label for="house-number">House number</label>
<input id="house-number" type="text" />

<label for="postal-code">Postal code</label>
<input id="postal-code" type="text" />

<label for="city">City</label>
<input id="city" type="text" />

<label for="country-code">Country code</label>
<input id="country-code" type="text" value="DE" />

Initialize the SDK

import { AddressAutocomplete } from './addressdesk-sdk.js';

const autocomplete = AddressAutocomplete.init({
  apiKey: 'YOUR_API_KEY',
  apiUrl: 'https://your-api.example.com',
  selector: '#address-search',
  minChars: 2,
  debounceMs: 220,
  limit: 6,
  fields: {
    street: '#street',
    house_number: '#house-number',
    postal_code: '#postal-code',
    city: '#city',
    country: '#country-code'
  },
  onSelect(address) {
    console.log('Selected address:', address);
  },
  onError(error) {
    console.error('Address suggestions failed:', error);
  }
});

How it works

  1. The SDK locates the input using selector or input.
  2. It wraps the input and creates a suggestions menu below it.
  3. After the minimum number of characters, it waits for the configured debounce interval and requests suggestions.
  4. Choosing a suggestion fills the configured fields and calls onSelect.
  5. The user can navigate suggestions with the keyboard or dismiss the menu with Escape.
  6. Call destroy() when the input is removed or the integration is no longer needed.

Selection fields

Map SDK output keys to elements with the fields option. Each value can be a CSS selector or an element.

fields: {
  street: '#street',
  house_number: '#house-number',
  postal_code: '#postal-code',
  city: '#city',
  region: '#region',
  country_code: '#country-code'
}

The SDK also recognizes the aliases houseNumber, postalCode, country, and countryCode when mapping a selected record. If a field is not found or the record has no corresponding value, that field is left unchanged.

Country filtering

Provide a fixed country code, a function returning the current country code, or omit the country option and map fields.country to a country input.

country: 'DE'
country: () => document.querySelector('#country-code').value

When the country changes in a form, the value is read when a new suggestion request is built.

09 / SDK VALIDATION

Validate with the SDK

The autocomplete instance exposes validate() and validateSelected(). These methods return a Promise that resolves with the decoded API response or rejects with an error.

Validate structured fields

const result = await autocomplete.validate(
  {
    street: document.querySelector('#street').value,
    house_number: document.querySelector('#house-number').value,
    postal_code: document.querySelector('#postal-code').value,
    city: document.querySelector('#city').value,
    country_code: document.querySelector('#country-code').value
  },
  {
    body: {
      street: document.querySelector('#street').value,
      house_number: document.querySelector('#house-number').value,
      postal_code: document.querySelector('#postal-code').value,
      city: document.querySelector('#city').value,
      country_code: document.querySelector('#country-code').value
    }
  }
);

console.log(result);

Validate the selected suggestion

const result = await autocomplete.validateSelected({
  body: {
    street: document.querySelector('#street').value,
    house_number: document.querySelector('#house-number').value,
    postal_code: document.querySelector('#postal-code').value,
    city: document.querySelector('#city').value,
    country_code: document.querySelector('#country-code').value
  }
});

Customize the validation request

The call-level options path, method, and body override the instance defaults for that request. The instance can also provide a reusable validationBody function.

const autocomplete = AddressAutocomplete.init({
  apiKey: 'YOUR_API_KEY',
  selector: '#address-search',
  validationPath: '/v1/addresses/validate',
  validationMethod: 'POST',
  validationBody(address) {
    return {
      street: address.street,
      house_number: address.house_number,
      postal_code: address.postal_code,
      city: address.city,
      country_code: address.country_code
    };
  }
});

For a GET validation method, the SDK converts the supplied body into query parameters. For other methods, it sends the body as JSON. Confirm which method and body format your server supports.

10 / EMBEDDED FORM

Mount a complete address form

Use AddressDeskAddressForm.mount() to render a form in an existing container. The form includes a search input, address fields, an autocomplete menu, a submit button, feedback messages, and AddressDesk branding.

HTML container

<div id="address-form"></div>

Minimal integration

Start with the required connection settings, a target element, and an onSubmit callback. The SDK supplies the form fields, autocomplete behavior, validation flow, and default labels.

import { AddressDeskAddressForm } from './addressdesk-sdk.js';

const API_KEY = 'YOUR_API_KEY';
const API_URL = 'https://your-api.example.com';

const addressForm = AddressDeskAddressForm.mount({
  apiKey: API_KEY,
  apiUrl: API_URL,
  target: '#address-form',
  buttonColor: '#5146E5',
  onSubmit(address, validationResult) {
    console.log(address);
  }
});

Complete integration example

import { AddressDeskAddressForm } from './addressdesk-sdk.js';

const addressForm = AddressDeskAddressForm.mount({
  apiKey: 'YOUR_API_KEY',
  apiUrl: 'https://your-api.example.com',
  target: '#address-form',
  country: 'DE',
  title: 'Shipping address',
  description: 'Find your address and confirm your details.',
  submitLabel: 'Continue',
  loadingLabel: 'Please wait…',
  validateOnSubmit: true,
  requireSelection: true,
  onSelect(address) {
    console.log('Address selected:', address);
  },
  onSubmit(address, validationResult) {
    console.log('Address:', address);
    console.log('Validation:', validationResult);
  },
  onInvalidAddress(result, address) {
    console.error('Address rejected:', result, address);
  },
  onError(error) {
    console.error('Form error:', error);
  }
});

Submission flow

  1. When requireSelection is enabled, the user must select an item from the AddressDesk suggestions.
  2. The form reads the current values and assembles a structured address object.
  3. When validateOnSubmit is enabled, it sends the configured validation request.
  4. If the response explicitly sets valid or is_valid to false, the form displays an error and calls onInvalidAddress.
  5. Otherwise, it displays the success message and calls onSubmit(address, validationResult).
  6. When validation is disabled, onSubmit receives the address and null as the validation result.

Customize the form for a German-language audience

You can localize the form by providing your own text for the title, description, field labels, button labels, and configurable status messages. Set country: 'DE' to start with Germany as the country code and filter address suggestions for Germany. The country option does not translate the interface automatically; the strings below provide the German wording.

import { AddressDeskAddressForm } from './addressdesk-sdk.js';

const API_KEY = 'YOUR_API_KEY';
const API_URL = 'https://your-api.example.com';
let addressForm = null;

try {
  addressForm = AddressDeskAddressForm.mount({
    apiKey: API_KEY,
    apiUrl: API_URL,
    target: '#address-form',
    country: 'DE',
    title: 'Lieferadresse',
    description: 'Finde deine Adresse und bestätige deine Angaben.',
    searchLabel: 'Adresse suchen',
    searchPlaceholder: 'Tippe hier, z. B. Marienplatz',
    streetLabel: 'Straße',
    houseNumberLabel: 'Hausnummer',
    postalCodeLabel: 'Postleitzahl',
    cityLabel: 'Ort',
    countryLabel: 'Ländercode',
    submitLabel: 'Weiter zur Zahlung',
    loadingLabel: 'Adresse wird überprüft…',
    selectedMessage: 'Adresse ausgewählt. Prüfe deine Angaben, bevor du fortfährst.',
    selectionRequiredMessage: 'Bitte wähle eine Adresse aus den Vorschlägen aus.',
    validatingMessage: 'Adresse wird überprüft…',
    successMessage: 'Adresse erfolgreich überprüft.',
    buttonColor: '#734234',
    minChars: 2,
    debounceMs: 250,
    limit: 6,
    validateOnSubmit: true,
    requireSelection: true,
    onSelect(address) {
      console.log('Ausgewählte Adresse:', address);
    },
    onValidation(result, address) {
      console.log('Validierungsergebnis:', result);
      console.log('Geprüfte Adresse:', address);
    },
    onInvalidAddress(result, address) {
      console.warn('Adresse ist ungültig:', result, address);
    },
    onSubmit(address, validationResult) {
      console.log('Adresse:', address);
      console.log('Validierungsergebnis:', validationResult);
    },
    onError(error) {
      console.error('AddressDesk-Fehler:', error);
    },
    onValidationError(error, address) {
      console.error('Adressvalidierung fehlgeschlagen:', error, address);
    }
  });
} catch (error) {
  console.error('AddressDesk konnte nicht initialisiert werden:', error);
}

Set title or description to false to hide the corresponding text. The buttonColor option sets the form's --addressdesk-button-color CSS custom property. The example localizes configurable labels and messages; built-in error text that has no corresponding option remains in the SDK's default language.

11 / REFERENCE

Configuration reference

Shared request options

OptionDefaultDescription
apiKeyRequiredAPI key sent through the X-API-Key header.
apiUrlhttps://addressdesk.appBase URL used for SDK requests. Trailing slashes are removed. Set this explicitly to use your own API deployment.
suggestPath/v1/addresses/suggestPath used for autocomplete suggestions.
validationPath/v1/addresses/validatePath used for validation requests.
validationMethodPOSTDefault validation HTTP method.
validationBodySDK defaultOptional function that creates the validation request body from an address value.

Autocomplete options

OptionDefaultDescription
selector / inputRequiredCSS selector or element for the existing search input.
fieldsMap of address keys to CSS selectors or DOM elements.
countryFrom mapped fieldFixed country code or function returning the current country code.
minChars2Minimum query length before searching.
debounceMs220Delay after typing before making a suggestion request.
limit6Number of suggestions requested from the API.
onSelectNoneCalled with the selected address record.
onErrorNoneCalled when suggestion requests fail.
onValidationNoneCalled with (result, address) after successful validation requests.
onValidationErroronErrorCalled with (error, address) when validation fails.

Address form options

OptionDefaultDescription
targetRequiredCSS selector or element where the form is mounted.
countryDEInitial country-code field value and country filter for address suggestions. For example, DE starts with Germany. This option does not translate the interface.
validateOnSubmittrueValidate before reporting a successful submission.
requireSelectiontrueRequire the user to select a suggestion before submitting.
titleShipping addressForm title. Set to false to hide it.
descriptionBuilt-in descriptionIntroductory text. Set to false to hide it.
buttonColor#243d2cButton color and form accent color.
submitLabelContinueButton label when the form is not submitting.
loadingLabelPlease wait…Button label during submission.
onSelectNoneCalled with the selected suggestion record.
onSubmitNoneCalled with (address, validationResult) after a successful flow.
onInvalidAddressNoneCalled when the result explicitly marks the address invalid.
onErrorNoneCalled when form autocomplete or submission fails.
onValidationNoneCalled with the raw result and address after successful validation.
onValidationErrorFallback behaviorCalled for validation failures when configured.

The form also accepts label and message overrides, including searchLabel, searchPlaceholder, streetLabel, houseNumberLabel, postalCodeLabel, cityLabel, countryLabel, selectedMessage, selectionRequiredMessage, validatingMessage, successMessage, and loadingLabel.

12 / EVENTS

Callbacks

Use callbacks to update your application when an address is selected, validation completes, or a request fails.

const autocomplete = AddressAutocomplete.init({
  apiKey: 'YOUR_API_KEY',
  selector: '#address-search',
  onSelect(address) {
    console.log('Selected:', address);
  },
  onError(error) {
    console.error('Suggestion error:', error);
  },
  onValidation(result, address) {
    console.log('Validation result:', result);
    console.log('Validated value:', address);
  },
  onValidationError(error, address) {
    console.error('Validation failed:', error);
    console.log('Submitted value:', address);
  }
});
CallbackArgumentsWhen it runs
onSelectaddressA suggestion is selected.
onErrorerrorA suggestion request or relevant form operation fails.
onValidationresult, addressThe validation endpoint returns a successful HTTP response.
onValidationErrorerror, addressThe validation request fails.
onSubmitaddress, validationResultThe embedded form's submission flow succeeds.
onInvalidAddressresult, addressThe embedded form receives valid: false or is_valid: false.
13 / LIFECYCLE

Lifecycle and cleanup

The SDK adds DOM elements and event listeners. Destroy an instance when its input, form container, or page section is being removed.

autocomplete.destroy();
addressForm.destroy();

AddressAutocomplete.destroy() clears its timer, aborts active requests, removes listeners, restores the original input to its previous location, and removes the SDK wrapper. AddressDeskAddressForm.destroy() destroys its autocomplete instance, removes the form submission listener, and removes the mounted form.

14 / TROUBLESHOOTING

Errors and troubleshooting

API key rejected

Verify that the key is present, active, authorized for the endpoint, and sent in the X-API-Key header. The SDK provides a specific error for HTTP 401 and 403 responses.

No suggestions appear

Confirm that the input has the configured selector, the query reaches minChars, the API returns a JSON object with a results array, and the browser can reach the API.

Address fields are not filled

Check the fields mappings and ensure the result includes the relevant properties, such as house_number and postal_code.

Validation request fails

Check the endpoint path, HTTP method, authentication, CORS configuration, and request body. Make sure the body matches the schema accepted by your backend.

Form says an address is required

With requireSelection: true, typing text alone does not count as selecting an address. Select a suggestion from the menu, or set requireSelection: false if your workflow intentionally permits manual entry.

Browser blocks the request

Configure the API server's CORS policy to permit the website origin and required headers, including X-API-Key and Content-Type where applicable.

15 / SECURITY

Security and production use

01

Browser keys are visible

The SDK runs in the browser and sends the API key with each request. Any key used there can be inspected by a visitor. Never use a private server-side secret as a browser key.

02

Use controlled keys

Use a dedicated key intended for client-side use, with the narrowest permissions and limits your backend supports. Apply server-side authentication, quotas, and monitoring as appropriate for your service.

03

Serve production traffic over HTTPS

Configure the SDK's apiUrl to your HTTPS API origin in production. Avoid sending address data or credentials over unencrypted HTTP.

04

Validate business-critical decisions on the server

Treat browser callbacks as user-interface integration points, not as a security boundary. Enforce authorization and server-side validation for business-critical operations.

AddressDesk

Use the interactive API documentation to inspect the endpoints exposed by the currently configured API server.