Skip to content

Commit 7ce5964

Browse files
author
vlad-outscraper
committed
add amazon SDK
1 parent 68b9b69 commit 7ce5964

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

outscraper/api_client.py

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def emails_and_contacts(self, query: list, fields: list = None) -> list:
477477
478478
Parameters:
479479
query (list | str): Domains or links (e.g., outscraper.com).
480-
fields (list): parameter defines which fields you want to include with each item returned in the response. By default, it returns all fields.
480+
fields (list): Parameter defines which fields you want to include with each item returned in the response. By default, it returns all fields.
481481
482482
Returns:
483483
list: json result
@@ -516,3 +516,69 @@ def phones_enricher(self, query: list, fields: list = None) -> list:
516516
return self._wait_request_archive(response.json()['id']).get('data', [])
517517

518518
raise Exception(f'Response status code: {response.status_code}')
519+
520+
def amazon_products(self, query: Union[list, str], limit: int = 24, fields: list = None, async_request: bool = False, ui: bool = None
521+
) -> Union[list, dict]:
522+
'''
523+
Returns information about products on Amazon.
524+
525+
Parameters:
526+
query (list | str): Amazon product or summary pages URLs.
527+
limit (int): The parameter specifies the limit of products to get from one query (in case of using summary pages).
528+
fields (list): Parameter defines which fields you want to include with each item returned in the response. By default, it returns all fields.
529+
async_request (bool): Parameter defines the way you want to submit your task to Outscraper. It can be set to `False` (default) to send a task and wait until you got your results, or `True` to submit your task and retrieve the results later using a request ID with `get_request_archive`. Each response is available for `2` hours after a request has been completed.
530+
ui (bool): Parameter defines whether a task will be executed as a UI task. This is commonly used when you want to create a regular platform task with API. Using this parameter overwrites the async_request parameter to `True`.
531+
532+
Returns:
533+
list: json result
534+
535+
See: https://app.outscraper.com/api-docs#tag/Amazon/paths/~1amazon~1products/get
536+
'''
537+
queries = as_list(query)
538+
wait_async = async_request or (len(queries) > 1 and limit > 1)
539+
540+
response = requests.get(f'{self._api_url}/amazon/products', params={
541+
'query': queries,
542+
'limit': limit,
543+
'async': wait_async,
544+
'fields': ','.join(fields) if fields else '',
545+
'ui': ui,
546+
}, headers=self._api_headers)
547+
548+
return self._handle_response(response, wait_async, async_request)
549+
550+
def amazon_reviews(self, query: Union[list, str], limit: int = 10, sort: str = 'helpful', filter_by_reviewer: str = 'all_reviews', filter_by_star: str = 'all_stars', fields: list = None, async_request: bool = False, ui: bool = None
551+
) -> Union[list, dict]:
552+
'''
553+
Returns reviews from Amazon products.
554+
555+
Parameters:
556+
query (list | str): You can use URLs or ASINs from Amazon products (e.g., https://www.amazon.com/dp/1612680194, 1612680194, etc.).
557+
limit (int): Parameter specifies the limit of reviews to get from one query.
558+
sort (str): Parameter specifies one of the sorting types. Available values: "helpful", and "recent".
559+
filter_by_reviewer (str): The parameter specifies one of the reviewer filter types (All reviewers / Verified purchase only). Available values: "all_reviews", and "avp_only_reviews".
560+
filter_by_star (str): The parameter specifies one of the filter types by stars. Available values: "all_stars", "five_star", "four_star", "three_star", "two_star", "one_star", "positive", and "critical".
561+
fields (list): Parameter defines which fields you want to include with each item returned in the response. By default, it returns all fields.
562+
async_request (bool): Parameter defines the way you want to submit your task to Outscraper. It can be set to `False` (default) to send a task and wait until you got your results, or `True` to submit your task and retrieve the results later using a request ID with `get_request_archive`. Each response is available for `2` hours after a request has been completed.
563+
ui (bool): Parameter defines whether a task will be executed as a UI task. This is commonly used when you want to create a regular platform task with API. Using this parameter overwrites the async_request parameter to `True`.
564+
565+
Returns:
566+
list: json result
567+
568+
See: https://app.outscraper.com/api-docs#tag/Amazon/paths/~1amazon~1reviews/get
569+
'''
570+
queries = as_list(query)
571+
wait_async = async_request or (len(queries) > 1 and limit > 10)
572+
573+
response = requests.get(f'{self._api_url}/amazon/reviews', params={
574+
'query': queries,
575+
'limit': limit,
576+
'sort': sort,
577+
'filterByReviewer': filter_by_reviewer,
578+
'filterByStar': filter_by_star,
579+
'async': wait_async,
580+
'fields': ','.join(fields) if fields else '',
581+
'ui': ui,
582+
}, headers=self._api_headers)
583+
584+
return self._handle_response(response, wait_async, async_request)

0 commit comments

Comments
 (0)