Skip to content

Latest commit

 

History

History
222 lines (172 loc) · 5.86 KB

locations.md

File metadata and controls

222 lines (172 loc) · 5.86 KB

Locations

const locationsApi = client.locationsApi;

Class Name

LocationsApi

Methods

List Locations

Provides details about all of the seller's locations, including those with an inactive status.

async listLocations(
  requestOptions?: RequestOptions
): Promise<ApiResponse<ListLocationsResponse>>

Parameters

Parameter Type Tags Description
requestOptions RequestOptions | undefined Optional Pass additional request options.

Response Type

ListLocationsResponse

Example Usage

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;
  }
}

Create Location

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>>

Parameters

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.

Response Type

CreateLocationResponse

Example Usage

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;
  }
}

Retrieve Location

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>>

Parameters

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.

Response Type

RetrieveLocationResponse

Example Usage

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;
  }
}

Update Location

Updates a location.

async updateLocation(
  locationId: string,
  body: UpdateLocationRequest,
  requestOptions?: RequestOptions
): Promise<ApiResponse<UpdateLocationResponse>>

Parameters

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.

Response Type

UpdateLocationResponse

Example Usage

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;
  }
}