Skip to content

Commit 87e332d

Browse files
committed
v0.2.9
1 parent 86d0910 commit 87e332d

14 files changed

Lines changed: 784 additions & 128 deletions

File tree

ad_api/api/eligibility.py

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse
1+
from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse, Utils
2+
import json
3+
import logging
24

35
class Eligibility(Client):
6+
r"""
7+
Check advertising eligibility of products.
8+
"""
49

510
@sp_endpoint('/eligibility/product/list', method='POST')
611
def get_eligibility(self, **kwargs) -> ApiResponse:
712
r"""
813
9-
get_eligibility(self, **kwargs) -> ApiResponse
14+
get_eligibility(body: (dict, str)) -> ApiResponse
1015
11-
Gets advertising eligibility status for a list of products.
16+
Gets a list of advertising eligibility objects for a set of products. Requests are permitted only for products sold by the merchant associated with the profile. Note that the request object is a list of ASINs, but multiple SKUs are returned if there is more than one SKU associated with an ASIN. If a product is not eligible for advertising, the response includes an object describing the reasons for ineligibility.
1217
1318
body: | REQUIRED
1419
@@ -23,4 +28,47 @@ def get_eligibility(self, **kwargs) -> ApiResponse:
2328
ApiResponse
2429
2530
"""
26-
return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs)
31+
body = Utils.convert_body(kwargs.pop('body'), wrap=False)
32+
return self._request(kwargs.pop('path'), data=body, params=kwargs)
33+
34+
35+
@sp_endpoint('/eligibility/product/list', method='POST')
36+
def get_eligibility_assistant(self, asin_list: list, sku_list: list = None, ad_type: str = "sp", locale:str = "en-GB", **kwargs) -> ApiResponse:
37+
r"""
38+
39+
get_eligibility_assistant(asin_list: list, sku_list: list = None, ad_type: str = "sp", locale:str = "en-GB") -> ApiResponse
40+
41+
Gets a list of advertising eligibility objects for a set of products. Requests are permitted only for products sold by the merchant associated with the profile. Note that the request object is a list of ASINs, but multiple SKUs are returned if there is more than one SKU associated with an ASIN. If a product is not eligible for advertising, the response includes an object describing the reasons for ineligibility.
42+
43+
| **asin_list**: 'A list of ASIN: An Amazon product identifier.'
44+
| **sku_list**: 'A list of SKU: A seller product identifier'
45+
| **adType**: *string*, {'description': 'Set to 'sp' to check product eligibility for Sponsored Products advertisements. Set to 'sb' to check product eligibility for Sponsored Brands advertisements. default: sp. [ sp, sb ]'}
46+
| **locale**': *string*, {'description': 'Set to the locale string in the table below to specify the language in which the response is returned. default: en_GB'}
47+
48+
Returns:
49+
50+
ApiResponse
51+
52+
"""
53+
54+
asin_dict = []
55+
56+
required = {}
57+
required.update({'adType': ad_type})
58+
59+
if len(asin_list) > 0 and isinstance(sku_list, str) or sku_list is None:
60+
for asin in asin_list:
61+
asin_dict.append({'asin': asin})
62+
63+
if sku_list is not None and isinstance(sku_list, list):
64+
if len(asin_list) == len(sku_list):
65+
for i in range(len(asin_list)):
66+
asin_dict.append({'asin': asin_list[i], 'sku': sku_list[i]})
67+
else:
68+
logging.error("No coinciden las listas")
69+
70+
required.update({'productDetailsList': asin_dict})
71+
required.update({'locale': locale})
72+
73+
data_str = json.dumps(required)
74+
return self._request(kwargs.pop('path'), data=data_str, params=kwargs)

ad_api/api/invoices.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ class Invoices(Client):
66
def list_invoices(self, **kwargs) -> ApiResponse:
77
r"""
88
9-
list_invoices(self, **kwargs) -> ApiResponse
9+
list_invoices(**kwargs) -> ApiResponse
1010
1111
Get invoices for advertiser. Requires one of these permissions: ["nemo_transactions_view","nemo_transactions_edit"]
1212
13-
query **invoiceStatuses**:*string* | Optional. Available values : ISSUED, PAID_IN_PART, PAID_IN_FULL, WRITTEN_OFF.
13+
query **invoiceStatuses**:*string* | Optional. Available values : ISSUED, PAID_IN_PART, PAID_IN_FULL, WRITTEN_OFF. (Not documented: ACCUMULATING)
14+
1415
query **count**:*string* | Optional. Number of records to include in the paged response. Defaults to 100. Cannot be combined with the cursor parameter.
16+
1517
query **cursor**:*string* | Optional. A cursor representing how far into a result set this query should begin. In the absence of a cursor the request will default to start index of 0 and page size of 100.
1618
1719
@@ -26,11 +28,11 @@ def list_invoices(self, **kwargs) -> ApiResponse:
2628
def get_invoice(self, invoiceId, **kwargs) -> ApiResponse:
2729
r"""
2830
29-
get_invoice(self, invoiceId, **kwargs) -> ApiResponse
31+
get_invoice(invoiceId: str) -> ApiResponse
3032
3133
Get invoice data by invoice ID. Requires one of these permissions: ["nemo_transactions_view","nemo_transactions_edit"]
3234
33-
path **invoiceId**:*string* | Optional. Available values : ISSUED, PAID_IN_PART, PAID_IN_FULL, WRITTEN_OFF.
35+
path **invoiceId**:*string* | required. ID of invoice to fetch
3436
3537
Returns:
3638

ad_api/api/metadata.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse
1+
from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse, Utils
22

33
class Metadata(Client):
4+
r"""
5+
The Amazon Product Selector API allows integrators to receive product metadata such as inventory status, price, eligibility status and product details for SKUS or ASINs in their Product Catalog in order to launch, manage or optimize Sponsored Product, Sponsored Brands or Sponsored Display advertising campaigns. The Product Selector API is available to Sellers, Vendors, and Authors.
6+
"""
47

58
@sp_endpoint('/product/metadata', method='POST')
69
def get_products_metadata(self, **kwargs) -> ApiResponse:
710
r"""
811
9-
get_products_metadata(self, **kwargs) -> ApiResponse
12+
get_products_metadata(body: (dict, str)) -> ApiResponse
1013
1114
Returns product metadata for the advertiser.
1215
@@ -41,4 +44,7 @@ def get_products_metadata(self, **kwargs) -> ApiResponse:
4144
ApiResponse
4245
4346
"""
44-
return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs)
47+
contentType = 'application/vnd.productmetadatarequest.v1+json'
48+
headers = {'Content-Type': contentType}
49+
body = Utils.convert_body(kwargs.pop('body'), wrap=False)
50+
return self._request(kwargs.pop('path'), data=body, params=kwargs, headers=headers)

ad_api/api/profiles.py

Lines changed: 106 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse
1+
from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse, Utils
2+
import json
23

34
class Profiles(Client):
4-
"""
5-
Profiles AD-API Client
6-
:link:
7-
With the Profiles.
8-
"""
95

106
@sp_endpoint('/v2/profiles', method='GET')
117
def list_profiles(self, **kwargs) -> ApiResponse:
@@ -31,29 +27,65 @@ def list_profiles(self, **kwargs) -> ApiResponse:
3127
"""
3228
return self._request(kwargs.pop('path'), params=kwargs)
3329

30+
31+
@sp_endpoint('/v2/profiles', method='PUT')
32+
def update_single_profile_assistant(self, profile_id: int, daily_budget: int, **kwargs) -> ApiResponse:
33+
r"""
34+
update_single_profile_assistant(profile_id: int, daily_budget: int, **kwargs) -> ApiResponse
35+
36+
Update the daily budget for one or more profiles. Note that this operation is only used for Sellers using Sponsored Products.
37+
38+
'**profile_id**': *integer($int64)* | required {'description': 'The identifier of the profile.'}
39+
40+
'**daily_budget**': *number*, | required {'description': 'Note that this field applies to Sponsored Product campaigns for seller type accounts only. Not supported for vendor type accounts.'}
41+
42+
'**\*\*kwargs**': You can add other keyword args like the original method (countryCode, currencyCode, timezone, accountInfo{}) but as they are read-only if you try to modify will get INVALID_ARGUMENT: Cannot modify "value" for profile
43+
Returns:
44+
45+
ApiResponse
46+
47+
"""
48+
49+
required = \
50+
{
51+
'profileId': profile_id,
52+
'dailyBudget': daily_budget,
53+
}
54+
55+
options = {}
56+
options.update({'path': kwargs.pop("path")})
57+
options.update({'method': kwargs.pop("method")})
58+
59+
required.update(kwargs)
60+
61+
data_str = json.dumps([required])
62+
return self._request(options.pop('path'), data=data_str, params=options)
63+
64+
3465
@sp_endpoint('/v2/profiles', method='PUT')
3566
def update_profile(self, **kwargs) -> ApiResponse:
3667
r"""
3768
38-
update_profile(self, **kwargs) -> ApiResponse
69+
update_profile(body: (dict, list, str)) -> ApiResponse
3970
4071
Update the daily budget for one or more profiles. Note that this operation is only used for Sellers using Sponsored Products.
4172
4273
body: | REQUIRED {'description': 'An array of ad groups.}'
4374
44-
| '**profileId**': *integer($int64)*, {'description': 'The identifier of the profile.'}
45-
| '**countryCode**': *string*, {'description': 'The countryCode for a given country'}
46-
| '**currencyCode**': *string*, {'description': 'The currency used for all monetary values for entities under this profile.'}
47-
| '**dailyBudget**': *number*, {'description': 'Note that this field applies to Sponsored Product campaigns for seller type accounts only. Not supported for vendor type accounts.'}
48-
| '**timezone**': *string*, {'description': 'The time zone used for all date-based campaign management and reporting.'}
49-
| '**accountInfo**': *AccountInfoAccountInfo*, {}
75+
| '**profileId**': *integer($int64)* | required {'description': 'The identifier of the profile.'}
76+
| '**countryCode**': *string* | readOnly {'description': 'The countryCode for a given country'}
77+
| '**currencyCode**': *string* | readOnly {'description': 'The currency used for all monetary values for entities under this profile.'}
78+
| '**dailyBudget**': *number* | required {'description': 'Note that this field applies to Sponsored Product campaigns for seller type accounts only. Not supported for vendor type accounts.'}
79+
| '**timezone**': *string* | readOnly {'description': 'The time zone used for all date-based campaign management and reporting.'}
80+
| '**accountInfo**': *AccountInfoAccountInfo* | readOnly {}
5081
5182
Returns:
5283
5384
ApiResponse
5485
5586
"""
56-
return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs)
87+
body = Utils.convert_body(kwargs.pop('body'))
88+
return self._request(kwargs.pop('path'), data=body, params=kwargs)
5789

5890
@sp_endpoint('/v2/profiles/{}', method='GET')
5991
def get_profile(self, profileId, **kwargs) -> ApiResponse:
@@ -74,43 +106,90 @@ def get_profile(self, profileId, **kwargs) -> ApiResponse:
74106
return self._request(fill_query_params(kwargs.pop('path'), profileId), params=kwargs)
75107

76108

109+
@sp_endpoint('/v2/profiles/registerBrand', method='PUT')
110+
def register_brand_assistant(self, country_code:str, brand:str, **kwargs) -> ApiResponse:
111+
r"""
112+
register_brand_assistant(country_code:str, brand:str) -> ApiResponse
113+
114+
SANDBOX ONLY - Create a vendor profile for sandbox.
115+
116+
| '**country_code**': *string*, {'description': 'The countryCode for a given country'}
117+
| '**brand**': *string*, {'description': 'The brand for the vendor account'}
118+
119+
120+
Returns:
121+
122+
ApiResponse
123+
124+
"""
125+
body = \
126+
{
127+
'countryCode': country_code,
128+
'brand': brand
129+
}
130+
131+
data_str = json.dumps(body)
132+
return self._request(kwargs.pop('path'), data=data_str, params=kwargs)
133+
77134
@sp_endpoint('/v2/profiles/registerBrand', method='PUT')
78135
def register_brand(self, **kwargs) -> ApiResponse:
79136
r"""
80137
81-
register_brand(self, **kwargs) -> ApiResponse
138+
register_brand(body: dict) -> ApiResponse
82139
83140
SANDBOX ONLY - Create a vendor profile for sandbox.
84141
85142
body: | REQUIRED
86-
87-
'**countryCode**': *string*, {'description': 'The countryCode for a given country'}
88-
'**brand**': *string*, {'description': 'The brand for the vendor account'}
143+
| {
144+
| '**countryCode**': *string*, {'description': 'The countryCode for a given country'}
145+
| '**brand**': *string*, {'description': 'The brand for the vendor account'}
146+
| }
89147
90148
91149
Returns:
92150
93151
ApiResponse
94152
95153
"""
96-
return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs)
154+
body = Utils.convert_body(kwargs.pop('body'), wrap=False)
155+
return self._request(kwargs.pop('path'), data=body, params=kwargs)
97156

98157
@sp_endpoint('/v2/profiles/register', method='PUT')
99-
def register(self, **kwargs) -> ApiResponse:
158+
def register_assistant(self, country_code: str, **kwargs) -> ApiResponse:
100159
r"""
101-
102-
register_brand(self, \*\*kwargs) -> ApiResponse
160+
register_assistant(country_code: str) -> ApiResponse
103161
104162
SANDBOX ONLY - Create a seller profile for sandbox.
105163
106-
body: REQUIRED
107-
108-
'**countryCode**': *string*, {'description': 'The countryCode for a given country'}
109-
164+
'**countryCode**': *string*, {'description': 'The countryCode for a given country: [ US, CA, MX, UK, DE, FR, ES, IT, NL, JP, AU, AE, SE, PL, TR ]'}
110165
111166
Returns:
112167
113168
ApiResponse
114169
115170
"""
116-
return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs)
171+
body = \
172+
{
173+
'countryCode': country_code,
174+
}
175+
176+
data_str = json.dumps(body)
177+
return self._request(kwargs.pop('path'), data=data_str, params=kwargs)
178+
179+
@sp_endpoint('/v2/profiles/register', method='PUT')
180+
def register(self, **kwargs) -> ApiResponse:
181+
r"""
182+
register(body: (dict, str)) -> ApiResponse
183+
184+
SANDBOX ONLY - Create a seller profile for sandbox.
185+
186+
body: | REQUIRED
187+
188+
| {
189+
| '**countryCode**': *string*, {'description': 'The countryCode for a given country [ US, CA, MX, UK, DE, FR, ES, IT, NL, JP, AU, AE, SE, PL, TR ]'}
190+
| }
191+
192+
"""
193+
194+
body = Utils.convert_body(kwargs.pop('body'), wrap=False)
195+
return self._request(kwargs.pop('path'), data=body, params=kwargs)

0 commit comments

Comments
 (0)