Class: Square::CustomerCustomAttributesApi

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/square/api/customer_custom_attributes_api.rb

Overview

CustomerCustomAttributesApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#execute_request, #get_user_agent, #validate_parameters, #validate_parameters_types

Constructor Details

#initialize(config, http_call_back: nil) ⇒ CustomerCustomAttributesApi

Returns a new instance of CustomerCustomAttributesApi.



4
5
6
# File 'lib/square/api/customer_custom_attributes_api.rb', line 4

def initialize(config, http_call_back: nil)
  super(config, http_call_back: http_call_back)
end

Instance Method Details

#bulk_upsert_customer_custom_attributes(body:) ⇒ BulkUpsertCustomerCustomAttributesResponse Hash

Creates or updates [custom attributes]($m/CustomAttribute) for customer profiles as a bulk operation. Use this endpoint to set the value of one or more custom attributes for one or more customer profiles. A custom attribute is based on a custom attribute definition in a Square seller account, which is created using the [CreateCustomerCustomAttributeDefinition]($e/CustomerCustomAttributes/Crea teCustomerCustomAttributeDefinition) endpoint. This `BulkUpsertCustomerCustomAttributes` 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 customer 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`. Note that seller-defined custom attributes (also known as custom fields) are always set to `VISIBILITY_READ_WRITE_VALUES`. parameter: An object containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (BulkUpsertCustomerCustomAttributesRequest)

    Required

Returns:

  • (BulkUpsertCustomerCustomAttributesResponse Hash)

    response from the API call



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/square/api/customer_custom_attributes_api.rb', line 283

def bulk_upsert_customer_custom_attributes(body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/custom-attributes/bulk-upsert'
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#create_customer_custom_attribute_definition(body:) ⇒ CreateCustomerCustomAttributeDefinitionResponse Hash

Creates a customer-related [custom attribute definition]($m/CustomAttributeDefinition) for a Square seller account. Use this endpoint to define a custom attribute that can be associated with customer profiles. A custom attribute definition specifies the `key`, `visibility`, `schema`, and other properties for a custom attribute. After the definition is created, you can call [UpsertCustomerCustomAttribute]($e/CustomerCustomAttributes/UpsertCustomer CustomAttribute) or [BulkUpsertCustomerCustomAttributes]($e/CustomerCustomAttributes/BulkUpser tCustomerCustomAttributes) to set the custom attribute for customer profiles in the seller's Customer Directory. Sellers can view all custom attributes in exported customer data, including those set to `VISIBILITY_HIDDEN`. parameter: An object containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (CreateCustomerCustomAttributeDefinitionRequest)

    Required

Returns:

  • (CreateCustomerCustomAttributeDefinitionResponse Hash)

    response from the API call



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/square/api/customer_custom_attributes_api.rb', line 85

def create_customer_custom_attribute_definition(body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/custom-attribute-definitions'
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#delete_customer_custom_attribute(customer_id:, key:) ⇒ DeleteCustomerCustomAttributeResponse Hash

Deletes a [custom attribute]($m/CustomAttribute) associated with a customer profile. To delete a custom attribute owned by another application, the `visibility` setting must be `VISIBILITY_READ_WRITE_VALUES`. Note that seller-defined custom attributes (also known as custom fields) are always set to `VISIBILITY_READ_WRITE_VALUES`. [customer profile]($m/Customer). 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.

Parameters:

  • customer_id (String)

    Required parameter: The ID of the target

  • key (String)

    Required parameter: The key of the custom attribute to

Returns:

  • (DeleteCustomerCustomAttributeResponse Hash)

    response from the API call



397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/square/api/customer_custom_attributes_api.rb', line 397

def delete_customer_custom_attribute(customer_id:,
                                     key:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/{customer_id}/custom-attributes/{key}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'customer_id' => { 'value' => customer_id, 'encode' => true },
    'key' => { 'value' => key, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.delete(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#delete_customer_custom_attribute_definition(key:) ⇒ DeleteCustomerCustomAttributeDefinitionResponse Hash

Deletes a customer-related [custom attribute definition]($m/CustomAttributeDefinition) from a Square seller account. Deleting a custom attribute definition also deletes the corresponding custom attribute from all customer profiles in the seller's Customer Directory. Only the definition owner can delete a custom attribute definition. definition to delete.

Parameters:

  • key (String)

    Required parameter: The key of the custom attribute

Returns:

  • (DeleteCustomerCustomAttributeDefinitionResponse Hash)

    response from the API call



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/square/api/customer_custom_attributes_api.rb', line 123

def delete_customer_custom_attribute_definition(key:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/custom-attribute-definitions/{key}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'key' => { 'value' => key, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.delete(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#list_customer_custom_attribute_definitions(limit: nil, cursor: nil) ⇒ ListCustomerCustomAttributeDefinitionsResponse Hash

Lists the customer-related [custom attribute definitions]($m/CustomAttributeDefinition) 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`. Note that seller-defined custom attributes (also known as custom fields) are always set to `VISIBILITY_READ_WRITE_VALUES`. 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](developer.squareup.com/docs/build-basics/common-api-p atterns/pagination). 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](developer.squareup.com/docs/build-basics/common-api-p atterns/pagination).

Parameters:

  • limit (Integer) (defaults to: nil)

    Optional parameter: The maximum number of results

  • cursor (String) (defaults to: nil)

    Optional parameter: The cursor returned in the

Returns:

  • (ListCustomerCustomAttributeDefinitionsResponse Hash)

    response from the API call



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/square/api/customer_custom_attributes_api.rb', line 32

def list_customer_custom_attribute_definitions(limit: nil,
                                               cursor: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/custom-attribute-definitions'
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    'limit' => limit,
    'cursor' => cursor
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#list_customer_custom_attributes(customer_id:, limit: nil, cursor: nil, with_definitions: false) ⇒ ListCustomerCustomAttributesResponse Hash

Lists the [custom attributes]($m/CustomAttribute) associated with a customer profile. 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`. [customer profile]($m/Customer). 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](developer.squareup.com/docs/build-basics/common-api-p atterns/pagination). 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](developer.squareup.com/docs/build-basics/common-api-p atterns/pagination). Indicates whether to return the [custom attribute definition]($m/CustomAttributeDefinition) 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`.

Parameters:

  • customer_id (String)

    Required parameter: The ID of the target

  • limit (Integer) (defaults to: nil)

    Optional parameter: The maximum number of results

  • cursor (String) (defaults to: nil)

    Optional parameter: The cursor returned in the

  • with_definitions (TrueClass|FalseClass) (defaults to: false)

    Optional parameter:

Returns:

  • (ListCustomerCustomAttributesResponse Hash)

    response from the API call



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/square/api/customer_custom_attributes_api.rb', line 343

def list_customer_custom_attributes(customer_id:,
                                    limit: nil,
                                    cursor: nil,
                                    with_definitions: false)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/{customer_id}/custom-attributes'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'customer_id' => { 'value' => customer_id, 'encode' => true }
  )
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    'limit' => limit,
    'cursor' => cursor,
    'with_definitions' => with_definitions
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#retrieve_customer_custom_attribute(customer_id:, key:, with_definition: false, version: nil) ⇒ RetrieveCustomerCustomAttributeResponse Hash

Retrieves a [custom attribute]($m/CustomAttribute) associated with a customer profile. 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`. Note that seller-defined custom attributes (also known as custom fields) are always set to `VISIBILITY_READ_WRITE_VALUES`. [customer profile]($m/Customer). 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. Indicates whether to return the [custom attribute definition]($m/CustomAttributeDefinition) 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`. 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.

Parameters:

  • customer_id (String)

    Required parameter: The ID of the target

  • key (String)

    Required parameter: The key of the custom attribute to

  • with_definition (TrueClass|FalseClass) (defaults to: false)

    Optional parameter:

  • version (Integer) (defaults to: nil)

    Optional parameter: The current version of the

Returns:

  • (RetrieveCustomerCustomAttributeResponse Hash)

    response from the API call



460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/square/api/customer_custom_attributes_api.rb', line 460

def retrieve_customer_custom_attribute(customer_id:,
                                       key:,
                                       with_definition: false,
                                       version: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/{customer_id}/custom-attributes/{key}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'customer_id' => { 'value' => customer_id, 'encode' => true },
    'key' => { 'value' => key, 'encode' => true }
  )
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    'with_definition' => with_definition,
    'version' => version
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#retrieve_customer_custom_attribute_definition(key:, version: nil) ⇒ RetrieveCustomerCustomAttributeDefinitionResponse Hash

Retrieves a customer-related [custom attribute definition]($m/CustomAttributeDefinition) 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`. Note that seller-defined custom attributes (also known as custom fields) are always set to `VISIBILITY_READ_WRITE_VALUES`. definition to retrieve. If the requesting application is not the definition owner, you must use the qualified key. 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.

Parameters:

  • key (String)

    Required parameter: The key of the custom attribute

  • version (Integer) (defaults to: nil)

    Optional parameter: The current version of the

Returns:

  • (RetrieveCustomerCustomAttributeDefinitionResponse Hash)

    response from the API call



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/square/api/customer_custom_attributes_api.rb', line 172

def retrieve_customer_custom_attribute_definition(key:,
                                                  version: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/custom-attribute-definitions/{key}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'key' => { 'value' => key, 'encode' => true }
  )
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    'version' => version
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#update_customer_custom_attribute_definition(key:, body:) ⇒ UpdateCustomerCustomAttributeDefinitionResponse Hash

Updates a customer-related [custom attribute definition]($m/CustomAttributeDefinition) 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. Note that sellers can view all custom attributes in exported customer data, including those set to `VISIBILITY_HIDDEN`. definition to update. parameter: An object containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • key (String)

    Required parameter: The key of the custom attribute

  • body (UpdateCustomerCustomAttributeDefinitionRequest)

    Required

Returns:

  • (UpdateCustomerCustomAttributeDefinitionResponse Hash)

    response from the API call



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/square/api/customer_custom_attributes_api.rb', line 223

def update_customer_custom_attribute_definition(key:,
                                                body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/custom-attribute-definitions/{key}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'key' => { 'value' => key, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.put(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#upsert_customer_custom_attribute(customer_id:, key:, body:) ⇒ UpsertCustomerCustomAttributeResponse Hash

Creates or updates a [custom attribute]($m/CustomAttribute) for a customer profile. Use this endpoint to set the value of a custom attribute for a specified customer profile. A custom attribute is based on a custom attribute definition in a Square seller account, which is created using the [CreateCustomerCustomAttributeDefinition]($e/CustomerCustomAttributes/Crea teCustomerCustomAttributeDefinition) endpoint. To create or update a custom attribute owned by another application, the `visibility` setting must be `VISIBILITY_READ_WRITE_VALUES`. Note that seller-defined custom attributes (also known as custom fields) are always set to `VISIBILITY_READ_WRITE_VALUES`. [customer profile]($m/Customer). 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. object containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • customer_id (String)

    Required parameter: The ID of the target

  • key (String)

    Required parameter: The key of the custom attribute to

  • body (UpsertCustomerCustomAttributeRequest)

    Required parameter: An

Returns:

  • (UpsertCustomerCustomAttributeResponse Hash)

    response from the API call



525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
# File 'lib/square/api/customer_custom_attributes_api.rb', line 525

def upsert_customer_custom_attribute(customer_id:,
                                     key:,
                                     body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/customers/{customer_id}/custom-attributes/{key}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'customer_id' => { 'value' => customer_id, 'encode' => true },
    'key' => { 'value' => key, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end