Class: AmzSpApi::SalesApiModel::SalesApi

Inherits:
Object
  • Object
show all
Defined in:
lib/sales-api-model/api/sales_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ SalesApi

Returns a new instance of SalesApi.



16
17
18
# File 'lib/sales-api-model/api/sales_api.rb', line 16

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



14
15
16
# File 'lib/sales-api-model/api/sales_api.rb', line 14

def api_client
  @api_client
end

Instance Method Details

#get_order_metrics(marketplace_ids, interval, granularity, opts = {}) ⇒ GetOrderMetricsResponse

Returns aggregated order metrics for given interval, broken down by granularity, for given buyer type. **Usage Plan:** | Rate (requests per second) | Burst | | —- | —- | | .5 | 15 | The ‘x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).

Parameters:

  • marketplace_ids

    A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified. For example, ATVPDKIKX0DER indicates the US marketplace.

  • interval

    A time interval used for selecting order metrics. This takes the form of two dates separated by two hyphens (first date is inclusive; second date is exclusive). Dates are in ISO8601 format and must represent absolute time (either Z notation or offset notation). Example: 2018-09-01T00:00:00-07:00–2018-09-04T00:00:00-07:00 requests order metrics for Sept 1st, 2nd and 3rd in the -07:00 zone.

  • granularity

    The granularity of the grouping of order metrics, based on a unit of time. Specifying granularity=Hour results in a successful request only if the interval specified is less than or equal to 30 days from now. For all other granularities, the interval specified must be less or equal to 2 years from now. Specifying granularity=Total results in order metrics that are aggregated over the entire interval that you specify. If the interval start and end date don’t align with the specified granularity, the head and tail end of the response interval will contain partial data. Example: Day to get a daily breakdown of the request interval, where the day boundary is defined by the granularityTimeZone.

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :granularity_time_zone (String)

    An IANA-compatible time zone for determining the day boundary. Required when specifying a granularity value greater than Hour. The granularityTimeZone value must align with the offset of the specified interval value. For example, if the interval value uses Z notation, then granularityTimeZone must be UTC. If the interval value uses an offset, then granularityTimeZone must be an IANA-compatible time zone that matches the offset. Example: US/Pacific to compute day boundaries, accounting for daylight time savings, for US/Pacific zone.

  • :buyer_type (String)

    Filters the results by the buyer type that you specify, B2B (business to business) or B2C (business to customer). Example: B2B, if you want the response to include order metrics for only B2B buyers. (default to All)

  • :fulfillment_network (String)

    Filters the results by the fulfillment network that you specify, MFN (merchant fulfillment network) or AFN (Amazon fulfillment network). Do not include this filter if you want the response to include order metrics for all fulfillment networks. Example: AFN, if you want the response to include order metrics for only Amazon fulfillment network.

  • :first_day_of_week (String)

    Specifies the day that the week starts on when granularity=Week, either Monday or Sunday. Default: Monday. Example: Sunday, if you want the week to start on a Sunday. (default to Monday)

  • :asin (String)

    Filters the results by the ASIN that you specify. Specifying both ASIN and SKU returns an error. Do not include this filter if you want the response to include order metrics for all ASINs. Example: B0792R1RSN, if you want the response to include order metrics for only ASIN B0792R1RSN.

  • :sku (String)

    Filters the results by the SKU that you specify. Specifying both ASIN and SKU returns an error. Do not include this filter if you want the response to include order metrics for all SKUs. Example: TestSKU, if you want the response to include order metrics for only SKU TestSKU.

Returns:



31
32
33
34
# File 'lib/sales-api-model/api/sales_api.rb', line 31

def get_order_metrics(marketplace_ids, interval, granularity, opts = {})
  data, _status_code, _headers = get_order_metrics_with_http_info(marketplace_ids, interval, granularity, opts)
  data
end

#get_order_metrics_with_http_info(marketplace_ids, interval, granularity, opts = {}) ⇒ Array<(GetOrderMetricsResponse, Integer, Hash)>

Returns aggregated order metrics for given interval, broken down by granularity, for given buyer type. **Usage Plan:** | Rate (requests per second) | Burst | | —- | —- | | .5 | 15 | The &#x60;x-amzn-RateLimit-Limit&#x60; response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).

Parameters:

  • marketplace_ids

    A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified. For example, ATVPDKIKX0DER indicates the US marketplace.

  • interval

    A time interval used for selecting order metrics. This takes the form of two dates separated by two hyphens (first date is inclusive; second date is exclusive). Dates are in ISO8601 format and must represent absolute time (either Z notation or offset notation). Example: 2018-09-01T00:00:00-07:00–2018-09-04T00:00:00-07:00 requests order metrics for Sept 1st, 2nd and 3rd in the -07:00 zone.

  • granularity

    The granularity of the grouping of order metrics, based on a unit of time. Specifying granularity&#x3D;Hour results in a successful request only if the interval specified is less than or equal to 30 days from now. For all other granularities, the interval specified must be less or equal to 2 years from now. Specifying granularity&#x3D;Total results in order metrics that are aggregated over the entire interval that you specify. If the interval start and end date don’t align with the specified granularity, the head and tail end of the response interval will contain partial data. Example: Day to get a daily breakdown of the request interval, where the day boundary is defined by the granularityTimeZone.

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :granularity_time_zone (String)

    An IANA-compatible time zone for determining the day boundary. Required when specifying a granularity value greater than Hour. The granularityTimeZone value must align with the offset of the specified interval value. For example, if the interval value uses Z notation, then granularityTimeZone must be UTC. If the interval value uses an offset, then granularityTimeZone must be an IANA-compatible time zone that matches the offset. Example: US/Pacific to compute day boundaries, accounting for daylight time savings, for US/Pacific zone.

  • :buyer_type (String)

    Filters the results by the buyer type that you specify, B2B (business to business) or B2C (business to customer). Example: B2B, if you want the response to include order metrics for only B2B buyers.

  • :fulfillment_network (String)

    Filters the results by the fulfillment network that you specify, MFN (merchant fulfillment network) or AFN (Amazon fulfillment network). Do not include this filter if you want the response to include order metrics for all fulfillment networks. Example: AFN, if you want the response to include order metrics for only Amazon fulfillment network.

  • :first_day_of_week (String)

    Specifies the day that the week starts on when granularity&#x3D;Week, either Monday or Sunday. Default: Monday. Example: Sunday, if you want the week to start on a Sunday.

  • :asin (String)

    Filters the results by the ASIN that you specify. Specifying both ASIN and SKU returns an error. Do not include this filter if you want the response to include order metrics for all ASINs. Example: B0792R1RSN, if you want the response to include order metrics for only ASIN B0792R1RSN.

  • :sku (String)

    Filters the results by the SKU that you specify. Specifying both ASIN and SKU returns an error. Do not include this filter if you want the response to include order metrics for all SKUs. Example: TestSKU, if you want the response to include order metrics for only SKU TestSKU.

Returns:

  • (Array<(GetOrderMetricsResponse, Integer, Hash)>)

    GetOrderMetricsResponse data, response status code and response headers



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/sales-api-model/api/sales_api.rb', line 48

def get_order_metrics_with_http_info(marketplace_ids, interval, granularity, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: SalesApi.get_order_metrics ...'
  end
  # verify the required parameter 'marketplace_ids' is set
  if @api_client.config.client_side_validation && marketplace_ids.nil?
    fail ArgumentError, "Missing the required parameter 'marketplace_ids' when calling SalesApi.get_order_metrics"
  end
  # verify the required parameter 'interval' is set
  if @api_client.config.client_side_validation && interval.nil?
    fail ArgumentError, "Missing the required parameter 'interval' when calling SalesApi.get_order_metrics"
  end
  # verify the required parameter 'granularity' is set
  if @api_client.config.client_side_validation && granularity.nil?
    fail ArgumentError, "Missing the required parameter 'granularity' when calling SalesApi.get_order_metrics"
  end
  # verify enum value
  if @api_client.config.client_side_validation && !['Hour', 'Day', 'Week', 'Month', 'Year', 'Total'].include?(granularity)
    fail ArgumentError, "invalid value for 'granularity', must be one of Hour, Day, Week, Month, Year, Total"
  end
  if @api_client.config.client_side_validation && opts[:'buyer_type'] && !['B2B', 'B2C', 'All'].include?(opts[:'buyer_type'])
    fail ArgumentError, 'invalid value for "buyer_type", must be one of B2B, B2C, All'
  end
  if @api_client.config.client_side_validation && opts[:'first_day_of_week'] && !['Monday', 'Sunday'].include?(opts[:'first_day_of_week'])
    fail ArgumentError, 'invalid value for "first_day_of_week", must be one of Monday, Sunday'
  end
  # resource path
  local_var_path = '/sales/v1/orderMetrics'

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'marketplaceIds'] = @api_client.build_collection_param(marketplace_ids, :csv)
  query_params[:'interval'] = interval
  query_params[:'granularity'] = granularity
  query_params[:'granularityTimeZone'] = opts[:'granularity_time_zone'] if !opts[:'granularity_time_zone'].nil?
  query_params[:'buyerType'] = opts[:'buyer_type'] if !opts[:'buyer_type'].nil?
  query_params[:'fulfillmentNetwork'] = opts[:'fulfillment_network'] if !opts[:'fulfillment_network'].nil?
  query_params[:'firstDayOfWeek'] = opts[:'first_day_of_week'] if !opts[:'first_day_of_week'].nil?
  query_params[:'asin'] = opts[:'asin'] if !opts[:'asin'].nil?
  query_params[:'sku'] = opts[:'sku'] if !opts[:'sku'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json', 'payload'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:body] 

  return_type = opts[:return_type] || 'GetOrderMetricsResponse' 

  auth_names = opts[:auth_names] || []
  data, status_code, headers = @api_client.call_api(:GET, local_var_path,
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type)

  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: SalesApi#get_order_metrics\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end