Skip to content

Latest commit

 

History

History
583 lines (450 loc) · 24.2 KB

location-custom-attributes.md

File metadata and controls

583 lines (450 loc) · 24.2 KB

Location Custom Attributes

const locationCustomAttributesApi = client.locationCustomAttributesApi;

Class Name

LocationCustomAttributesApi

Methods

List Location Custom Attribute Definitions

Lists the location-related custom attribute definitions that belong to a Square seller account. When all response pages are retrieved, the results include all custom attribute definitions that are visible to the requesting application, including those that are created by other applications and set to VISIBILITY_READ_ONLY or VISIBILITY_READ_WRITE_VALUES.

async listLocationCustomAttributeDefinitions(  visibilityFilter?: string,
  limit?: number,
  cursor?: string,
requestOptions?: RequestOptions): Promise<ApiResponse<ListLocationCustomAttributeDefinitionsResponse>>

Parameters

Parameter Type Tags Description
visibilityFilter string | undefined Query, Optional Filters the CustomAttributeDefinition results by their visibility values.
limit number | undefined Query, Optional The maximum number of results to return in a single paged response. This limit is advisory.
The response might contain more or fewer results. The minimum value is 1 and the maximum value is 100.
The default value is 20. For more information, see Pagination.
cursor string | undefined Query, Optional The cursor returned in the paged response from the previous call to this endpoint.
Provide this cursor to retrieve the next page of results for your original request.
For more information, see Pagination.
requestOptions RequestOptions | undefined Optional Pass additional request options.

Response Type

ListLocationCustomAttributeDefinitionsResponse

Example Usage

try {
  const { result, ...httpResponse } = await locationCustomAttributesApi.listLocationCustomAttributeDefinitions();
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch (error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}

Create Location Custom Attribute Definition

Creates a location-related custom attribute definition for a Square seller account. Use this endpoint to define a custom attribute that can be associated with locations. A custom attribute definition specifies the key, visibility, schema, and other properties for a custom attribute. After the definition is created, you can call UpsertLocationCustomAttribute or BulkUpsertLocationCustomAttributes to set the custom attribute for locations.

async createLocationCustomAttributeDefinition(  body: CreateLocationCustomAttributeDefinitionRequest,
requestOptions?: RequestOptions): Promise<ApiResponse<CreateLocationCustomAttributeDefinitionResponse>>

Parameters

Parameter Type Tags Description
body CreateLocationCustomAttributeDefinitionRequest 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

CreateLocationCustomAttributeDefinitionResponse

Example Usage

const body: CreateLocationCustomAttributeDefinitionRequest = {
  customAttributeDefinition: {
    key: 'bestseller',
    name: 'Bestseller',
    description: 'Bestselling item at location',
    visibility: 'VISIBILITY_READ_WRITE_VALUES',
  },
};

try {
  const { result, ...httpResponse } = await locationCustomAttributesApi.createLocationCustomAttributeDefinition(body);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch (error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}

Delete Location Custom Attribute Definition

Deletes a location-related custom attribute definition from a Square seller account. Deleting a custom attribute definition also deletes the corresponding custom attribute from all locations. Only the definition owner can delete a custom attribute definition.

async deleteLocationCustomAttributeDefinition(  key: string,
requestOptions?: RequestOptions): Promise<ApiResponse<DeleteLocationCustomAttributeDefinitionResponse>>

Parameters

Parameter Type Tags Description
key string Template, Required The key of the custom attribute definition to delete.
requestOptions RequestOptions | undefined Optional Pass additional request options.

Response Type

DeleteLocationCustomAttributeDefinitionResponse

Example Usage

const key = 'key0';

try {
  const { result, ...httpResponse } = await locationCustomAttributesApi.deleteLocationCustomAttributeDefinition(key);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch (error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}

Retrieve Location Custom Attribute Definition

Retrieves a location-related custom attribute definition from a Square seller account. To retrieve a custom attribute definition created by another application, the visibility setting must be VISIBILITY_READ_ONLY or VISIBILITY_READ_WRITE_VALUES.

async retrieveLocationCustomAttributeDefinition(  key: string,
  version?: number,
requestOptions?: RequestOptions): Promise<ApiResponse<RetrieveLocationCustomAttributeDefinitionResponse>>

Parameters

Parameter Type Tags Description
key string Template, Required The key of the custom attribute definition to retrieve. If the requesting application
is not the definition owner, you must use the qualified key.
version number | undefined Query, Optional The current version of the custom attribute definition, which is used for strongly consistent
reads to guarantee that you receive the most up-to-date data. When included in the request,
Square returns the specified version or a higher version if one exists. If the specified version
is higher than the current version, Square returns a BAD_REQUEST error.
requestOptions RequestOptions | undefined Optional Pass additional request options.

Response Type

RetrieveLocationCustomAttributeDefinitionResponse

Example Usage

const key = 'key0';

try {
  const { result, ...httpResponse } = await locationCustomAttributesApi.retrieveLocationCustomAttributeDefinition(key);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch (error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}

Update Location Custom Attribute Definition

Updates a location-related custom attribute definition for a Square seller account. Use this endpoint to update the following fields: name, description, visibility, or the schema for a Selection data type. Only the definition owner can update a custom attribute definition.

async updateLocationCustomAttributeDefinition(  key: string,
  body: UpdateLocationCustomAttributeDefinitionRequest,
requestOptions?: RequestOptions): Promise<ApiResponse<UpdateLocationCustomAttributeDefinitionResponse>>

Parameters

Parameter Type Tags Description
key string Template, Required The key of the custom attribute definition to update.
body UpdateLocationCustomAttributeDefinitionRequest 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

UpdateLocationCustomAttributeDefinitionResponse

Example Usage

const key = 'key0';

const body: UpdateLocationCustomAttributeDefinitionRequest = {
  customAttributeDefinition: {
    description: 'Update the description as desired.',
    visibility: 'VISIBILITY_READ_ONLY',
  },
};

try {
  const { result, ...httpResponse } = await locationCustomAttributesApi.updateLocationCustomAttributeDefinition(
  key,
  body
);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch (error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}

Bulk Delete Location Custom Attributes

Deletes custom attributes for locations as a bulk operation. To delete a custom attribute owned by another application, the visibility setting must be VISIBILITY_READ_WRITE_VALUES.

async bulkDeleteLocationCustomAttributes(  body: BulkDeleteLocationCustomAttributesRequest,
requestOptions?: RequestOptions): Promise<ApiResponse<BulkDeleteLocationCustomAttributesResponse>>

Parameters

Parameter Type Tags Description
body BulkDeleteLocationCustomAttributesRequest 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

BulkDeleteLocationCustomAttributesResponse

Example Usage

const body: BulkDeleteLocationCustomAttributesRequest = {
  values: {
    'id1': {
      key: 'bestseller',
    },
    'id2': {
      key: 'bestseller',
    },
    'id3': {
      key: 'phone-number',
    }
  },
};

try {
  const { result, ...httpResponse } = await locationCustomAttributesApi.bulkDeleteLocationCustomAttributes(body);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch (error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}

Bulk Upsert Location Custom Attributes

Creates or updates custom attributes for locations as a bulk operation. Use this endpoint to set the value of one or more custom attributes for one or more locations. A custom attribute is based on a custom attribute definition in a Square seller account, which is created using the CreateLocationCustomAttributeDefinition endpoint. This BulkUpsertLocationCustomAttributes endpoint accepts a map of 1 to 25 individual upsert requests and returns a map of individual upsert responses. Each upsert request has a unique ID and provides a location ID and custom attribute. Each upsert response is returned with the ID of the corresponding request. To create or update a custom attribute owned by another application, the visibility setting must be VISIBILITY_READ_WRITE_VALUES.

async bulkUpsertLocationCustomAttributes(  body: BulkUpsertLocationCustomAttributesRequest,
requestOptions?: RequestOptions): Promise<ApiResponse<BulkUpsertLocationCustomAttributesResponse>>

Parameters

Parameter Type Tags Description
body BulkUpsertLocationCustomAttributesRequest 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

BulkUpsertLocationCustomAttributesResponse

Example Usage

const body: BulkUpsertLocationCustomAttributesRequest = {
  values: {
    'key0': {
      locationId: 'location_id4',
      customAttribute: {},
    },
    'key1': {
      locationId: 'location_id4',
      customAttribute: {},
    }
  },
};

try {
  const { result, ...httpResponse } = await locationCustomAttributesApi.bulkUpsertLocationCustomAttributes(body);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch (error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}

List Location Custom Attributes

Lists the custom attributes associated with a location. You can use the with_definitions query parameter to also retrieve custom attribute definitions in the same call. When all response pages are retrieved, the results include all custom attributes that are visible to the requesting application, including those that are owned by other applications and set to VISIBILITY_READ_ONLY or VISIBILITY_READ_WRITE_VALUES.

async listLocationCustomAttributes(  locationId: string,
  visibilityFilter?: string,
  limit?: number,
  cursor?: string,
  withDefinitions?: boolean,
requestOptions?: RequestOptions): Promise<ApiResponse<ListLocationCustomAttributesResponse>>

Parameters

Parameter Type Tags Description
locationId string Template, Required The ID of the target location.
visibilityFilter string | undefined Query, Optional Filters the CustomAttributeDefinition results by their visibility values.
limit number | undefined Query, Optional The maximum number of results to return in a single paged response. This limit is advisory.
The response might contain more or fewer results. The minimum value is 1 and the maximum value is 100.
The default value is 20. For more information, see Pagination.
cursor string | undefined Query, Optional The cursor returned in the paged response from the previous call to this endpoint.
Provide this cursor to retrieve the next page of results for your original request. For more
information, see Pagination.
withDefinitions boolean | undefined Query, Optional Indicates whether to return the custom attribute definition in the definition field of each
custom attribute. Set this parameter to true to get the name and description of each custom
attribute, information about the data type, or other definition details. The default value is false.
Default: false
requestOptions RequestOptions | undefined Optional Pass additional request options.

Response Type

ListLocationCustomAttributesResponse

Example Usage

const locationId = 'location_id4';

const withDefinitions = false;

try {
  const { result, ...httpResponse } = await locationCustomAttributesApi.listLocationCustomAttributes(
  locationId,
  undefined,
  undefined,
  undefined,
  withDefinitions
);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch (error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}

Delete Location Custom Attribute

Deletes a custom attribute associated with a location. To delete a custom attribute owned by another application, the visibility setting must be VISIBILITY_READ_WRITE_VALUES.

async deleteLocationCustomAttribute(  locationId: string,
  key: string,
requestOptions?: RequestOptions): Promise<ApiResponse<DeleteLocationCustomAttributeResponse>>

Parameters

Parameter Type Tags Description
locationId string Template, Required The ID of the target location.
key string Template, Required The key of the custom attribute to delete. This key must match the key of a custom
attribute definition in the Square seller account. If the requesting application is not the
definition owner, you must use the qualified key.
requestOptions RequestOptions | undefined Optional Pass additional request options.

Response Type

DeleteLocationCustomAttributeResponse

Example Usage

const locationId = 'location_id4';

const key = 'key0';

try {
  const { result, ...httpResponse } = await locationCustomAttributesApi.deleteLocationCustomAttribute(
  locationId,
  key
);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch (error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}

Retrieve Location Custom Attribute

Retrieves a custom attribute associated with a location. You can use the with_definition query parameter to also retrieve the custom attribute definition in the same call. To retrieve a custom attribute owned by another application, the visibility setting must be VISIBILITY_READ_ONLY or VISIBILITY_READ_WRITE_VALUES.

async retrieveLocationCustomAttribute(  locationId: string,
  key: string,
  withDefinition?: boolean,
  version?: number,
requestOptions?: RequestOptions): Promise<ApiResponse<RetrieveLocationCustomAttributeResponse>>

Parameters

Parameter Type Tags Description
locationId string Template, Required The ID of the target location.
key string Template, Required The key of the custom attribute to retrieve. This key must match the key of a custom
attribute definition in the Square seller account. If the requesting application is not the
definition owner, you must use the qualified key.
withDefinition boolean | undefined Query, Optional Indicates whether to return the custom attribute definition in the definition field of
the custom attribute. Set this parameter to true to get the name and description of the custom
attribute, information about the data type, or other definition details. The default value is false.
Default: false
version number | undefined Query, Optional The current version of the custom attribute, which is used for strongly consistent reads to
guarantee that you receive the most up-to-date data. When included in the request, Square
returns the specified version or a higher version if one exists. If the specified version is
higher than the current version, Square returns a BAD_REQUEST error.
requestOptions RequestOptions | undefined Optional Pass additional request options.

Response Type

RetrieveLocationCustomAttributeResponse

Example Usage

const locationId = 'location_id4';

const key = 'key0';

const withDefinition = false;

try {
  const { result, ...httpResponse } = await locationCustomAttributesApi.retrieveLocationCustomAttribute(
  locationId,
  key,
  withDefinition
);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch (error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}

Upsert Location Custom Attribute

Creates or updates a custom attribute for a location. Use this endpoint to set the value of a custom attribute for a specified location. A custom attribute is based on a custom attribute definition in a Square seller account, which is created using the CreateLocationCustomAttributeDefinition endpoint. To create or update a custom attribute owned by another application, the visibility setting must be VISIBILITY_READ_WRITE_VALUES.

async upsertLocationCustomAttribute(  locationId: string,
  key: string,
  body: UpsertLocationCustomAttributeRequest,
requestOptions?: RequestOptions): Promise<ApiResponse<UpsertLocationCustomAttributeResponse>>

Parameters

Parameter Type Tags Description
locationId string Template, Required The ID of the target location.
key string Template, Required The key of the custom attribute to create or update. This key must match the key of a
custom attribute definition in the Square seller account. If the requesting application is not
the definition owner, you must use the qualified key.
body UpsertLocationCustomAttributeRequest 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

UpsertLocationCustomAttributeResponse

Example Usage

const locationId = 'location_id4';

const key = 'key0';

const body: UpsertLocationCustomAttributeRequest = {
  customAttribute: {},
};

try {
  const { result, ...httpResponse } = await locationCustomAttributesApi.upsertLocationCustomAttribute(
  locationId,
  key,
  body
);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch (error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}