Class: Peddler::APIs::SalesV1

Inherits:
Peddler::API show all
Defined in:
lib/peddler/apis/sales_v1.rb,
lib/peddler/apis/sales_v1/error.rb,
lib/peddler/apis/sales_v1/error_list.rb,
lib/peddler/apis/sales_v1/order_metrics_list.rb,
lib/peddler/apis/sales_v1/order_metrics_interval.rb,
lib/peddler/apis/sales_v1/get_order_metrics_response.rb

Overview

Selling Partner API for Sales

The Selling Partner API for Sales provides APIs related to sales performance.

Defined Under Namespace

Classes: ErrorList, OrderMetricsList

Constant Summary collapse

Error =

Error response returned when the request is unsuccessful.

Structure.new do
  # @return [String] An error code that identifies the type of error that occured.
  attribute(:code, String)

  # @return [String] A message that describes the error condition in a human-readable form.
  attribute(:message, String)

  # @return [String] Additional details that can help the caller understand or fix the issue.
  attribute?(:details, String)
end
OrderMetricsInterval =

Contains order metrics.

Structure.new do
  # @return [Money] The average price for an item based on the specified filters. Formula is totalSales/unitCount.
  attribute(:average_unit_price, Money, from: "averageUnitPrice")

  # @return [String] The interval of time based on requested granularity (ex. Hour, Day, etc.) If this is the
  #   first or the last interval from the list, it might contain incomplete data if the requested interval doesn't
  #   align with the requested granularity (ex. request interval 2018-09-01T02:00:00Z--2018-09-04T19:00:00Z and
  #   granularity day will result in Sept 1st UTC day and Sept 4th UTC days having partial data).
  attribute(:interval, String)

  # @return [Integer] The number of orders based on the specified filters.
  attribute(:order_count, Integer, from: "orderCount")

  # @return [Integer] The number of order items based on the specified filters.
  attribute(:order_item_count, Integer, from: "orderItemCount")

  # @return [Money] The total ordered product sales for all orders based on the specified filters.
  attribute(:total_sales, Money, from: "totalSales")

  # @return [Integer] The number of units in orders based on the specified filters.
  attribute(:unit_count, Integer, from: "unitCount")
end
GetOrderMetricsResponse =

The response schema for the getOrderMetrics operation.

Structure.new do
  # @return [Array<Error>] Encountered errors for the getOrderMetrics operation.
  attribute?(:errors, [Error])

  # @return [Array<OrderMetricsInterval>] The payload for the getOrderMetrics operation.
  attribute?(:payload, [OrderMetricsInterval])
end

Instance Attribute Summary

Attributes inherited from Peddler::API

#access_token, #endpoint, #retries

Instance Method Summary collapse

Methods inherited from Peddler::API

#endpoint_uri, #http, #initialize, #sandbox, #sandbox?

Constructor Details

This class inherits a constructor from Peddler::API

Instance Method Details

#get_order_metrics(marketplace_ids, interval, granularity, granularity_time_zone: nil, buyer_type: "All", fulfillment_network: nil, first_day_of_week: "Monday", asin: nil, sku: nil, amazon_program: nil, rate_limit: 0.5) ⇒ Peddler::Response

Note:

This operation can make a static sandbox call.

Returns aggregated order metrics for given interval, broken down by granularity, for given buyer type.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/peddler/apis/sales_v1.rb', line 57

def get_order_metrics(marketplace_ids, interval, granularity, granularity_time_zone: nil, buyer_type: "All",
  fulfillment_network: nil, first_day_of_week: "Monday", asin: nil, sku: nil, amazon_program: nil,
  rate_limit: 0.5)
  path = "/sales/v1/orderMetrics"
  params = {
    "marketplaceIds" => stringify_array(marketplace_ids),
    "interval" => interval,
    "granularityTimeZone" => granularity_time_zone,
    "granularity" => granularity,
    "buyerType" => buyer_type,
    "fulfillmentNetwork" => fulfillment_network,
    "firstDayOfWeek" => first_day_of_week,
    "asin" => asin,
    "sku" => sku,
    "amazonProgram" => amazon_program,
  }.compact
  parser = -> { GetOrderMetricsResponse }
  get(path, params:, rate_limit:, parser:)
end