Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Commit feefbdc

Browse files
authored
Merge pull request #10 from pepsico-ecommerce/fj/DEP-2445/add_dsp_reports
Adding handling of dsp reports endpoints
2 parents be78a06 + a134c8b commit feefbdc

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

amazon_advertising_api/advertising_api.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import gzip
1515
import json
1616

17+
DSP_REPORT = "dsp_report"
18+
1719

1820
class AdvertisingApi(object):
1921

@@ -1065,7 +1067,10 @@ def request_report(self, record_type=None, report_id=None, data=None, campaign_t
10651067
:type data: string
10661068
"""
10671069
if record_type is not None:
1068-
interface = '{}/{}/report'.format(campaign_type, record_type)
1070+
if record_type == DSP_REPORT:
1071+
interface = 'dsp/reports'
1072+
else:
1073+
interface = '{}/{}/report'.format(campaign_type, record_type)
10691074
return self._operation(interface, data, method='POST')
10701075
elif report_id is not None:
10711076
interface = 'reports/{}'.format(report_id)
@@ -1075,8 +1080,10 @@ def request_report(self, record_type=None, report_id=None, data=None, campaign_t
10751080
'code': 0,
10761081
'response': 'record_type and report_id are both empty.'}
10771082

1078-
def get_report(self, report_id):
1083+
def get_report(self, report_id, report_type=None):
10791084
interface = 'reports/{}'.format(report_id)
1085+
if report_type is not None and report_type == DSP_REPORT:
1086+
interface = 'dsp/' + interface
10801087
res = self._operation(interface)
10811088
if res['success']:
10821089
body = json.loads(res['response'])
@@ -1166,6 +1173,7 @@ def _operation(self, interface, params=None, method='GET'):
11661173
:type method: string
11671174
"""
11681175
api_v3 = interface.startswith('sb')
1176+
dsp_report = interface.startswith('dsp')
11691177

11701178
if self._access_token is None:
11711179
return {'success': False,
@@ -1187,7 +1195,10 @@ def _operation(self, interface, params=None, method='GET'):
11871195

11881196
data = None
11891197

1190-
url = f"https://{self.endpoint}/" + ("" if api_v3 else f"{self.api_version}/") + f"{interface}"
1198+
if api_v3 or dsp_report:
1199+
url = f"https://{self.endpoint}/{interface}"
1200+
else:
1201+
url = f"https://{self.endpoint}/{self.api_version}/{interface}"
11911202

11921203
if method == 'GET':
11931204
if params is not None:

0 commit comments

Comments
 (0)