Autocomplete Places
autocompletePlaces
is used to get a list of places autocompleted from an address (or partial address). This is useful when providing an autofill input for a buyer to enter their address when it comes to finding their closest store location(s).
Usage
autocompletePlaces
takes in the following object:
interface AutocompletePlacesRequest {
address: string;
types?: AutocompletePlaceTypeEnum;
}
address
is simply a partial or full address written by the buyer (e.g. “4 Pennsylvania Plaza” or “4 Pennsylvania Plaza, New York, NY 10001, United States”)types
is the type of places that you want to include in the autocomplete results, defaults to “geocode”. Valid types include “address”, “geocode”
Example
const autocompletePlacesRequest = {
address: '4 Pennsylvania Plaza',
types: 'address'
};
try {
const response = await sdk.places.autocompletePlaces(autocompletePlacesRequest);
} catch (error) {
// Handle errors
}
Return Value
On success the following object is returned. Note that on no matches found, data will be an empty array.
interface AutocompletePlacesResponse {
data: AutocompletePlace[];
}
data
contains an array ofAutocompletePlace
s objects which best match theaddress
provided.interface AutocompletePlace { place_id: string; main_text: string; description: string; api_specific_data: { types: string[]; }; }
place_id
is the ID of the place (e.g. “G:ChIJFcXEG65ZwokRLH0n5pmtMIQ”).main_text
is the shorthand address of the place (e.g. “4 Pennsylvania Plaza”).description
is the full address of the place (e.g. “4 Pennsylvania Plaza, New York, NY, USA”).api_specific_data
is just additional type data about the place (e.g. types: [“street_address”, “geocode”]).
Error Handling
The SDK does no special error handling for this GET request. On a network error, it will simply throw the Error
object that fetch
would throw.