From f5a51906f455e80d7963a85035b776979d1a3ffc Mon Sep 17 00:00:00 2001 From: Aliaksandr Sheliutsin Date: Thu, 5 Nov 2020 13:06:08 +0300 Subject: [PATCH 1/5] Fixed typo --- searchads_api/api.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/searchads_api/api.py b/searchads_api/api.py index cba7563..a4bcf11 100644 --- a/searchads_api/api.py +++ b/searchads_api/api.py @@ -88,7 +88,7 @@ def create_campaign(self, campaign_name, budget, daily_budget, - curruncy): + currency): """ Creates a campaign to promote an app. """ @@ -97,11 +97,11 @@ def create_campaign(self, "name": campaign_name, "budgetAmount": { "amount": "{}".format(budget), - "currency": curruncy + "currency": currency }, "dailyBudgetAmount": { "amount": "{}".format(daily_budget), - "currency": curruncy + "currency": currency }, "adamId": app_id, "countriesOrRegions": countries @@ -1304,7 +1304,8 @@ def get_keywords_report_by_date(self, return_row_totals=True, return_grand_totals=True, offset=0, - limit=1000): + limit=1000, + **kwargs): """ Get reports on targeting keywords within a specific campaign. """ From 50f57d72e211a772388c854054fbdce087648d22 Mon Sep 17 00:00:00 2001 From: Aliaksandr Sheliutsin Date: Thu, 5 Nov 2020 13:20:55 +0300 Subject: [PATCH 2/5] Added ability to set new properties in _get_data method like "granularity" and "fields" --- searchads_api/api.py | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/searchads_api/api.py b/searchads_api/api.py index a4bcf11..e6ceb4a 100644 --- a/searchads_api/api.py +++ b/searchads_api/api.py @@ -1146,7 +1146,8 @@ def get_campaigns_report_by_date(self, return_row_totals=True, return_grand_totals=True, offset=0, - limit=1000): + limit=1000, + **kwargs): """ Get reports on campaigns within a specific org. { @@ -1206,7 +1207,8 @@ def get_campaigns_report_by_date(self, return_row_totals=return_row_totals, return_grand_totals=return_grand_totals, offset=offset, - limit=limit) + limit=limit, + **kwargs) def get_adgroups_report_by_date(self, campaignId, @@ -1219,7 +1221,8 @@ def get_adgroups_report_by_date(self, return_row_totals=True, return_grand_totals=True, offset=0, - limit=1000): + limit=1000, + **kwargs): """ Get reports on adGroups within a specific campaign. { @@ -1261,7 +1264,8 @@ def get_adgroups_report_by_date(self, return_row_totals=return_row_totals, return_grand_totals=return_grand_totals, offset=offset, - limit=limit) + limit=limit, + **kwargs) def get_creativesets_report_by_date(self, campaignId, @@ -1274,7 +1278,8 @@ def get_creativesets_report_by_date(self, return_row_totals=True, return_grand_totals=True, offset=0, - limit=1000): + limit=1000, + **kwargs): """ Fetches reports on Creative Sets used within a campaign. conditions example @@ -1291,7 +1296,8 @@ def get_creativesets_report_by_date(self, return_row_totals=return_row_totals, return_grand_totals=return_grand_totals, offset=offset, - limit=limit) + limit=limit, + **kwargs) def get_keywords_report_by_date(self, campaignId, @@ -1320,7 +1326,8 @@ def get_keywords_report_by_date(self, return_row_totals=return_row_totals, return_grand_totals=return_grand_totals, offset=offset, - limit=limit) + limit=limit, + **kwargs) def get_searchterms_report_by_date(self, campaignId, @@ -1333,7 +1340,8 @@ def get_searchterms_report_by_date(self, return_row_totals=True, return_grand_totals=True, offset=0, - limit=1000): + limit=1000, + **kwargs): """ Get reports on targeting keywords within a specific campaign. """ @@ -1348,7 +1356,8 @@ def get_searchterms_report_by_date(self, return_row_totals=return_row_totals, return_grand_totals=return_grand_totals, offset=offset, - limit=limit) + limit=limit, + **kwargs) def _get_data(self, data_type, @@ -1363,7 +1372,8 @@ def _get_data(self, offset, limit, campaignId=None, - group_by=None): + group_by=None, + **kwargs): row = [] grandTotals = [] if limit == 0: @@ -1396,6 +1406,12 @@ def _get_data(self, data["groupBy"] = [ group_by ] + if kwargs: + data = { + **data, + **kwargs + } + if data_type == "campaigns": res = self.api_call("reports/campaigns", json_data=data, method="POST") From 4e200fa1488c77736beaa091e17aeb98cabb89e6 Mon Sep 17 00:00:00 2001 From: Aliaksandr Sheliutsin Date: Tue, 10 Nov 2020 11:03:05 +0300 Subject: [PATCH 3/5] Removed catching all errors in api_call function --- searchads_api/api.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/searchads_api/api.py b/searchads_api/api.py index e6ceb4a..5177979 100644 --- a/searchads_api/api.py +++ b/searchads_api/api.py @@ -31,7 +31,7 @@ def api_call(self, headers={}, json_data={}, params={}, - method="GET", + method="GET", limit=1000, offset=0): """ @@ -64,22 +64,19 @@ def api_call(self, kwargs["params"].update(params) api_endpoint = "{}/{}".format(self.api_version, api_endpoint) url = url.format(api_endpoint) - try: - if method == "get" or method == "GET": - req = caller.get(url, **kwargs) - elif method == "post" or method == "POST": - req = caller.post(url, **kwargs) - elif method == "put" or method == "PUT": - req = caller.put(url, **kwargs) - elif method == "delete" or method == "DELETE": - req = caller.delete(url, **kwargs) - if self.verbose: - print(req.url) - print(req.text) - return req.json() - except Exception as e: - print(str(e), url) - return None + req = None + if method == "get" or method == "GET": + req = caller.get(url, **kwargs) + elif method == "post" or method == "POST": + req = caller.post(url, **kwargs) + elif method == "put" or method == "PUT": + req = caller.put(url, **kwargs) + elif method == "delete" or method == "DELETE": + req = caller.delete(url, **kwargs) + if self.verbose and req: + print(req.url) + print(req.text) + return req.json() # Campaign Methods def create_campaign(self, @@ -1444,7 +1441,7 @@ def _get_data(self, grandTotals.extend( res["data"]["reportingDataResponse"]["grandTotals"]) res_len = len(row) - + offset = len(row) # print(limit) if res_len == limit or res_len >= res["pagination"]["totalResults"]: From fc68816050bbd14c0baa86214f20ce7da709719e Mon Sep 17 00:00:00 2001 From: Aliaksandr Sheliutsin Date: Mon, 7 Dec 2020 14:27:10 +0300 Subject: [PATCH 4/5] Added raising status errors --- searchads_api/api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/searchads_api/api.py b/searchads_api/api.py index 5177979..bb2f5d4 100644 --- a/searchads_api/api.py +++ b/searchads_api/api.py @@ -76,6 +76,8 @@ def api_call(self, if self.verbose and req: print(req.url) print(req.text) + # Raising errors to show errors + req.raise_for_status() return req.json() # Campaign Methods From 9d6ec81008a19894147febcf27e5072000df084a Mon Sep 17 00:00:00 2001 From: "aliaksandr.sheliutsin" Date: Tue, 23 Mar 2021 11:27:48 +0300 Subject: [PATCH 5/5] Add function to get list of origins --- searchads_api/api.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/searchads_api/api.py b/searchads_api/api.py index bb2f5d4..1890024 100644 --- a/searchads_api/api.py +++ b/searchads_api/api.py @@ -186,6 +186,31 @@ def get_campaigns(self, limit=0, offset=0): offset += result["pagination"]["itemsPerPage"] return res + def get_origins(self): + """ + Get User ACL Response Example + { + "data": [ + { + "currency": "USD", + "orgId": , + "orgName": "", + "paymentModel": "LOC", + "roleNames": ["Admin"] + }, + { + "currency": "USD", + "orgId": ;, + "orgName": "", + "paymentModel": "LOC", + "roleNames": ["Admin"] + }], + } + """ + return self.api_call( + api_endpoint="acls" + ) + def update_campaign(self, campaign_id, countries=None,