Class: Printful::ReportsAPIClient

Inherits:
Object
  • Object
show all
Defined in:
lib/printful_client/api/reports_api_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ ReportsAPIClient

Returns a new instance of ReportsAPIClient.



19
20
21
# File 'lib/printful_client/api/reports_api_client.rb', line 19

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

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



17
18
19
# File 'lib/printful_client/api/reports_api_client.rb', line 17

def api_client
  @api_client
end

Instance Method Details

#get_statistics(date_from, date_to, report_types, opts = {}) ⇒ GetStatistics200Response

Get statistics Returns statistics for specified report types. You need to specify the report types you want to retrieve in the ‘report_types` query parameter as a comma-separated list, e.g. `report_types=sales_and_costs,profit`. Note: You cannot get statistics for a period longer than 6 months. #### Example To get statistics in the default currency of a store for `sales_and_costs` and `profit` reports for August 2022, you can use the following URL: api.printful.com/reports/statistics?report_types=sales_and_costs,profit&date_from=2022-08-01&date_to=2022-08-31. ### Report types Currently, the following report types are available: | Report type | Description | |—————————-|———————————————————-| | `sales_and_costs` | Detailed information on sales and costs grouped by date. | | `sales_and_costs_summary` | Short information on sales and costs grouped by date. | | `printful_costs` | Amount paid to Printful for fulfillment and shipping. | | `profit` | Profit in the specified period. | | `total_paid_orders` | The number of paid orders in the specified period. | | `costs_by_amount` | Information on costs by amount grouped by date. | | `costs_by_product` | Information on costs grouped by product. | | `costs_by_variant` | Information on costs grouped by variant. | | `average_fulfillment_time` | Average time it took Printful to fulfill Your orders. | The response structure for the specific reports is documented in the response schema (`result.store_statistics.`).

Parameters:

  • date_from (Date)

    The beginning of the period to get the statistics from (date in `Y-m-d` format).

  • date_to (Date)

    The end of the period to get the statistics from (date in `Y-m-d` format).

  • report_types (String)

    A comma-separated list of report types to be retrieved.

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

    the optional parameters

Options Hash (opts):

  • :x_pf_store_id (String)

    Use this to specify which store you want to use (required only for account level token)

  • :currency (String)

    The currency (3-letter code) to return the statistics in. You can also specify `display_currency` as the value to get the statistics in the account's display currency. The store currency will be used by default.

Returns:



31
32
33
34
# File 'lib/printful_client/api/reports_api_client.rb', line 31

def get_statistics(date_from, date_to, report_types, opts = {})
  data, _status_code, _headers = get_statistics_with_http_info(date_from, date_to, report_types, opts)
  data
end

#get_statistics_with_http_info(date_from, date_to, report_types, opts = {}) ⇒ Array<(GetStatistics200Response, Integer, Hash)>

Get statistics Returns statistics for specified report types. You need to specify the report types you want to retrieve in the &#x60;report_types&#x60; query parameter as a comma-separated list, e.g. &#x60;report_types&#x3D;sales_and_costs,profit&#x60;. Note: You cannot get statistics for a period longer than 6 months. #### Example To get statistics in the default currency of a store for &#x60;sales_and_costs&#x60; and &#x60;profit&#x60; reports for August 2022, you can use the following URL: api.printful.com/reports/statistics?report_types&#x3D;sales_and_costs,profit&amp;date_from&#x3D;2022-08-01&amp;date_to&#x3D;2022-08-31. ### Report types Currently, the following report types are available: | Report type | Description | |—————————-|———————————————————-| | &#x60;sales_and_costs&#x60; | Detailed information on sales and costs grouped by date. | | &#x60;sales_and_costs_summary&#x60; | Short information on sales and costs grouped by date. | | &#x60;printful_costs&#x60; | Amount paid to Printful for fulfillment and shipping. | | &#x60;profit&#x60; | Profit in the specified period. | | &#x60;total_paid_orders&#x60; | The number of paid orders in the specified period. | | &#x60;costs_by_amount&#x60; | Information on costs by amount grouped by date. | | &#x60;costs_by_product&#x60; | Information on costs grouped by product. | | &#x60;costs_by_variant&#x60; | Information on costs grouped by variant. | | &#x60;average_fulfillment_time&#x60; | Average time it took Printful to fulfill Your orders. | The response structure for the specific reports is documented in the response schema (&#x60;result.store_statistics.&#x60;).

Parameters:

  • date_from (Date)

    The beginning of the period to get the statistics from (date in &#x60;Y-m-d&#x60; format).

  • date_to (Date)

    The end of the period to get the statistics from (date in &#x60;Y-m-d&#x60; format).

  • report_types (String)

    A comma-separated list of report types to be retrieved.

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

    the optional parameters

Options Hash (opts):

  • :x_pf_store_id (String)

    Use this to specify which store you want to use (required only for account level token)

  • :currency (String)

    The currency (3-letter code) to return the statistics in. You can also specify &#x60;display_currency&#x60; as the value to get the statistics in the account&#39;s display currency. The store currency will be used by default.

Returns:

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

    GetStatistics200Response data, response status code and response headers



45
46
47
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
# File 'lib/printful_client/api/reports_api_client.rb', line 45

def get_statistics_with_http_info(date_from, date_to, report_types, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ReportsAPIClient.get_statistics ...'
  end
  # verify the required parameter 'date_from' is set
  if @api_client.config.client_side_validation && date_from.nil?
    fail ArgumentError, "Missing the required parameter 'date_from' when calling ReportsAPIClient.get_statistics"
  end
  # verify the required parameter 'date_to' is set
  if @api_client.config.client_side_validation && date_to.nil?
    fail ArgumentError, "Missing the required parameter 'date_to' when calling ReportsAPIClient.get_statistics"
  end
  # verify the required parameter 'report_types' is set
  if @api_client.config.client_side_validation && report_types.nil?
    fail ArgumentError, "Missing the required parameter 'report_types' when calling ReportsAPIClient.get_statistics"
  end
  # resource path
  local_var_path = '/reports/statistics'

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'date_from'] = date_from
  query_params[:'date_to'] = date_to
  query_params[:'report_types'] = report_types
  query_params[:'currency'] = opts[:'currency'] if !opts[:'currency'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  header_params[:'X-PF-Store-Id'] = opts[:'x_pf_store_id'] if !opts[:'x_pf_store_id'].nil?

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

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

  # return_type
  return_type = opts[:debug_return_type] || 'GetStatistics200Response'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['OAuth']

  new_options = opts.merge(
    :operation => :"ReportsAPIClient.get_statistics",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ReportsAPIClient#get_statistics\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end