1Step 1: Overview#

Send the user's search text to Swiftcomplete and display the suggestions it returns. If the user picks an individual address, retrieve its full details. If they pick a container, such as a postcode or street, open it and let them choose an address from the results.

A populated result includes address lines and a display label. It can also include structured address components and coordinates.

2Step 2: Base endpoint#

Endpoint
https://api.swiftcomplete.com/v1/swiftlookup/

Use HTTPS GET requests with the parameters in the query string.

3Step 3: Request parameters#

Query parameterDescription
keyYour Swiftcomplete API key.
textThe search text entered by the user.
biasTowardsOptional coordinates in lat,lon format. Favours results near that location.
populateIndexThe selected item's zero-based index in the response array. Requests the full address for that item.
countriesComma-separated country codes that limit where the API searches.
containerThe value returned with a container suggestion. Send it to fetch the addresses it contains.
maxResultsThe maximum number of child results to return in a container request, up to 100.
pageFromThe offset at which to start the next page of child results.

4Step 4: Standard autocomplete flow#

Search on every keystroke

As the user types, send the current contents of the address field in text.

Request
GET https://api.swiftcomplete.com/v1/swiftlookup/?key=INSERT_KEY_HERE&text=what3

The example response below shows the first two suggestions.

Response
[
  {
    "primary": { "text": "What3words, Alfred Rd", "highlights": [0, 4] },
    "secondary": { "text": "London", "highlights": [] },
    "type": "address.business",
    "isContainer": false,
    "countryCode": "GB"
  },
  {
    "primary": { "text": "Sew What, 34 Caledonian Rd", "highlights": [4, 7, 10, 10] },
    "secondary": { "text": "Wishaw", "highlights": [] },
    "type": "address.business",
    "isContainer": false,
    "countryCode": "GB"
  }
]

Display the suggestion list

Response fieldHow to use it
primary.textDisplay as the main text for the suggestion.
secondary.textDisplay as supporting text.
primary.highlights, secondary.highlightsHighlight the matching character ranges in each display string.
typeIdentify the kind of result.
isContainerDecide whether to open a container or populate the selected result directly.
countryCodeIdentify the country associated with the suggestion.

Populate a selected result

When the user chooses a suggestion with isContainer set to false, repeat the exact request that returned it and add populateIndex with its position in the array. The first result has index 0.

Request
GET https://api.swiftcomplete.com/v1/swiftlookup/?key=INSERT_KEY_HERE&text=what3&populateIndex=0
Response
[
  {
    "primary": { "text": "What3words, Alfred Rd", "highlights": [0, 4] },
    "secondary": { "text": "London", "highlights": [] },
    "isContainer": false,
    "geometry": {
      "centre": {
        "lat": 51.521198,
        "lon": -0.196334
      }
    },
    "populatedRecord": {
      "lines": [
        "What3words Ltd",
        "65 Alfred Road",
        "LONDON",
        "W2 5EU",
        "United Kingdom"
      ],
      "label": "What3words Ltd\n65 Alfred Road\nLONDON\nW2 5EU\nUnited Kingdom"
    }
  }
]

Use the populated record

  • Use populatedRecord.lines for the individual address lines.
  • Use populatedRecord.label for a display label with line breaks.
  • Read structured address components from populatedRecord.data when present.
  • Read latitude and longitude from geometry.centre.lat and geometry.centre.lon when available.

5Step 5: Container flow#

If a suggestion has isContainer set to true, open it first. Apply populateIndex to the request that returned the chosen child address.

Search for a container

In this example, a postcode search returns one suggestion with a container value.

Request
GET https://api.swiftcomplete.com/v1/swiftlookup/?key=INSERT_KEY_HERE&text=ng97bs
Response
[
  {
    "primary": { "text": "NG9 7BS", "highlights": [0, 2, 4, 6] },
    "secondary": { "text": "Brookhill St", "highlights": [] },
    "type": "place.area.postcode",
    "isContainer": true,
    "container": "V1;NG9 7BS;52.923435;-1.279735",
    "countryCode": "GB"
  }
]

Open the container

Start a new request using the returned container value. This example uses maxResults=100 and encodes the space in the postcode as %20.

Request
GET https://api.swiftcomplete.com/v1/swiftlookup/?key=INSERT_KEY_HERE&container=V1;NG9%207BS;52.923435;-1.279735&maxResults=100

The example response below shows the first two child results.

Response
[
  {
    "primary": { "text": "2 Brookhill St" },
    "secondary": { "text": "Stapleford, NG9 7BS" },
    "isContainer": false
  },
  {
    "primary": { "text": "2a Brookhill St" },
    "secondary": { "text": "Stapleford, NG9 7BS" },
    "isContainer": false
  }
]

Let the user choose a child result

Display the child addresses as a second list of suggestions.

Populate the selected child result

Repeat the container request that returned the chosen address. Keep its existing parameters, including pageFrom if the result came from a later page, and add populateIndex with the child's index in that response.

6Step 6: Container pagination#

If the response contains exactly maxResults items, another page may be available. Use pageFrom to fetch it. For example, to fetch the next page after the first 10 results, set pageFrom=10.

Request
GET https://api.swiftcomplete.com/v1/swiftlookup/?key=INSERT_KEY_HERE&container=V1;NG9%207BS;52.923435;-1.279735&maxResults=10&pageFrom=10

Advance pageFrom by the page size after each full page. Stop when the response contains fewer items than maxResults.

Typing

Call swiftlookup with the current text after each keystroke and display the results as suggestions.

Selecting a non-container result

Repeat the search request with the selected index in populateIndex. Use the returned populatedRecord to fill the address fields.

Selecting a container result

Open the container and show its child addresses. When the user picks one, repeat the request for that list or page with the chosen index in populateIndex.

8Step 8: Important implementation rules#

  • Send the current search text after each keystroke.
  • For a population request, keep the original query parameters and add only populateIndex.
  • Open a container before populating any of its child addresses.
  • Use pageFrom for container pagination and stop after a response with fewer than maxResults items.

9Step 9: Integration logic#

Pseudocode
suggestions = lookup(key, text)

When the user selects a suggestion:
  If isContainer is false:
    Repeat the search request with populateIndex set to the selected index
    Use populatedRecord

  If isContainer is true:
    Request the child results with key, container and maxResults
    If a page is full, fetch the next page with pageFrom as needed
    When the user selects a child, repeat the request for its page
      with populateIndex set to the child's index on that page
    Use populatedRecord

10Step 10: Response fields to store#

FieldValue
populatedRecord.labelAddress formatted as a multiline label.
populatedRecord.linesIndividual address lines in an array.
populatedRecord.dataStructured address components, when present.
geometry.centre.latLatitude, when available.
geometry.centre.lonLongitude, when available.
countryCodeCountry code.

11Step 11: Summary#

Search with text as the user types. To retrieve a direct address, repeat the search with populateIndex. For a container, fetch its child results, page through them with pageFrom if needed, and use populateIndex on the request that returned the chosen child.

Find out more

Can’t find what you’re looking for, or want to report an issue? Get in touch here.

esc
↑ ↓ to choose↵ to openesc to close