Snapshots
- class ad_api.api.sp.Snapshots(account='default', marketplace: Marketplaces = Marketplaces.EU, credentials=None, proxies=None, verify=True, timeout=None, debug=False, access_token=None)
Use the Amazon Advertising API for Sponsored Products for campaign, ad group, keyword, negative keyword, and product ad management operations. For more information about Sponsored Products, see the Sponsored Products Support Center. For onboarding information, see the account setup topic.
- post_snapshot(self, recordType, **kwargs) ApiResponse:
Request a file-based snapshot of all entities of the specified type in the account satisfying the filtering criteria.
- Keyword Args
- path recordType (integer): The type of entity for which the snapshot is generated. Available values : campaigns, adGroups, keywords, negativeKeywords, campaignNegativeKeywords, productAds, targets, negativeTargets [required]
- Request body
- stateFilter (string): [required] [ enabled, paused, archived, enabled, paused, enabled, archived, paused, archived, enabled, paused, archived ].
- Returns:
ApiResponse
### Example python
from ad_api.api.sp.snapshots import Snapshots file = open("request.json") data = file.read() file.close() # Available values : campaigns, adGroups, keywords, negativeKeywords, campaignNegativeKeywords, productAds, targets, negativeTargets record_type = 'campaigns' result = Snapshots().post_snapshot( recordType=record_type, body=data )
### Example json
Open this
json
file to see the result:{ "stateFilter": "enabled" }
- get_snapshot(self, reportId, **kwargs) ApiResponse:
Gets the status of a requested snapshot.
- Keyword Args
- path snapshotId (number): The snapshot identifier. [required]
- Returns:
ApiResponse
### Example python
from ad_api.api.sp.snapshots import Snapshots # this snapshot_id is obtained from post_snapshot method snapshot_id = "amzn1.clicksAPI.v1.p44551.614D9309.84477233-ccc8-4591-80f2-1f96b7ea9c7e" result = Snapshots().get_snapshot( snapshotId=snapshot_id )
### Result json
{'expiration': 1640304000000, 'fileSize': 1241, 'location': 'https://advertising-api-eu.amazon.com/v1/snapshots/amzn1.clicksAPI.v1.p44551.614D9309.84477233-ccc8-4591-80f2-1f96b7ea9c7e/download', 'snapshotId': 'amzn1.clicksAPI.v1.p44551.614D9309.84477233-ccc8-4591-80f2-1f96b7ea9c7e', 'status': 'SUCCESS', 'statusDetails': 'Snapshot has been successfully generated.'}}
- download_snapshot(self, **kwargs) ApiResponse:
Downloads the snapshot previously get report specified by location (this is not part of the official Amazon Advertising API, is a helper method to download the snapshot). Take in mind that a direct download of location returned in get_snapshot will return 401 - Unauthorized.
kwarg parameter file if not provided will take the default amazon name from path download (add a path with slash / if you want a specific folder, do not add extension as the return will provide the right extension based on format choosed if needed)
kwarg parameter format if not provided a format will return a url to download the snapshot (this url has a expiration time)
- Keyword Args
- url (string): The location obatined from get_snapshot [required]file (string): The path to save the file if mode is download json, zip or gzip. [optional]format (string): The mode to download the snapshot: data (list), raw, url, json, zip, gzip. Default (url) [optional]
- Returns:
ApiResponse
Warning
This method is not a part of the Amazon Advertising Api.
### Example python
from ad_api.api.sp.snapshots import Snapshots # the url=location is obtained from get_snapshot method need to in stay 'status': 'SUCCESS' if is 'IN_PROGRESS' the snapshot cannot be downloaded location = 'https://advertising-api-eu.amazon.com/v1/snapshots/amzn1.clicksAPI.v1.p44551.614D9309.84477233-ccc8-4591-80f2-1f96b7ea9c7e/download' # path = '/Users/your-profile/Downloads/report_name' # mode = "data" # "data (list), raw, url, json, zip, gzip default is url" result = Reports().download_report( url=location, # file=path, # format=mode )