python-amazon-ad-api 2.3.0__py3-none-any.whl → 2.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ad_api/api/__init__.py +76 -0
- ad_api/api/campaign_diagnostics.py +1 -1
- ad_api/api/dsp_ad_group_and_campaign.py +139 -0
- ad_api/api/dsp_audience_create.py +53 -0
- ad_api/api/dsp_bid_adjustments.py +193 -0
- ad_api/api/dsp_campaign_flights.py +119 -0
- ad_api/api/dsp_campaign_insights.py +59 -0
- ad_api/api/dsp_combined_audiences.py +83 -0
- ad_api/api/dsp_conversion_tracking_products.py +92 -0
- ad_api/api/dsp_conversions.py +442 -0
- ad_api/api/dsp_creatives.py +114 -0
- ad_api/api/dsp_deal_permissions.py +170 -0
- ad_api/api/dsp_deal_proposals.py +440 -0
- ad_api/api/dsp_deals.py +204 -0
- ad_api/api/dsp_deals_management.py +66 -0
- ad_api/api/dsp_discovery_advertised_product_categories.py +35 -0
- ad_api/api/dsp_discovery_apps.py +36 -0
- ad_api/api/dsp_discovery_domain_lists.py +36 -0
- ad_api/api/dsp_discovery_geo_locations.py +42 -0
- ad_api/api/dsp_discovery_iab_content.py +37 -0
- ad_api/api/dsp_discovery_inventory_source_exchanges.py +36 -0
- ad_api/api/dsp_discovery_products.py +102 -0
- ad_api/api/dsp_discovery_third_party_target_segments.py +36 -0
- ad_api/api/dsp_frequency_associations.py +138 -0
- ad_api/api/dsp_frequency_groups.py +112 -0
- ad_api/api/dsp_frequency_insights.py +85 -0
- ad_api/api/dsp_guidance.py +111 -0
- ad_api/api/dsp_inherited_settings.py +133 -0
- ad_api/api/dsp_inventory_groups.py +209 -0
- ad_api/api/dsp_measurement.py +693 -0
- ad_api/api/dsp_seats.py +43 -0
- ad_api/api/dsp_target_kpi_recommendations.py +44 -0
- ad_api/api/dsp_targeting.py +98 -0
- ad_api/api/forecast.py +130 -0
- ad_api/api/hashed_records.py +39 -0
- ad_api/api/historic_reach.py +148 -0
- ad_api/api/locations.py +57 -0
- ad_api/api/plan_management.py +1268 -0
- ad_api/api/record_management.py +121 -0
- ad_api/api/targetable_entities.py +89 -0
- ad_api/version.py +1 -1
- {python_amazon_ad_api-2.3.0.dist-info → python_amazon_ad_api-2.4.0.dist-info}/METADATA +1 -1
- {python_amazon_ad_api-2.3.0.dist-info → python_amazon_ad_api-2.4.0.dist-info}/RECORD +46 -8
- {python_amazon_ad_api-2.3.0.dist-info → python_amazon_ad_api-2.4.0.dist-info}/WHEEL +0 -0
- {python_amazon_ad_api-2.3.0.dist-info → python_amazon_ad_api-2.4.0.dist-info}/licenses/LICENSE +0 -0
- {python_amazon_ad_api-2.3.0.dist-info → python_amazon_ad_api-2.4.0.dist-info}/top_level.txt +0 -0
ad_api/api/dsp_seats.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Seats and Seat IDs /dsp/seats.
|
|
2
|
+
|
|
3
|
+
Contract: Seat IDs 3.0, the *Seat IDs* child of *Seats*. One read route,
|
|
4
|
+
``vnd.dspseats``, and two versions: ``v1`` and ``v2``.
|
|
5
|
+
|
|
6
|
+
``ClientId`` is required; ``Scope`` and **``Amazon-Ads-Manager-AccountId``**
|
|
7
|
+
are optional: this is one of the few routes that accepts the manager header,
|
|
8
|
+
and there is no ``Amazon-Ads-AccountId`` at all.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse, Utils
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class DspSeats(Client):
|
|
15
|
+
r"""Seat IDs - /dsp/seats
|
|
16
|
+
|
|
17
|
+
Documentation: https://advertising.amazon.com/API/docs/en-us/seat-ids
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
@sp_endpoint('/dsp/seats/current/list', method='POST',
|
|
21
|
+
headers=['Amazon-Advertising-API-Scope', 'Amazon-Advertising-API-Manager-Account'])
|
|
22
|
+
def list_current_seats(self, version: str = "1", **kwargs) -> ApiResponse:
|
|
23
|
+
r"""
|
|
24
|
+
Lists the seats of the caller. Read only.
|
|
25
|
+
|
|
26
|
+
This is the only route so far that accepts ``Amazon-Ads-Manager-AccountId``
|
|
27
|
+
without an ``Amazon-Ads-AccountId``: the manager replaces the account.
|
|
28
|
+
|
|
29
|
+
Keyword Args
|
|
30
|
+
|
|
31
|
+
- ``version`` (str): the version in the media type, ``1``. [optional]
|
|
32
|
+
|
|
33
|
+
- ``selector`` (str): ``profile_id`` or ``account_id``. [optional]
|
|
34
|
+
|
|
35
|
+
Returns
|
|
36
|
+
ApiResponse, ``200``, with the seats.
|
|
37
|
+
"""
|
|
38
|
+
media_type = 'application/vnd.dspseats.v' + version + '+json'
|
|
39
|
+
headers = {'Accept': media_type}
|
|
40
|
+
headers['Content-Type'] = media_type
|
|
41
|
+
body = Utils.convert_body(kwargs.pop('body'), False)
|
|
42
|
+
return self._request(kwargs.pop('path'),
|
|
43
|
+
data=body, params=kwargs, headers=headers)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Target KPI recommendations /dsp/campaigns/targetKpi/recommendations.
|
|
2
|
+
|
|
3
|
+
Contract: Goal Seeking Bidder Target KPI Recommendation 3.0. One route, read
|
|
4
|
+
only despite the POST.
|
|
5
|
+
|
|
6
|
+
The two media types do not share a name: the request is
|
|
7
|
+
``vnd.gsbtargetkpirecommendation.v<n>`` and the answer is
|
|
8
|
+
``vnd.spinitialbudgetrecommendation.v<n>``. The released version is 3.4, not 1,
|
|
9
|
+
so that is the default here.
|
|
10
|
+
|
|
11
|
+
Only ``ClientId`` and ``Scope`` are declared: no account id header at all.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse, Utils
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class DspTargetKpiRecommendations(Client):
|
|
18
|
+
r"""Target KPI recommendations - /dsp/campaigns/targetKpi/recommendations
|
|
19
|
+
|
|
20
|
+
Documentation: https://advertising.amazon.com/API/docs/en-us/target-kpi-recommendations
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
@sp_endpoint('/dsp/campaigns/targetKpi/recommendations', method='POST',
|
|
24
|
+
headers=['Amazon-Advertising-API-Scope'])
|
|
25
|
+
def get_target_kpi_recommendations(self, version: str = "3.4", **kwargs) -> ApiResponse:
|
|
26
|
+
r"""
|
|
27
|
+
Reads the bid and budget Amazon recommends for a KPI target.
|
|
28
|
+
|
|
29
|
+
The answer arrives as ``vnd.spinitialbudgetrecommendation``, a different name
|
|
30
|
+
from the request. That one is the contract.
|
|
31
|
+
|
|
32
|
+
Keyword Args
|
|
33
|
+
|
|
34
|
+
- ``version`` (str): the version in the media type, ``3.4``. [optional]
|
|
35
|
+
|
|
36
|
+
Returns
|
|
37
|
+
ApiResponse, ``200``, with the recommendation.
|
|
38
|
+
"""
|
|
39
|
+
media_type = 'application/vnd.gsbtargetkpirecommendation.v' + version + '+json'
|
|
40
|
+
headers = {'Accept': media_type}
|
|
41
|
+
headers['Content-Type'] = media_type
|
|
42
|
+
body = Utils.convert_body(kwargs.pop('body'), False)
|
|
43
|
+
return self._request(kwargs.pop('path'),
|
|
44
|
+
data=body, params=kwargs, headers=headers)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""Targeting /dsp/v1/targets.
|
|
2
|
+
|
|
3
|
+
Contract: Amazon Ads DSP API Targets - V1 3.0, *Targeting* under *Campaign
|
|
4
|
+
management*. Four operations, all POST, all ``application/json``: create, the
|
|
5
|
+
two deletes, and the read.
|
|
6
|
+
|
|
7
|
+
Here **all three headers are required**, including ``Scope``:
|
|
8
|
+
``Amazon-Advertising-API-ClientId``, ``Amazon-Advertising-API-Scope`` and
|
|
9
|
+
``Amazon-Ads-AccountId``.
|
|
10
|
+
|
|
11
|
+
The create and the two deletes answer 207. ``list`` answers 200.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse, Utils
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class DspTargeting(Client):
|
|
18
|
+
r"""Targeting - /dsp/v1/targets
|
|
19
|
+
|
|
20
|
+
Documentation: https://advertising.amazon.com/API/docs/en-us/dsp-universal-targeting
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
@sp_endpoint('/dsp/v1/targets', method='POST',
|
|
24
|
+
headers=['Amazon-Advertising-API-Scope', 'Amazon-Ads-AccountId'])
|
|
25
|
+
def create_targets(self, **kwargs) -> ApiResponse:
|
|
26
|
+
r"""
|
|
27
|
+
Creates targets on an ad group.
|
|
28
|
+
|
|
29
|
+
Keyword Args
|
|
30
|
+
|
|
31
|
+
- ``selector`` (str): ``profile_id`` or ``account_id``. [optional]
|
|
32
|
+
|
|
33
|
+
Returns
|
|
34
|
+
ApiResponse, **207** multi-status, one per target.
|
|
35
|
+
"""
|
|
36
|
+
headers = {'Accept': 'application/json'}
|
|
37
|
+
headers['Content-Type'] = 'application/json'
|
|
38
|
+
body = Utils.convert_body(kwargs.pop('body'), False)
|
|
39
|
+
return self._request(kwargs.pop('path'),
|
|
40
|
+
data=body, params=kwargs, headers=headers)
|
|
41
|
+
|
|
42
|
+
@sp_endpoint('/dsp/v1/targets/delete', method='POST',
|
|
43
|
+
headers=['Amazon-Advertising-API-Scope', 'Amazon-Ads-AccountId'])
|
|
44
|
+
def delete_targets(self, **kwargs) -> ApiResponse:
|
|
45
|
+
r"""
|
|
46
|
+
Deletes targets by id. A POST with ``/delete``: the ids go in the body.
|
|
47
|
+
|
|
48
|
+
Keyword Args
|
|
49
|
+
|
|
50
|
+
- ``selector`` (str): ``profile_id`` or ``account_id``. [optional]
|
|
51
|
+
|
|
52
|
+
Returns
|
|
53
|
+
ApiResponse, **207** multi-status.
|
|
54
|
+
"""
|
|
55
|
+
headers = {'Accept': 'application/json'}
|
|
56
|
+
headers['Content-Type'] = 'application/json'
|
|
57
|
+
body = Utils.convert_body(kwargs.pop('body'), False)
|
|
58
|
+
return self._request(kwargs.pop('path'),
|
|
59
|
+
data=body, params=kwargs, headers=headers)
|
|
60
|
+
|
|
61
|
+
@sp_endpoint('/dsp/v1/targets/deleteByObject', method='POST',
|
|
62
|
+
headers=['Amazon-Advertising-API-Scope', 'Amazon-Ads-AccountId'])
|
|
63
|
+
def delete_targets_by_object(self, **kwargs) -> ApiResponse:
|
|
64
|
+
r"""
|
|
65
|
+
Deletes targets by the object they point at, not by id. Use this one when
|
|
66
|
+
what you have is the target expression and not its id.
|
|
67
|
+
|
|
68
|
+
Keyword Args
|
|
69
|
+
|
|
70
|
+
- ``selector`` (str): ``profile_id`` or ``account_id``. [optional]
|
|
71
|
+
|
|
72
|
+
Returns
|
|
73
|
+
ApiResponse, **207** multi-status.
|
|
74
|
+
"""
|
|
75
|
+
headers = {'Accept': 'application/json'}
|
|
76
|
+
headers['Content-Type'] = 'application/json'
|
|
77
|
+
body = Utils.convert_body(kwargs.pop('body'), False)
|
|
78
|
+
return self._request(kwargs.pop('path'),
|
|
79
|
+
data=body, params=kwargs, headers=headers)
|
|
80
|
+
|
|
81
|
+
@sp_endpoint('/dsp/v1/targets/list', method='POST',
|
|
82
|
+
headers=['Amazon-Advertising-API-Scope', 'Amazon-Ads-AccountId'])
|
|
83
|
+
def list_targets(self, **kwargs) -> ApiResponse:
|
|
84
|
+
r"""
|
|
85
|
+
Lists targets. Read only, POST because the filter goes in the body.
|
|
86
|
+
|
|
87
|
+
Keyword Args
|
|
88
|
+
|
|
89
|
+
- ``selector`` (str): ``profile_id`` or ``account_id``. [optional]
|
|
90
|
+
|
|
91
|
+
Returns
|
|
92
|
+
ApiResponse, ``200``, with the targets.
|
|
93
|
+
"""
|
|
94
|
+
headers = {'Accept': 'application/json'}
|
|
95
|
+
headers['Content-Type'] = 'application/json'
|
|
96
|
+
body = Utils.convert_body(kwargs.pop('body'), False)
|
|
97
|
+
return self._request(kwargs.pop('path'),
|
|
98
|
+
data=body, params=kwargs, headers=headers)
|
ad_api/api/forecast.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""Reach and performance forecasting /mediaPlan/v1.
|
|
2
|
+
|
|
3
|
+
Contract: Reach Planning Service 3.0. Five ``POST`` routes, plain
|
|
4
|
+
``application/json`` in body and answer, all of them under ``/mediaPlan/v1``, the
|
|
5
|
+
same prefix *Plan management* uses. It is the second child of *Media Planning*.
|
|
6
|
+
|
|
7
|
+
Three routes create work and answer **207**, not 200: ``reachForecasts``,
|
|
8
|
+
``deduplicatedReachForecasts`` and ``performanceForecasts``. The other two read:
|
|
9
|
+
``reachForecasts/list`` and ``reachForecasts/targets/list``.
|
|
10
|
+
|
|
11
|
+
Only ``Amazon-Advertising-API-ClientId`` is marked required in the contract;
|
|
12
|
+
the scope and the account headers are optional there. The scope is what
|
|
13
|
+
identifies the account in practice.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse, Utils
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Forecast(Client):
|
|
20
|
+
r"""Forecast - reach and performance forecasting, /mediaPlan/v1
|
|
21
|
+
|
|
22
|
+
Documentation: https://advertising.amazon.com/API/docs/en-us/reach-and-performance-forecasting
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
@sp_endpoint('/mediaPlan/v1/reachForecasts/list', method='POST',
|
|
26
|
+
headers=['Amazon-Advertising-API-Scope'])
|
|
27
|
+
def list_reach_forecasts(self, **kwargs) -> ApiResponse:
|
|
28
|
+
r"""
|
|
29
|
+
Lists the reach forecasts of the account. Read only.
|
|
30
|
+
|
|
31
|
+
Request Body [Required]
|
|
32
|
+
| **reachForecastIds** (list): one to a hundred UUIDs, from a
|
|
33
|
+
| previous create.
|
|
34
|
+
|
|
35
|
+
Request Body [Optional]
|
|
36
|
+
| **maxResults** (int): default 100, from 1 to 100.
|
|
37
|
+
| **nextToken** (str): token from a previous answer.
|
|
38
|
+
|
|
39
|
+
Returns
|
|
40
|
+
ApiResponse with ``reachForecasts`` and ``nextToken``. An account
|
|
41
|
+
without forecasts answers ``200`` with an empty list.
|
|
42
|
+
"""
|
|
43
|
+
headers = {'Accept': 'application/json',
|
|
44
|
+
'Content-Type': 'application/json'}
|
|
45
|
+
body = Utils.convert_body(kwargs.pop('body'), False)
|
|
46
|
+
return self._request(fill_query_params(kwargs.pop('path')),
|
|
47
|
+
data=body, params=kwargs, headers=headers)
|
|
48
|
+
|
|
49
|
+
@sp_endpoint('/mediaPlan/v1/reachForecasts', method='POST',
|
|
50
|
+
headers=['Amazon-Advertising-API-Scope'])
|
|
51
|
+
def create_reach_forecast(self, **kwargs) -> ApiResponse:
|
|
52
|
+
r"""
|
|
53
|
+
Creates one or more reach forecasts. Answers **207**, the multi-status
|
|
54
|
+
code, because each forecast can succeed or fail on its own.
|
|
55
|
+
|
|
56
|
+
Request Body [Required]
|
|
57
|
+
| **reachForecasts** (list): the forecasts to create.
|
|
58
|
+
|
|
59
|
+
Request Body [Optional]
|
|
60
|
+
| **commonTargets** (object): targets shared by every forecast in
|
|
61
|
+
| the request.
|
|
62
|
+
|
|
63
|
+
Returns
|
|
64
|
+
ApiResponse, one entry per forecast.
|
|
65
|
+
"""
|
|
66
|
+
headers = {'Accept': 'application/json',
|
|
67
|
+
'Content-Type': 'application/json'}
|
|
68
|
+
body = Utils.convert_body(kwargs.pop('body'), False)
|
|
69
|
+
return self._request(fill_query_params(kwargs.pop('path')),
|
|
70
|
+
data=body, params=kwargs, headers=headers)
|
|
71
|
+
|
|
72
|
+
@sp_endpoint('/mediaPlan/v1/deduplicatedReachForecasts', method='POST',
|
|
73
|
+
headers=['Amazon-Advertising-API-Scope'])
|
|
74
|
+
def create_deduplicated_reach_forecasts(self, **kwargs) -> ApiResponse:
|
|
75
|
+
r"""
|
|
76
|
+
Creates reach forecasts that account for overlap with each other, so the
|
|
77
|
+
combined reach is not double counted. Answers **207**.
|
|
78
|
+
|
|
79
|
+
Request Body [Required]
|
|
80
|
+
| **deduplicatedReachForecasts** (list): the forecasts to create.
|
|
81
|
+
|
|
82
|
+
Returns
|
|
83
|
+
ApiResponse, one entry per forecast.
|
|
84
|
+
"""
|
|
85
|
+
headers = {'Accept': 'application/json',
|
|
86
|
+
'Content-Type': 'application/json'}
|
|
87
|
+
body = Utils.convert_body(kwargs.pop('body'), False)
|
|
88
|
+
return self._request(fill_query_params(kwargs.pop('path')),
|
|
89
|
+
data=body, params=kwargs, headers=headers)
|
|
90
|
+
|
|
91
|
+
@sp_endpoint('/mediaPlan/v1/performanceForecasts', method='POST',
|
|
92
|
+
headers=['Amazon-Advertising-API-Scope'])
|
|
93
|
+
def generate_performance_forecasts(self, **kwargs) -> ApiResponse:
|
|
94
|
+
r"""
|
|
95
|
+
Generates the performance forecast of a plan: impressions, clicks and
|
|
96
|
+
the rest. Answers **207**.
|
|
97
|
+
|
|
98
|
+
Request Body [Required]
|
|
99
|
+
| **performanceForecasts** (list): what to forecast.
|
|
100
|
+
|
|
101
|
+
Returns
|
|
102
|
+
ApiResponse, one entry per forecast.
|
|
103
|
+
"""
|
|
104
|
+
headers = {'Accept': 'application/json',
|
|
105
|
+
'Content-Type': 'application/json'}
|
|
106
|
+
body = Utils.convert_body(kwargs.pop('body'), False)
|
|
107
|
+
return self._request(fill_query_params(kwargs.pop('path')),
|
|
108
|
+
data=body, params=kwargs, headers=headers)
|
|
109
|
+
|
|
110
|
+
@sp_endpoint('/mediaPlan/v1/reachForecasts/targets/list', method='POST',
|
|
111
|
+
headers=['Amazon-Advertising-API-Scope'])
|
|
112
|
+
def list_reach_forecast_targets(self, **kwargs) -> ApiResponse:
|
|
113
|
+
r"""
|
|
114
|
+
Lists the targets one reach forecast was built from. Read only.
|
|
115
|
+
|
|
116
|
+
Request Body [Required]
|
|
117
|
+
| **reachForecastId** (str): the forecast, a UUID.
|
|
118
|
+
|
|
119
|
+
Request Body [Optional]
|
|
120
|
+
| **maxResults** (int): page size.
|
|
121
|
+
| **nextToken** (str): token from a previous answer.
|
|
122
|
+
|
|
123
|
+
Returns
|
|
124
|
+
ApiResponse with the targets and ``nextToken``.
|
|
125
|
+
"""
|
|
126
|
+
headers = {'Accept': 'application/json',
|
|
127
|
+
'Content-Type': 'application/json'}
|
|
128
|
+
body = Utils.convert_body(kwargs.pop('body'), False)
|
|
129
|
+
return self._request(fill_query_params(kwargs.pop('path')),
|
|
130
|
+
data=body, params=kwargs, headers=headers)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Hashed records /dp/records/hashed.
|
|
2
|
+
|
|
3
|
+
Contract: Hashed Records 3.0, the *Hashed records* child of *Data provider*.
|
|
4
|
+
One route: ``POST /dp/records/hashed``, plain ``application/json``.
|
|
5
|
+
|
|
6
|
+
It takes records whose identifiers are already hashed, so a data provider never
|
|
7
|
+
ships raw cookies or emails to Amazon.
|
|
8
|
+
|
|
9
|
+
Like its sibling, the contract asks for no identity header: only
|
|
10
|
+
``Authorization``, ``Amazon-Advertising-API-ClientId`` and ``Content-Type``.
|
|
11
|
+
This client is not allowed to call it: the service answers
|
|
12
|
+
``403 Client is not allowed to call this API``.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse, Utils
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class HashedRecords(Client):
|
|
19
|
+
r"""Hashed records - /dp/records/hashed
|
|
20
|
+
|
|
21
|
+
Documentation: https://advertising.amazon.com/API/docs/en-us/data-provider/hashed-records
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
@sp_endpoint('/dp/records/hashed', method='POST', headers=[])
|
|
25
|
+
def post_hashed_records(self, **kwargs) -> ApiResponse:
|
|
26
|
+
r"""
|
|
27
|
+
Sends records with hashed identifiers.
|
|
28
|
+
|
|
29
|
+
Request Body [Required]
|
|
30
|
+
The records the contract publishes, with their hashed ids.
|
|
31
|
+
|
|
32
|
+
Returns
|
|
33
|
+
ApiResponse with the outcome. Access denied answers ``403``.
|
|
34
|
+
"""
|
|
35
|
+
headers = {'Accept': 'application/json',
|
|
36
|
+
'Content-Type': 'application/json'}
|
|
37
|
+
body = Utils.convert_body(kwargs.pop('body'), False)
|
|
38
|
+
return self._request(fill_query_params(kwargs.pop('path')),
|
|
39
|
+
data=body, params=kwargs, headers=headers)
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"""Historic reach /mediaPlan/historicalReachCurves and /mediaPlan/v2.
|
|
2
|
+
|
|
3
|
+
Contract: Media Insights Hub 3.0, the *Historic reach* family of *Media
|
|
4
|
+
Planning*. Five ``POST`` and ``GET`` routes across two prefixes: the two ``list``
|
|
5
|
+
routes live under ``/mediaPlan/historicalReachCurves`` and speak
|
|
6
|
+
``application/vnd.mediaplanhistoricalreachcurves.v1+json``; the report routes
|
|
7
|
+
live under ``/mediaPlan/v2`` and speak plain ``application/json``. Errors come
|
|
8
|
+
as ``application/vnd.error.v1+json`` on the v1 lists.
|
|
9
|
+
|
|
10
|
+
Header: ``Amazon-Advertising-API-ClientId`` is required; the contract lists
|
|
11
|
+
``Amazon-Ads-AccountId``, the DSP advertiser id, and
|
|
12
|
+
``Amazon-Advertising-API-Scope`` as optional. Both identity headers are
|
|
13
|
+
declared, so a DSP caller can send the account id and a profile caller the
|
|
14
|
+
scope; ``selector`` picks one.
|
|
15
|
+
|
|
16
|
+
The two ``list`` routes require a ``targeting`` object and, inside it,
|
|
17
|
+
``geography``. Sending a body without it answers
|
|
18
|
+
``400 Value null at targeting failed to satisfy constraint``, which reads
|
|
19
|
+
like an access problem and is not one. With it, the route answers ``200``.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse, Utils
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class HistoricReach(Client):
|
|
26
|
+
r"""Historic reach - /mediaPlan
|
|
27
|
+
|
|
28
|
+
Documentation: https://advertising.amazon.com/API/docs/en-us/historic-reach
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
@sp_endpoint('/mediaPlan/historicalReachCurves/list', method='POST',
|
|
32
|
+
headers=['Amazon-Advertising-API-Scope',
|
|
33
|
+
'Amazon-Ads-AccountId'])
|
|
34
|
+
def list_historical_reach_curves(self, version: str = "1", **kwargs) -> ApiResponse:
|
|
35
|
+
r"""
|
|
36
|
+
Lists the historic reach curves of the account. Read only.
|
|
37
|
+
|
|
38
|
+
Request Body [Required]
|
|
39
|
+
| **targeting** (dict): at least ``geography``, such as ``ES``.
|
|
40
|
+
| It also takes ``channels``, ``demographics`` and ``reachType``
|
|
41
|
+
| (``INDIVIDUALS`` or ``HOUSEHOLDS``).
|
|
42
|
+
|
|
43
|
+
Request Body [Optional]
|
|
44
|
+
| **month** (str): ``MM/YYYY``. Defaults to the most recent month the
|
|
45
|
+
| geography has.
|
|
46
|
+
| **maxResults** (int): default 1000, from 1 to 1000.
|
|
47
|
+
| **nextToken** (str): token from a previous answer.
|
|
48
|
+
|
|
49
|
+
Keyword Args
|
|
50
|
+
|
|
51
|
+
- ``version`` (str): media type version. Defaults to ``1``. [optional]
|
|
52
|
+
|
|
53
|
+
Returns
|
|
54
|
+
ApiResponse with ``historicalReachCurves`` and ``totalResults``.
|
|
55
|
+
"""
|
|
56
|
+
media_type = ('application/vnd.mediaplanhistoricalreachcurves.v'
|
|
57
|
+
+ version + '+json')
|
|
58
|
+
headers = {'Accept': media_type, 'Content-Type': media_type}
|
|
59
|
+
body = Utils.convert_body(kwargs.pop('body'), False)
|
|
60
|
+
return self._request(fill_query_params(kwargs.pop('path')),
|
|
61
|
+
data=body, params=kwargs, headers=headers)
|
|
62
|
+
|
|
63
|
+
@sp_endpoint('/mediaPlan/historicalReachCurvesMetadata/list', method='POST',
|
|
64
|
+
headers=['Amazon-Advertising-API-Scope',
|
|
65
|
+
'Amazon-Ads-AccountId'])
|
|
66
|
+
def list_historical_reach_curve_metadata(self, version: str = "1", **kwargs) -> ApiResponse:
|
|
67
|
+
r"""
|
|
68
|
+
Lists the metadata of the historic reach curves. Read only.
|
|
69
|
+
|
|
70
|
+
Request Body
|
|
71
|
+
The list body the contract publishes for this resource.
|
|
72
|
+
|
|
73
|
+
Keyword Args
|
|
74
|
+
|
|
75
|
+
- ``version`` (str): media type version. Defaults to ``1``. [optional]
|
|
76
|
+
|
|
77
|
+
Returns
|
|
78
|
+
ApiResponse with the metadata.
|
|
79
|
+
"""
|
|
80
|
+
media_type = ('application/vnd.mediaplanhistoricalreachcurves.v'
|
|
81
|
+
+ version + '+json')
|
|
82
|
+
headers = {'Accept': media_type, 'Content-Type': media_type}
|
|
83
|
+
body = Utils.convert_body(kwargs.pop('body'), False)
|
|
84
|
+
return self._request(fill_query_params(kwargs.pop('path')),
|
|
85
|
+
data=body, params=kwargs, headers=headers)
|
|
86
|
+
|
|
87
|
+
@sp_endpoint('/mediaPlan/v2/historicalReachCurves', method='POST',
|
|
88
|
+
headers=['Amazon-Advertising-API-Scope',
|
|
89
|
+
'Amazon-Ads-AccountId'])
|
|
90
|
+
def create_historical_reach_curve_report(self, **kwargs) -> ApiResponse:
|
|
91
|
+
r"""
|
|
92
|
+
Asks for a historic reach curve report. It is asynchronous: the answer
|
|
93
|
+
carries a ``reportId`` and its state is read with
|
|
94
|
+
``get_historical_reach_curve_report_status``.
|
|
95
|
+
|
|
96
|
+
Request Body [Required]
|
|
97
|
+
The report body the contract publishes.
|
|
98
|
+
|
|
99
|
+
Returns
|
|
100
|
+
ApiResponse with the created report.
|
|
101
|
+
"""
|
|
102
|
+
headers = {'Accept': 'application/json',
|
|
103
|
+
'Content-Type': 'application/json'}
|
|
104
|
+
body = Utils.convert_body(kwargs.pop('body'), False)
|
|
105
|
+
return self._request(fill_query_params(kwargs.pop('path')),
|
|
106
|
+
data=body, params=kwargs, headers=headers)
|
|
107
|
+
|
|
108
|
+
@sp_endpoint('/mediaPlan/v2/historicalReachCurves/{}', method='GET',
|
|
109
|
+
headers=['Amazon-Advertising-API-Scope',
|
|
110
|
+
'Amazon-Ads-AccountId'])
|
|
111
|
+
def get_historical_reach_curve_report(self, reportId, **kwargs) -> ApiResponse:
|
|
112
|
+
r"""
|
|
113
|
+
Reads a historic reach curve report. Read only.
|
|
114
|
+
|
|
115
|
+
Path Parameters
|
|
116
|
+
|
|
117
|
+
- ``reportId`` (str): the report. [required]
|
|
118
|
+
|
|
119
|
+
Keyword Args
|
|
120
|
+
|
|
121
|
+
- ``maxResults`` (int): page size. [optional]
|
|
122
|
+
- ``nextToken`` (str): token from a previous answer. [optional]
|
|
123
|
+
|
|
124
|
+
Returns
|
|
125
|
+
ApiResponse with the report rows.
|
|
126
|
+
"""
|
|
127
|
+
headers = {'Accept': 'application/json'}
|
|
128
|
+
return self._request(fill_query_params(kwargs.pop('path'), reportId),
|
|
129
|
+
params=kwargs, headers=headers)
|
|
130
|
+
|
|
131
|
+
@sp_endpoint('/mediaPlan/v2/historicalReachCurves/{}/status', method='GET',
|
|
132
|
+
headers=['Amazon-Advertising-API-Scope',
|
|
133
|
+
'Amazon-Ads-AccountId'])
|
|
134
|
+
def get_historical_reach_curve_report_status(self, reportId, **kwargs) -> ApiResponse:
|
|
135
|
+
r"""
|
|
136
|
+
Reads the state of a report: whether it is still being built or ready to
|
|
137
|
+
be fetched. Read only.
|
|
138
|
+
|
|
139
|
+
Path Parameters
|
|
140
|
+
|
|
141
|
+
- ``reportId`` (str): the report. [required]
|
|
142
|
+
|
|
143
|
+
Returns
|
|
144
|
+
ApiResponse with the status.
|
|
145
|
+
"""
|
|
146
|
+
headers = {'Accept': 'application/json'}
|
|
147
|
+
return self._request(fill_query_params(kwargs.pop('path'), reportId),
|
|
148
|
+
params=kwargs, headers=headers)
|
ad_api/api/locations.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Locations /locations/list.
|
|
2
|
+
|
|
3
|
+
Contract: Locations 3.0. One ``POST`` route, plain ``application/json`` in the
|
|
4
|
+
body and in the answer, so there is no media type version to build here. It is
|
|
5
|
+
the second child of *Discovery*, next to *Targetable entities*.
|
|
6
|
+
|
|
7
|
+
**US only, and that is two things at once.** The route lives in the NA
|
|
8
|
+
partition, so a US profile must go to ``advertising-api.amazon.com``: sent to
|
|
9
|
+
the EU host it answers ``400 Profile not found``. And even in the right
|
|
10
|
+
partition an EU profile, which is legitimate on the EU host, gets ``200`` with
|
|
11
|
+
``{"locations": []}``: the route only carries data for the United States.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from ad_api.base import Client, sp_endpoint, fill_query_params, ApiResponse, Utils
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Locations(Client):
|
|
18
|
+
r"""Locations - /locations/list
|
|
19
|
+
|
|
20
|
+
Documentation: https://advertising.amazon.com/API/docs/en-us/locations
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
@sp_endpoint('/locations/list', method='POST',
|
|
24
|
+
headers=['Amazon-Advertising-API-Scope'])
|
|
25
|
+
def list_locations(self, **kwargs) -> ApiResponse:
|
|
26
|
+
r"""
|
|
27
|
+
Lists the locations that match the filters given. Read only.
|
|
28
|
+
|
|
29
|
+
Request Body [Required in practice]
|
|
30
|
+
| **filters** (list): at least one filter. The contract does not
|
|
31
|
+
| mark it required, but sending a body without it answers
|
|
32
|
+
| ``400 Value null at ``filters`` failed to satisfy constraint``.
|
|
33
|
+
|
|
34
|
+
Each filter takes ``field`` and ``values``:
|
|
35
|
+
|
|
36
|
+
- ``field`` (str): ``locationId``, ``name`` or ``category``.
|
|
37
|
+
- ``values`` (list): the values to match. The ``name`` field is a
|
|
38
|
+
fuzzy search; for ``category`` the values are ``CITY``, ``STATE``,
|
|
39
|
+
``DMA``, ``COUNTRY`` or ``POSTAL_CODE``.
|
|
40
|
+
|
|
41
|
+
The filters combine with AND: an item must match all of them.
|
|
42
|
+
|
|
43
|
+
Returns
|
|
44
|
+
ApiResponse with ``locations``, a list of items carrying
|
|
45
|
+
``locationId``, ``name`` and ``category``. There is no pagination
|
|
46
|
+
in the answer.
|
|
47
|
+
|
|
48
|
+
**US only.** A US profile answers on the NA host; on the EU host it is
|
|
49
|
+
``400 Profile not found``. An EU profile on its own host answers ``200``
|
|
50
|
+
with ``locations: []``, because the route only carries data for the
|
|
51
|
+
United States.
|
|
52
|
+
"""
|
|
53
|
+
headers = {'Accept': 'application/json',
|
|
54
|
+
'Content-Type': 'application/json'}
|
|
55
|
+
body = Utils.convert_body(kwargs.pop('body'), False)
|
|
56
|
+
return self._request(fill_query_params(kwargs.pop('path')),
|
|
57
|
+
data=body, params=kwargs, headers=headers)
|