Files
ozon-api-client/ozon/analytics.go
2023-06-23 20:57:38 +03:00

173 lines
4.6 KiB
Go

package ozon
import (
"net/http"
"time"
core "github.com/diphantxm/ozon-api-client"
)
type Analytics struct {
client *core.Client
}
type GetAnalyticsDataParams struct {
// Date from which the data will be in the report
DateFrom time.Time `json:"date_from"`
// Date up to which the data will be in the report
DateTo time.Time `json:"date_to"`
// Items Enum: "unknownDimension" "sku" "spu" "day" "week" "month" "year" "category1" "category2" "category3" "category4" "brand" "modelID"
Dimension []GetAnalyticsDataDimension `json:"dimension"`
// Filters
Filters []GetAnalyticsDataFilter `json:"filters"`
// Number of items in the respones:
// - maximum is 1000,
// - minimum is 1.
Limit int64 `json:"limit"`
// Specify up to 14 metrics. If there are more, you will get an error with the InvalidArgument code
Metrics []GetAnalyticsDataFilterMetric `json:"metrics"`
// Number of elements that will be skipped in the response. For example, if `offset=10`, the response will start with the 11th element found
Offset int64 `json:"offset"`
// Report sorting settings
Sort []GetAnalyticsDataSort `json:"sort"`
}
type GetAnalyticsDataFilter struct {
// Sorting parameter. You can pass any attribute from the `dimension` and `metric` parameters except the `brand` attribute
Key string `json:"key"`
// Comparison operation
Operation GetAnalyticsDataFilterOperation `json:"operation"`
// Value for comparison
Value string `json:"value"`
}
// Report sorting settings
type GetAnalyticsDataSort struct {
// Metric by which the method result will be sorted
Key GetAnalyticsDataFilterMetric `json:"key"`
// Sorting type
Order Order `json:"order"`
}
type GetAnalyticsDataResponse struct {
core.CommonResponse
// Method result
Result GetAnalyticsDataResult `json:"result"`
// Report creation time
Timestamp string `json:"timestamp"`
}
type GetAnalyticsDataResult struct {
// Data array
Data []GetAnalyticsDataResultData `json:"data"`
// Total and average metrics values
Totals []float64 `json:"totals"`
}
type GetAnalyticsDataResultData struct {
// Data grouping in the report
Dimensions []GetAnalyticsDataResultDimension `json:"dimensions"`
// Metric values list
Metrics []float64 `json:"metrics"`
}
type GetAnalyticsDataResultDimension struct {
// Identifier
Id string `json:"id"`
// Name
Name string `json:"name"`
}
// Specify the period and metrics that are required. The response will contain analytical data grouped by the `dimensions` parameter.
func (c Analytics) GetAnalyticsData(params *GetAnalyticsDataParams) (*GetAnalyticsDataResponse, error) {
url := "/v1/analytics/data"
resp := &GetAnalyticsDataResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}
type GetStocksOnWarehousesParams struct {
// Number of values per page.
//
// Default is 100
Limit int64 `json:"limit" default:"100"`
// Number of elements that will be skipped in the response. For example, if `offset=10`, the response will start with the 11th element found
Offset int64 `json:"offset"`
// Warehouse type filter:
WarehouseType WarehouseType `json:"warehouse_type"`
}
type GetStocksOnWarehousesResponse struct {
core.CommonResponse
// Method result
Result GetStocksOnWarehousesResult `json:"result"`
}
type GetStocksOnWarehousesResult struct {
// Information about products and stocks
Rows []GetStocksOnWarehousesResultRow `json:"rows"`
}
type GetStocksOnWarehousesResultRow struct {
// Product identifier in the Ozon system, SKU
SKU int64 `json:"sku"`
// Product identifier in the seller's system
ItemCode string `json:"item_code"`
// Product name in the Ozon system
ItemName string `json:"item_name"`
// Product amount available for sale on Ozon
FreeToSellAmount int64 `json:"free_to_sell_amount"`
// Product amount specified for confirmed future supplies
PromisedAmount int64 `json:"promised_amount"`
// Product amount reserved for purchase, returns, and transportation between warehouses
ReservedAmount int64 `json:"reserved_amount"`
// Name of the warehouse where the products are stored
WarehouseName string `json:"warehouse_name"`
}
// Report on stocks and products movement at Ozon warehouses
func (c Analytics) GetStocksOnWarehouses(params *GetStocksOnWarehousesParams) (*GetStocksOnWarehousesResponse, error) {
url := "/v2/analytics/stock_on_warehouses"
resp := &GetStocksOnWarehousesResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}