const locationsApi = client.locationsApi;
LocationsApi
Provides details about all of the seller's locations, including those with an inactive status.
async listLocations(
requestOptions?: RequestOptions
): Promise<ApiResponse<ListLocationsResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
try {
const { result, ...httpResponse } = await locationsApi.listLocations();
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch (error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}
Creates a location. Creating new locations allows for separate configuration of receipt layouts, item prices, and sales reports. Developers can use locations to separate sales activity through applications that integrate with Square from sales activity elsewhere in a seller's account. Locations created programmatically with the Locations API last forever and are visible to the seller for their own management. Therefore, ensure that each location has a sensible and unique name.
async createLocation(
body: CreateLocationRequest,
requestOptions?: RequestOptions
): Promise<ApiResponse<CreateLocationResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
body |
CreateLocationRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
const body: CreateLocationRequest = {
location: {
name: 'Midtown',
address: {
addressLine1: '1234 Peachtree St. NE',
locality: 'Atlanta',
administrativeDistrictLevel1: 'GA',
postalCode: '30309',
},
description: 'Midtown Atlanta store',
},
};
try {
const { result, ...httpResponse } = await locationsApi.createLocation(body);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch (error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}
Retrieves details of a single location. Specify "main" as the location ID to retrieve details of the main location.
async retrieveLocation(
locationId: string,
requestOptions?: RequestOptions
): Promise<ApiResponse<RetrieveLocationResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
locationId |
string |
Template, Required | The ID of the location to retrieve. Specify the string "main" to return the main location. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
const locationId = 'location_id4';
try {
const { result, ...httpResponse } = await locationsApi.retrieveLocation(locationId);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch (error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}
Updates a location.
async updateLocation(
locationId: string,
body: UpdateLocationRequest,
requestOptions?: RequestOptions
): Promise<ApiResponse<UpdateLocationResponse>>
Parameter | Type | Tags | Description |
---|---|---|---|
locationId |
string |
Template, Required | The ID of the location to update. |
body |
UpdateLocationRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
requestOptions |
RequestOptions | undefined |
Optional | Pass additional request options. |
const locationId = 'location_id4';
const body: UpdateLocationRequest = {
location: {
businessHours: {
periods: [
{
dayOfWeek: 'FRI',
startLocalTime: '07:00',
endLocalTime: '18:00',
},
{
dayOfWeek: 'SAT',
startLocalTime: '07:00',
endLocalTime: '18:00',
},
{
dayOfWeek: 'SUN',
startLocalTime: '09:00',
endLocalTime: '15:00',
}
],
},
description: 'Midtown Atlanta store - Open weekends',
},
};
try {
const { result, ...httpResponse } = await locationsApi.updateLocation(
locationId,
body
);
// Get more response info...
// const { statusCode, headers } = httpResponse;
} catch (error) {
if (error instanceof ApiError) {
const errors = error.result;
// const { statusCode, headers } = error;
}
}