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

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



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/square/api/customer_custom_attributes_api.rb', line 274

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



82
83
84
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
# File 'lib/square/api/customer_custom_attributes_api.rb', line 82

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 associated with a customer profile. To delete a custom attribute owned by another application, the ‘visibility` setting must be `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



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'lib/square/api/customer_custom_attributes_api.rb', line 384

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



120
121
122
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
# File 'lib/square/api/customer_custom_attributes_api.rb', line 120

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



29
30
31
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
# File 'lib/square/api/customer_custom_attributes_api.rb', line 29

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 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). 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 (Boolean) (defaults to: false)

    Optional parameter: Indicates whether to

Returns:

  • (ListCustomerCustomAttributesResponse Hash)

    response from the API call



333
334
335
336
337
338
339
340
341
342
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
# File 'lib/square/api/customer_custom_attributes_api.rb', line 333

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 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`. [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. 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 (Boolean) (defaults to: false)

    Optional parameter: Indicates whether to

  • version (Integer) (defaults to: nil)

    Optional parameter: The current version of the

Returns:

  • (RetrieveCustomerCustomAttributeResponse Hash)

    response from the API call



443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/square/api/customer_custom_attributes_api.rb', line 443

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



166
167
168
169
170
171
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
# File 'lib/square/api/customer_custom_attributes_api.rb', line 166

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



217
218
219
220
221
222
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
# File 'lib/square/api/customer_custom_attributes_api.rb', line 217

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 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`. [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



504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# File 'lib/square/api/customer_custom_attributes_api.rb', line 504

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