Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OptimizationRules class to API #181

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ad_api/api/sp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from .budget_rules_recommendations import BudgetRulesRecommendations
from .product_recommendations import ProductRecommendations
from .campaigns_budget_usage import CampaignsBudgetUsage
from .schedule_based_bid_optimization import ScheduleBasedBidOptimizationRules

__all__ = [
"Campaigns",
Expand Down Expand Up @@ -61,4 +62,6 @@
"BudgetRulesRecommendations",
"ProductRecommendations",
"CampaignsBudgetUsage",
"ScheduleBasedBidOptimizationRules",
"BidRecommendationsV3",
]
63 changes: 63 additions & 0 deletions ad_api/api/sp/schedule_based_bid_optimization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

from typing import Any

from ad_api.base import ApiResponse, Client, Utils, fill_query_params, sp_endpoint


class ScheduleBasedBidOptimizationRules(Client):
"""
A class representing the Amazon Advertising API endpoint for Schedule Based Bid Optimization Rules.
https://advertising.amazon.com/API/docs/en-us/sponsored-products/3-0/openapi/prod#tag/Optimization-Rules

Methods
-------
create_optimization_rules(**kwargs)
Creates a new optimization rule.
update_optimization_rules(**kwargs)
Updates an existing optimization rule.
associate_optimization_rules_with_campaign(campaignId, **kwargs)
Associates an optimization rule with a campaign.
searches_optimization_rules(**kwargs)
Searches for optimization rules that match the specified criteria.
"""

HEADERS = {
"Content-Type": "application/vnd.spoptimizationrules.v1+json",
"Accept": "application/vnd.spoptimizationrules.v1+json",
}

@sp_endpoint('/sp/rules/optimization', method='POST')
def create_optimization_rules(self, **kwargs: dict[str, Any]) -> ApiResponse:
return self._request(
str(kwargs.pop('path')),
data=Utils.convert_body(kwargs.pop('body'), False),
params=kwargs,
headers=self.HEADERS,
)

@sp_endpoint('/sp/rules/optimization', method='PUT')
def update_optimization_rules(self, **kwargs: dict[str, Any]) -> ApiResponse:
return self._request(
str(kwargs.pop('path')),
data=Utils.convert_body(kwargs.pop('body'), False),
params=kwargs,
headers=self.HEADERS,
)

@sp_endpoint('/sp/campaigns/{}/optimizationRules', method='POST')
def associate_optimization_rules_with_campaign(self, campaignId: str, **kwargs: dict[str, Any]) -> ApiResponse:
return self._request(
fill_query_params(kwargs.pop('path'), campaignId),
data=Utils.convert_body(kwargs.pop('body'), False),
params=kwargs,
headers=self.HEADERS,
)

@sp_endpoint('/sp/rules/optimization/search', method='POST')
def searches_optimization_rules(self, **kwargs: dict[str, Any]) -> ApiResponse:
return self._request(
str(kwargs.pop('path')),
data=Utils.convert_body(kwargs.pop('body'), False),
params=kwargs,
headers=self.HEADERS,
)
Loading