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;
}
addressis 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”)typesis 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[];
}
datacontains an array ofAutocompletePlaces objects which best match theaddressprovided.interface AutocompletePlace { place_id: string; main_text: string; description: string; api_specific_data: { types: string[]; }; }place_idis the ID of the place (e.g. “G:ChIJFcXEG65ZwokRLH0n5pmtMIQ”).main_textis the shorthand address of the place (e.g. “4 Pennsylvania Plaza”).descriptionis the full address of the place (e.g. “4 Pennsylvania Plaza, New York, NY, USA”).api_specific_datais 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.