From 1cb019dce9e37424c2c4572b84b2d0da88242c8e Mon Sep 17 00:00:00 2001 From: denisneuf Date: Sat, 18 Sep 2021 21:34:22 +0200 Subject: [PATCH] added common resources: eligibility, invoices, metadata, profiles --- ad_api/api/__init__.py | 10 ++++ ad_api/api/eligibility.py | 26 +++++++++ ad_api/api/invoices.py | 40 ++++++++++++++ ad_api/api/metadata.py | 44 +++++++++++++++ ad_api/api/profiles.py | 111 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 231 insertions(+) create mode 100644 ad_api/api/eligibility.py create mode 100644 ad_api/api/invoices.py create mode 100644 ad_api/api/metadata.py create mode 100644 ad_api/api/profiles.py diff --git a/ad_api/api/__init__.py b/ad_api/api/__init__.py index e69de29..a4bd2dd 100644 --- a/ad_api/api/__init__.py +++ b/ad_api/api/__init__.py @@ -0,0 +1,10 @@ +from .profiles import Profiles +from .invoices import Invoices +from .eligibility import Eligibility +from .metadata import Metadata +__all__ = [ + "Profiles", + "Invoices", + "Eligibility", + "Metadata" +] \ No newline at end of file diff --git a/ad_api/api/eligibility.py b/ad_api/api/eligibility.py new file mode 100644 index 0000000..8b3511a --- /dev/null +++ b/ad_api/api/eligibility.py @@ -0,0 +1,26 @@ +from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse + +class Eligibility(Client): + + @sp_endpoint('/eligibility/product/list', method='POST') + def get_eligibility(self, **kwargs) -> ApiResponse: + r""" + + get_eligibility(self, **kwargs) -> ApiResponse + + Gets advertising eligibility status for a list of products. + + body: | REQUIRED + + '**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 ]'} + + '**productDetailsList**': *dict*, {'asin*': 'An Amazon product identifier.', 'sku': 'A seller product identifier'} + + '**locale**': *string*, {'description': 'Set to the locale string in the table below to specify the language in which the response is returned.'} + + Returns: + + ApiResponse + + """ + return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs) diff --git a/ad_api/api/invoices.py b/ad_api/api/invoices.py new file mode 100644 index 0000000..bed6fe5 --- /dev/null +++ b/ad_api/api/invoices.py @@ -0,0 +1,40 @@ +from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse + +class Invoices(Client): + + @sp_endpoint('/invoices', method='GET') + def list_invoices(self, **kwargs) -> ApiResponse: + r""" + + list_invoices(self, **kwargs) -> ApiResponse + + Get invoices for advertiser. Requires one of these permissions: ["nemo_transactions_view","nemo_transactions_edit"] + + query **invoiceStatuses**:*string* | Optional. Available values : ISSUED, PAID_IN_PART, PAID_IN_FULL, WRITTEN_OFF. + query **count**:*string* | Optional. Number of records to include in the paged response. Defaults to 100. Cannot be combined with the cursor parameter. + 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. + + + Returns: + + ApiResponse + + """ + return self._request(kwargs.pop('path'), params=kwargs) + + @sp_endpoint('/invoices/{}', method='GET') + def get_invoice(self, invoiceId, **kwargs) -> ApiResponse: + r""" + + get_invoice(self, invoiceId, **kwargs) -> ApiResponse + + Get invoice data by invoice ID. Requires one of these permissions: ["nemo_transactions_view","nemo_transactions_edit"] + + path **invoiceId**:*string* | Optional. Available values : ISSUED, PAID_IN_PART, PAID_IN_FULL, WRITTEN_OFF. + + Returns: + + ApiResponse + + """ + return self._request(fill_query_params(kwargs.pop('path'), invoiceId), params=kwargs) diff --git a/ad_api/api/metadata.py b/ad_api/api/metadata.py new file mode 100644 index 0000000..c77371f --- /dev/null +++ b/ad_api/api/metadata.py @@ -0,0 +1,44 @@ +from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse + +class Metadata(Client): + + @sp_endpoint('/product/metadata', method='POST') + def get_products_metadata(self, **kwargs) -> ApiResponse: + r""" + + get_products_metadata(self, **kwargs) -> ApiResponse + + Returns product metadata for the advertiser. + + body: | REQUIRED + + '**asins**': *list>string*, {'description': 'Specific asins to search for in the advertiser's inventory. Cannot use together with skus or searchStr input types.'} + + '**checkItemDetails**': *boolean*, {'description': 'Whether item details such as name, image, and price is required. default: false'} + + '**cursorToken**': *string*, {'description': 'Pagination token used for the suggested sort type'} + + '**adType**': *string*, {'description': 'Program type. Required if checks advertising eligibility. Enum: [ SP, SB, SD ]'} + + '**skus**': *list>string*, {'description': 'Specific skus to search for in the advertiser's inventory. Currently only support SP program type for sellers. Cannot use together with asins or searchStr input types'} + + '**checkEligibility**': *boolean*, {'description': 'Whether advertising eligibility info is required. default: false'} + + '**searchStr**': *string*, {'description': 'Specific string in the item title to search for in the advertiser's inventory. Case insensitive. Cannot use together with asins or skus input types'} + + '**pageIndex**': *integer($int32)*, {'description*': 'Index of the page to be returned'} + + '**sortOrder**': *string*, {'description': 'Sort order (has to be DESC for the suggested sort type). default: DESC. Enum [ ASC, DESC ]'} + + '**pageSize**': *integer($int32)*, {'description*': 'Number of items to be returned on this page index (max 100 for author)'} + + '**sortBy**': *string*, {'description': 'Sort option for the result. Currently only support SP program type for sellers. Enum [ SUGGESTED, CREATED_DATE ]'} + + + + Returns: + + ApiResponse + + """ + return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs) \ No newline at end of file diff --git a/ad_api/api/profiles.py b/ad_api/api/profiles.py new file mode 100644 index 0000000..5c3db12 --- /dev/null +++ b/ad_api/api/profiles.py @@ -0,0 +1,111 @@ +from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse + +class Profiles(Client): + + @sp_endpoint('/v2/profiles', method='GET') + def list_profiles(self, **kwargs) -> ApiResponse: + r""" + + list_profiles(self, **kwargs) -> ApiResponse + + Gets a list of profiles. + + query **apiProgram**:*string* | Optional. Filters response to include profiles that have permissions for the specified Advertising API program only. Available values : billing, campaign, paymentMethod, store, report, account, posts + + query **accessLevel**:*string* | Optional. Filters response to include profiles that have specified permissions for the specified Advertising API program only. Available values : edit, view + + query **profileTypeFilter**:*string* | Optional. Filters response to include profiles that are of the specified types in the comma-delimited list. Available values : seller, vendor, agency + + query **validPaymentMethodFilter**:*string* | Optional. Filter response to include profiles that have valid payment methods. Available values : true, false + + + Returns: + + ApiResponse + + """ + return self._request(kwargs.pop('path'), params=kwargs) + + @sp_endpoint('/v2/profiles', method='PUT') + def update_profile(self, **kwargs) -> ApiResponse: + r""" + + update_profile(self, **kwargs) -> ApiResponse + + Update the daily budget for one or more profiles. Note that this operation is only used for Sellers using Sponsored Products. + + body: | REQUIRED {'description': 'An array of ad groups.}' + + | '**profileId**': *integer($int64)*, {'description': 'The identifier of the profile.'} + | '**countryCode**': *string*, {'description': 'The countryCode for a given country'} + | '**currencyCode**': *string*, {'description': 'The currency used for all monetary values for entities under this profile.'} + | '**dailyBudget**': *number*, {'description': 'Note that this field applies to Sponsored Product campaigns for seller type accounts only. Not supported for vendor type accounts.'} + | '**timezone**': *string*, {'description': 'The time zone used for all date-based campaign management and reporting.'} + | '**accountInfo**': *AccountInfoAccountInfo*, {} + + Returns: + + ApiResponse + + """ + return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs) + + @sp_endpoint('/v2/profiles/{}', method='GET') + def get_profile(self, profileId, **kwargs) -> ApiResponse: + r""" + + get_profile(self, profileId, **kwargs) -> ApiResponse + + Gets a profile specified by identifier. + + path **profileId**:*number* | Required. The identifier of an existing profile Id. + + + Returns: + + ApiResponse + + """ + return self._request(fill_query_params(kwargs.pop('path'), profileId), params=kwargs) + + + @sp_endpoint('/v2/profiles/registerBrand', method='PUT') + def register_brand(self, **kwargs) -> ApiResponse: + r""" + + register_brand(self, **kwargs) -> ApiResponse + + SANDBOX ONLY - Create a vendor profile for sandbox. + + body: | REQUIRED + + '**countryCode**': *string*, {'description': 'The countryCode for a given country'} + '**brand**': *string*, {'description': 'The brand for the vendor account'} + + + Returns: + + ApiResponse + + """ + return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs) + + @sp_endpoint('/v2/profiles/register', method='PUT') + def register(self, **kwargs) -> ApiResponse: + r""" + + register_brand(self, \*\*kwargs) -> ApiResponse + + SANDBOX ONLY - Create a seller profile for sandbox. + + body: REQUIRED + + '**countryCode**': *string*, {'description': 'The countryCode for a given country'} + + + Returns: + + ApiResponse + + """ + return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs)