-
Notifications
You must be signed in to change notification settings - Fork 48
/
catalog_api.py
745 lines (620 loc) · 27.7 KB
/
catalog_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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
110
111
112
113
114
115
116
117
118
119
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
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
372
373
374
375
376
377
378
379
380
381
382
383
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
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
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
# -*- coding: utf-8 -*-
from square.api_helper import APIHelper
from square.http.api_response import ApiResponse
from square.api.base_api import BaseApi
from square.http.auth.o_auth_2 import OAuth2
class CatalogApi(BaseApi):
"""A Controller to access Endpoints in the square API."""
def __init__(self, config, call_back=None):
super(CatalogApi, self).__init__(config, call_back)
def batch_delete_catalog_objects(self,
body):
"""Does a POST request to /v2/catalog/batch-delete.
Deletes a set of [CatalogItem](#type-catalogitem)s based on the
provided list of target IDs and returns a set of successfully deleted
IDs in
the response. Deletion is a cascading event such that all children of
the
targeted object are also deleted. For example, deleting a CatalogItem
will
also delete all of its
[CatalogItemVariation](#type-catalogitemvariation)
children.
`BatchDeleteCatalogObjects` succeeds even if only a portion of the
targeted
IDs can be deleted. The response will only include IDs that were
actually deleted.
Args:
body (BatchDeleteCatalogObjectsRequest): An object containing the
fields to POST for the request. See the corresponding object
definition for field details.
Returns:
BatchDeleteCatalogObjectsResponse: Response from the API. Success
Raises:
APIException: When an error occurs while fetching the data from
the remote API. This exception includes the HTTP Response
code, an error message, and the HTTP body that was received in
the request.
"""
# Prepare query URL
_url_path = '/v2/catalog/batch-delete'
_query_builder = self.config.get_base_uri()
_query_builder += _url_path
_query_url = APIHelper.clean_url(_query_builder)
# Prepare headers
_headers = {
'accept': 'application/json',
'content-type': 'application/json; charset=utf-8'
}
# Prepare and execute request
_request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
OAuth2.apply(self.config, _request)
_response = self.execute_request(_request)
decoded = APIHelper.json_deserialize(_response.text)
if type(decoded) is dict:
_errors = decoded.get('errors')
else:
_errors = None
_result = ApiResponse(_response, body=decoded, errors=_errors)
return _result
def batch_retrieve_catalog_objects(self,
body):
"""Does a POST request to /v2/catalog/batch-retrieve.
Returns a set of objects based on the provided ID.
Each [CatalogItem](#type-catalogitem) returned in the set includes all
of its
child information including: all of its
[CatalogItemVariation](#type-catalogitemvariation) objects, references
to
its [CatalogModifierList](#type-catalogmodifierlist) objects, and the
ids of
any [CatalogTax](#type-catalogtax) objects that apply to it.
Args:
body (BatchRetrieveCatalogObjectsRequest): An object containing
the fields to POST for the request. See the corresponding
object definition for field details.
Returns:
BatchRetrieveCatalogObjectsResponse: Response from the API.
Success
Raises:
APIException: When an error occurs while fetching the data from
the remote API. This exception includes the HTTP Response
code, an error message, and the HTTP body that was received in
the request.
"""
# Prepare query URL
_url_path = '/v2/catalog/batch-retrieve'
_query_builder = self.config.get_base_uri()
_query_builder += _url_path
_query_url = APIHelper.clean_url(_query_builder)
# Prepare headers
_headers = {
'accept': 'application/json',
'content-type': 'application/json; charset=utf-8'
}
# Prepare and execute request
_request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
OAuth2.apply(self.config, _request)
_response = self.execute_request(_request)
decoded = APIHelper.json_deserialize(_response.text)
if type(decoded) is dict:
_errors = decoded.get('errors')
else:
_errors = None
_result = ApiResponse(_response, body=decoded, errors=_errors)
return _result
def batch_upsert_catalog_objects(self,
body):
"""Does a POST request to /v2/catalog/batch-upsert.
Creates or updates up to 10,000 target objects based on the provided
list of objects. The target objects are grouped into batches and each
batch is
inserted/updated in an all-or-nothing manner. If an object within a
batch is
malformed in some way, or violates a database constraint, the entire
batch
containing that item will be disregarded. However, other batches in
the same
request may still succeed. Each batch may contain up to 1,000 objects,
and
batches will be processed in order as long as the total object count
for the
request (items, variations, modifier lists, discounts, and taxes) is
no more
than 10,000.
Args:
body (BatchUpsertCatalogObjectsRequest): An object containing the
fields to POST for the request. See the corresponding object
definition for field details.
Returns:
BatchUpsertCatalogObjectsResponse: Response from the API. Success
Raises:
APIException: When an error occurs while fetching the data from
the remote API. This exception includes the HTTP Response
code, an error message, and the HTTP body that was received in
the request.
"""
# Prepare query URL
_url_path = '/v2/catalog/batch-upsert'
_query_builder = self.config.get_base_uri()
_query_builder += _url_path
_query_url = APIHelper.clean_url(_query_builder)
# Prepare headers
_headers = {
'accept': 'application/json',
'content-type': 'application/json; charset=utf-8'
}
# Prepare and execute request
_request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
OAuth2.apply(self.config, _request)
_response = self.execute_request(_request)
decoded = APIHelper.json_deserialize(_response.text)
if type(decoded) is dict:
_errors = decoded.get('errors')
else:
_errors = None
_result = ApiResponse(_response, body=decoded, errors=_errors)
return _result
def create_catalog_image(self,
request=None,
image_file=None):
"""Does a POST request to /v2/catalog/images.
Upload an image file to create a new
[CatalogImage](#type-catalogimage) for an existing
[CatalogObject](#type-catalogobject). Images can be uploaded and
linked in this request or created independently
(without an object assignment) and linked to a
[CatalogObject](#type-catalogobject) at a later time.
CreateCatalogImage accepts HTTP multipart/form-data requests with a
JSON part and an image file part in
JPEG, PJPEG, PNG, or GIF format. The maximum file size is 15MB. The
following is an example of such an HTTP request:
```
POST /v2/catalog/images
Accept: application/json
Content-Type: multipart/form-data;boundary="boundary"
Square-Version: XXXX-XX-XX
Authorization: Bearer {ACCESS_TOKEN}
--boundary
Content-Disposition: form-data; name="request"
Content-Type: application/json
{
"idempotency_key":"528dea59-7bfb-43c1-bd48-4a6bba7dd61f86",
"object_id": "ND6EA5AAJEO5WL3JNNIAQA32",
"image":{
"id":"#TEMP_ID",
"type":"IMAGE",
"image_data":{
"caption":"A picture of a cup of coffee"
}
}
}
--boundary
Content-Disposition: form-data; name="image"; filename="Coffee.jpg"
Content-Type: image/jpeg
{ACTUAL_IMAGE_BYTES}
--boundary
```
Additional information and an example cURL request can be found in the
[Create a Catalog Image
recipe](https://developer.squareup.com/docs/more-apis/catalog/cookbook/
create-catalog-images).
Args:
request (CreateCatalogImageRequest, optional): TODO: type
description here.
image_file (string, optional): TODO: type description here.
Returns:
CreateCatalogImageResponse: Response from the API. Success
Raises:
APIException: When an error occurs while fetching the data from
the remote API. This exception includes the HTTP Response
code, an error message, and the HTTP body that was received in
the request.
"""
# Prepare query URL
_url_path = '/v2/catalog/images'
_query_builder = self.config.get_base_uri()
_query_builder += _url_path
_query_url = APIHelper.clean_url(_query_builder)
# Prepare files
_files = {
'request': (None, APIHelper.json_serialize(request), 'application/json; charset=utf-8'),
'image_file': (image_file.name, image_file, 'image/jpeg')
}
# Prepare headers
_headers = {
'accept': 'application/json'
}
# Prepare and execute request
_request = self.config.http_client.post(_query_url, headers=_headers, files=_files)
OAuth2.apply(self.config, _request)
_response = self.execute_request(_request)
decoded = APIHelper.json_deserialize(_response.text)
if type(decoded) is dict:
_errors = decoded.get('errors')
else:
_errors = None
_result = ApiResponse(_response, body=decoded, errors=_errors)
return _result
def catalog_info(self):
"""Does a GET request to /v2/catalog/info.
Returns information about the Square Catalog API, such as batch size
limits for `BatchUpsertCatalogObjects`.
Returns:
CatalogInfoResponse: Response from the API. Success
Raises:
APIException: When an error occurs while fetching the data from
the remote API. This exception includes the HTTP Response
code, an error message, and the HTTP body that was received in
the request.
"""
# Prepare query URL
_url_path = '/v2/catalog/info'
_query_builder = self.config.get_base_uri()
_query_builder += _url_path
_query_url = APIHelper.clean_url(_query_builder)
# Prepare headers
_headers = {
'accept': 'application/json'
}
# Prepare and execute request
_request = self.config.http_client.get(_query_url, headers=_headers)
OAuth2.apply(self.config, _request)
_response = self.execute_request(_request)
decoded = APIHelper.json_deserialize(_response.text)
if type(decoded) is dict:
_errors = decoded.get('errors')
else:
_errors = None
_result = ApiResponse(_response, body=decoded, errors=_errors)
return _result
def list_catalog(self,
cursor=None,
types=None):
"""Does a GET request to /v2/catalog/list.
Returns a list of [CatalogObject](#type-catalogobject)s that includes
all objects of a set of desired types (for example, all
[CatalogItem](#type-catalogitem)
and [CatalogTax](#type-catalogtax) objects) in the catalog. The
`types` parameter
is specified as a comma-separated list of valid
[CatalogObject](#type-catalogobject) types:
`ITEM`, `ITEM_VARIATION`, `MODIFIER`, `MODIFIER_LIST`, `CATEGORY`,
`DISCOUNT`, `TAX`, `IMAGE`.
__Important:__ ListCatalog does not return deleted catalog items. To
retrieve
deleted catalog items, use SearchCatalogObjects and set
`include_deleted_objects`
to `true`.
Args:
cursor (string, optional): The pagination cursor returned in the
previous response. Leave unset for an initial request. See
[Pagination](https://developer.squareup.com/docs/basics/api101/
pagination) for more information.
types (string, optional): An optional case-insensitive,
comma-separated list of object types to retrieve, for example
`ITEM,ITEM_VARIATION,CATEGORY,IMAGE`. The legal values are
taken from the CatalogObjectType enum: `ITEM`,
`ITEM_VARIATION`, `CATEGORY`, `DISCOUNT`, `TAX`, `MODIFIER`,
`MODIFIER_LIST`, or `IMAGE`.
Returns:
ListCatalogResponse: Response from the API. Success
Raises:
APIException: When an error occurs while fetching the data from
the remote API. This exception includes the HTTP Response
code, an error message, and the HTTP body that was received in
the request.
"""
# Prepare query URL
_url_path = '/v2/catalog/list'
_query_builder = self.config.get_base_uri()
_query_builder += _url_path
_query_parameters = {
'cursor': cursor,
'types': types
}
_query_builder = APIHelper.append_url_with_query_parameters(
_query_builder,
_query_parameters
)
_query_url = APIHelper.clean_url(_query_builder)
# Prepare headers
_headers = {
'accept': 'application/json'
}
# Prepare and execute request
_request = self.config.http_client.get(_query_url, headers=_headers)
OAuth2.apply(self.config, _request)
_response = self.execute_request(_request)
decoded = APIHelper.json_deserialize(_response.text)
if type(decoded) is dict:
_errors = decoded.get('errors')
else:
_errors = None
_result = ApiResponse(_response, body=decoded, errors=_errors)
return _result
def upsert_catalog_object(self,
body):
"""Does a POST request to /v2/catalog/object.
Creates or updates the target [CatalogObject](#type-catalogobject).
Args:
body (UpsertCatalogObjectRequest): An object containing the fields
to POST for the request. See the corresponding object
definition for field details.
Returns:
UpsertCatalogObjectResponse: Response from the API. Success
Raises:
APIException: When an error occurs while fetching the data from
the remote API. This exception includes the HTTP Response
code, an error message, and the HTTP body that was received in
the request.
"""
# Prepare query URL
_url_path = '/v2/catalog/object'
_query_builder = self.config.get_base_uri()
_query_builder += _url_path
_query_url = APIHelper.clean_url(_query_builder)
# Prepare headers
_headers = {
'accept': 'application/json',
'content-type': 'application/json; charset=utf-8'
}
# Prepare and execute request
_request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
OAuth2.apply(self.config, _request)
_response = self.execute_request(_request)
decoded = APIHelper.json_deserialize(_response.text)
if type(decoded) is dict:
_errors = decoded.get('errors')
else:
_errors = None
_result = ApiResponse(_response, body=decoded, errors=_errors)
return _result
def delete_catalog_object(self,
object_id):
"""Does a DELETE request to /v2/catalog/object/{object_id}.
Deletes a single [CatalogObject](#type-catalogobject) based on the
provided ID and returns the set of successfully deleted IDs in the
response.
Deletion is a cascading event such that all children of the targeted
object
are also deleted. For example, deleting a
[CatalogItem](#type-catalogitem)
will also delete all of its
[CatalogItemVariation](#type-catalogitemvariation) children.
Args:
object_id (string): The ID of the catalog object to be deleted.
When an object is deleted, other objects in the graph that
depend on that object will be deleted as well (for example,
deleting a catalog item will delete its catalog item
variations).
Returns:
DeleteCatalogObjectResponse: Response from the API. Success
Raises:
APIException: When an error occurs while fetching the data from
the remote API. This exception includes the HTTP Response
code, an error message, and the HTTP body that was received in
the request.
"""
# Prepare query URL
_url_path = '/v2/catalog/object/{object_id}'
_url_path = APIHelper.append_url_with_template_parameters(_url_path, {
'object_id': object_id
})
_query_builder = self.config.get_base_uri()
_query_builder += _url_path
_query_url = APIHelper.clean_url(_query_builder)
# Prepare headers
_headers = {
'accept': 'application/json'
}
# Prepare and execute request
_request = self.config.http_client.delete(_query_url, headers=_headers)
OAuth2.apply(self.config, _request)
_response = self.execute_request(_request)
decoded = APIHelper.json_deserialize(_response.text)
if type(decoded) is dict:
_errors = decoded.get('errors')
else:
_errors = None
_result = ApiResponse(_response, body=decoded, errors=_errors)
return _result
def retrieve_catalog_object(self,
object_id,
include_related_objects=None):
"""Does a GET request to /v2/catalog/object/{object_id}.
Returns a single [CatalogItem](#type-catalogitem) as a
[CatalogObject](#type-catalogobject) based on the provided ID. The
returned
object includes all of the relevant [CatalogItem](#type-catalogitem)
information including:
[CatalogItemVariation](#type-catalogitemvariation)
children, references to its
[CatalogModifierList](#type-catalogmodifierlist) objects, and the ids
of
any [CatalogTax](#type-catalogtax) objects that apply to it.
Args:
object_id (string): The object ID of any type of catalog objects
to be retrieved.
include_related_objects (bool, optional): If `true`, the response
will include additional objects that are related to the
requested object, as follows: If the `object` field of the
response contains a CatalogItem, its associated
CatalogCategory, CatalogTax objects, CatalogImages and
CatalogModifierLists will be returned in the `related_objects`
field of the response. If the `object` field of the response
contains a CatalogItemVariation, its parent CatalogItem will
be returned in the `related_objects` field of the response.
Default value: `false`
Returns:
RetrieveCatalogObjectResponse: Response from the API. Success
Raises:
APIException: When an error occurs while fetching the data from
the remote API. This exception includes the HTTP Response
code, an error message, and the HTTP body that was received in
the request.
"""
# Prepare query URL
_url_path = '/v2/catalog/object/{object_id}'
_url_path = APIHelper.append_url_with_template_parameters(_url_path, {
'object_id': object_id
})
_query_builder = self.config.get_base_uri()
_query_builder += _url_path
_query_parameters = {
'include_related_objects': include_related_objects
}
_query_builder = APIHelper.append_url_with_query_parameters(
_query_builder,
_query_parameters
)
_query_url = APIHelper.clean_url(_query_builder)
# Prepare headers
_headers = {
'accept': 'application/json'
}
# Prepare and execute request
_request = self.config.http_client.get(_query_url, headers=_headers)
OAuth2.apply(self.config, _request)
_response = self.execute_request(_request)
decoded = APIHelper.json_deserialize(_response.text)
if type(decoded) is dict:
_errors = decoded.get('errors')
else:
_errors = None
_result = ApiResponse(_response, body=decoded, errors=_errors)
return _result
def search_catalog_objects(self,
body):
"""Does a POST request to /v2/catalog/search.
Queries the targeted catalog using a variety of query types:
[CatalogQuerySortedAttribute](#type-catalogquerysortedattribute),
[CatalogQueryExact](#type-catalogqueryexact),
[CatalogQueryRange](#type-catalogqueryrange),
[CatalogQueryText](#type-catalogquerytext),
[CatalogQueryItemsForTax](#type-catalogqueryitemsfortax), and
[CatalogQueryItemsForModifierList](#type-catalogqueryitemsformodifierli
st).
--
--
Future end of the above comment:
[CatalogQueryItemsForTax](#type-catalogqueryitemsfortax),
[CatalogQueryItemsForModifierList](#type-catalogqueryitemsformodifierli
st),
[CatalogQueryItemsForItemOptions](#type-catalogqueryitemsforitemoptions
), and
[CatalogQueryItemVariationsForItemOptionValues](#type-catalogqueryitemv
ariationsforitemoptionvalues).
Args:
body (SearchCatalogObjectsRequest): An object containing the
fields to POST for the request. See the corresponding object
definition for field details.
Returns:
SearchCatalogObjectsResponse: Response from the API. Success
Raises:
APIException: When an error occurs while fetching the data from
the remote API. This exception includes the HTTP Response
code, an error message, and the HTTP body that was received in
the request.
"""
# Prepare query URL
_url_path = '/v2/catalog/search'
_query_builder = self.config.get_base_uri()
_query_builder += _url_path
_query_url = APIHelper.clean_url(_query_builder)
# Prepare headers
_headers = {
'accept': 'application/json',
'content-type': 'application/json; charset=utf-8'
}
# Prepare and execute request
_request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
OAuth2.apply(self.config, _request)
_response = self.execute_request(_request)
decoded = APIHelper.json_deserialize(_response.text)
if type(decoded) is dict:
_errors = decoded.get('errors')
else:
_errors = None
_result = ApiResponse(_response, body=decoded, errors=_errors)
return _result
def update_item_modifier_lists(self,
body):
"""Does a POST request to /v2/catalog/update-item-modifier-lists.
Updates the [CatalogModifierList](#type-catalogmodifierlist) objects
that apply to the targeted [CatalogItem](#type-catalogitem) without
having
to perform an upsert on the entire item.
Args:
body (UpdateItemModifierListsRequest): An object containing the
fields to POST for the request. See the corresponding object
definition for field details.
Returns:
UpdateItemModifierListsResponse: Response from the API. Success
Raises:
APIException: When an error occurs while fetching the data from
the remote API. This exception includes the HTTP Response
code, an error message, and the HTTP body that was received in
the request.
"""
# Prepare query URL
_url_path = '/v2/catalog/update-item-modifier-lists'
_query_builder = self.config.get_base_uri()
_query_builder += _url_path
_query_url = APIHelper.clean_url(_query_builder)
# Prepare headers
_headers = {
'accept': 'application/json',
'content-type': 'application/json; charset=utf-8'
}
# Prepare and execute request
_request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
OAuth2.apply(self.config, _request)
_response = self.execute_request(_request)
decoded = APIHelper.json_deserialize(_response.text)
if type(decoded) is dict:
_errors = decoded.get('errors')
else:
_errors = None
_result = ApiResponse(_response, body=decoded, errors=_errors)
return _result
def update_item_taxes(self,
body):
"""Does a POST request to /v2/catalog/update-item-taxes.
Updates the [CatalogTax](#type-catalogtax) objects that apply to the
targeted [CatalogItem](#type-catalogitem) without having to perform
an
upsert on the entire item.
Args:
body (UpdateItemTaxesRequest): An object containing the fields to
POST for the request. See the corresponding object definition
for field details.
Returns:
UpdateItemTaxesResponse: Response from the API. Success
Raises:
APIException: When an error occurs while fetching the data from
the remote API. This exception includes the HTTP Response
code, an error message, and the HTTP body that was received in
the request.
"""
# Prepare query URL
_url_path = '/v2/catalog/update-item-taxes'
_query_builder = self.config.get_base_uri()
_query_builder += _url_path
_query_url = APIHelper.clean_url(_query_builder)
# Prepare headers
_headers = {
'accept': 'application/json',
'content-type': 'application/json; charset=utf-8'
}
# Prepare and execute request
_request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
OAuth2.apply(self.config, _request)
_response = self.execute_request(_request)
decoded = APIHelper.json_deserialize(_response.text)
if type(decoded) is dict:
_errors = decoded.get('errors')
else:
_errors = None
_result = ApiResponse(_response, body=decoded, errors=_errors)
return _result