9 Commits

Author SHA1 Message Date
Kirill
40dd5b86a8 Update October 26, 2023 (#46) 2023-10-27 20:06:33 +03:00
Antares
e5f2007a8e Fix fields in Finance methods (#45)
Fixed operation type field in getting transaction list
Fixed fields in params for getting finance realization report
2023-10-26 14:48:31 +03:00
Kirill
40d9fc32cb Update October 19, 2023 (#44) 2023-10-20 00:58:22 +03:00
Kirill
b07968d280 update/6-october-2023 - New Categories' methods version (#43) 2023-10-08 19:02:14 +03:00
Kirill
699d210296 update/4-october-2023 - Barcodes (#42) 2023-10-08 18:27:39 +03:00
Kirill
07d38a8456 remove deprecated method Delete Polygon (#41) 2023-09-05 23:11:43 +03:00
Kirill
0f1d0410bc update some methods description (#40) 2023-09-05 23:06:04 +03:00
Kirill
6d4d97e3c8 added comments on restrictions for seller without Premium subscription (#39) 2023-08-25 16:38:38 +03:00
Kirill
85543f45b0 update comments on price in Update Price params (#38) 2023-08-25 16:36:25 +03:00
15 changed files with 675 additions and 277 deletions

View File

@@ -20,6 +20,21 @@ type GetAnalyticsDataParams struct {
DateTo time.Time `json:"date_to"` DateTo time.Time `json:"date_to"`
// Items Enum: "unknownDimension" "sku" "spu" "day" "week" "month" "year" "category1" "category2" "category3" "category4" "brand" "modelID" // Items Enum: "unknownDimension" "sku" "spu" "day" "week" "month" "year" "category1" "category2" "category3" "category4" "brand" "modelID"
// Data grouping available to all sellers:
// - unknownDimension—unknown,
// - sku—product identifier,
// - spu—product identifier,
// - day—day,
// - week—week,
// - month—month.
// Data grouping available to sellers with Premium subscription:
// - year—year,
// - category1—first level category,
// - category2—second level category,
// - category3—third level category,
// - category4—fourth level category,
// - brand—brand,
// - modelID—model.
Dimension []GetAnalyticsDataDimension `json:"dimension"` Dimension []GetAnalyticsDataDimension `json:"dimension"`
// Filters // Filters
@@ -31,6 +46,30 @@ type GetAnalyticsDataParams struct {
Limit int64 `json:"limit"` Limit int64 `json:"limit"`
// Specify up to 14 metrics. If there are more, you will get an error with the InvalidArgument code // Specify up to 14 metrics. If there are more, you will get an error with the InvalidArgument code
// The list of metrics for which the report will be generated.
//
// Metrics available to all sellers:
//
// - revenue—ordered amount,
// - ordered_units—ordered products.
// Metrics available to sellers with Premium subscription:
// - unknown_metric—unknown metric,
// - hits_view_search—impressions in search and category,
// - hits_view_pdp—impressions on the product description page,
// - hits_view—total impressions,
// - hits_tocart_search—added to cart from search or category,
// - hits_tocart_pdp—added to cart from the product description page,
// - hits_tocart—added to cart total,
// - session_view_search—sessions with impressions in search or category,
// - session_view_pdp—sessions with impressions on the product description page,
// - session_view—sessions total,
// - conv_tocart_search—conversion to cart from search or category,
// - conv_tocart_pdp—conversion to cart from a product description page,
// - conv_tocart—total conversion to cart,
// - returns—returned products,
// - cancellations—canceled products,
// - delivered_units—delivered products,
// - position_category—position in search and category.
Metrics []GetAnalyticsDataFilterMetric `json:"metrics"` 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 // Number of elements that will be skipped in the response. For example, if `offset=10`, the response will start with the 11th element found
@@ -95,6 +134,13 @@ type GetAnalyticsDataResultDimension struct {
} }
// Specify the period and metrics that are required. The response will contain analytical data grouped by the `dimensions` parameter. // Specify the period and metrics that are required. The response will contain analytical data grouped by the `dimensions` parameter.
//
// There are restrictions for sellers without Premium subscription:
//
// - data is available for the last 3 months,
// - some of the data grouping methods and metrics aren't available.
//
// There are no restrictions for sellers with Premium subscription
func (c Analytics) GetAnalyticsData(ctx context.Context, params *GetAnalyticsDataParams) (*GetAnalyticsDataResponse, error) { func (c Analytics) GetAnalyticsData(ctx context.Context, params *GetAnalyticsDataParams) (*GetAnalyticsDataResponse, error) {
url := "/v1/analytics/data" url := "/v1/analytics/data"

111
ozon/barcodes.go Normal file
View File

@@ -0,0 +1,111 @@
package ozon
import (
"context"
"net/http"
core "github.com/diphantxm/ozon-api-client"
)
type Barcodes struct {
client *core.Client
}
type GenerateBarcodesParams struct {
// List of products for which you want to generate barcodes
ProductIds []int64 `json:"product_ids"`
}
type GenerateBarcodesResponse struct {
core.CommonResponse
Errors []GenerateBarcodesError `json:"errors"`
}
type GenerateBarcodesError struct {
// Error code
Code string `json:"code"`
// Error details
Error string `json:"error"`
// Barcode that is failed to generate
Barcode string `json:"barcode"`
// Product identifier for which the barcode generation failed
ProductId int64 `json:"product_id"`
}
// If a product doesn't have a barcode, you can create it using this method. If a barcode already exists,
// but it isn't specified in your account, you can bind it using the `/v1/barcode/add` method.
//
// You can't generate barcodes for more than 100 products per request.
// You can use the method no more than 20 times per minute.
func (b *Barcodes) Generate(ctx context.Context, params *GenerateBarcodesParams) (*GenerateBarcodesResponse, error) {
url := "/v1/barcode/generate"
resp := &GenerateBarcodesResponse{}
response, err := b.client.Request(ctx, http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}
type BindBarcodesParams struct {
// List of barcodes and products
Barcodes []BindBarcode `json:"barcodes"`
}
type BindBarcode struct {
// Barcode. Maximum 100 characters
Barcode string `json:"barcode"`
// Product identifier in the Ozon system, SKU
SKU int64 `json:"sku"`
}
type BindBarcodesResponse struct {
core.CommonResponse
// Errors while binding barcodes
Errors []BindBarcodesError `json:"errors"`
}
type BindBarcodesError struct {
// Error code
Code string `json:"code"`
// Error details
Error string `json:"error"`
// Barcode that is failed to generate
Barcode string `json:"barcode"`
// SKU of the product for which the barcode binding failed
SKU int64 `json:"sku"`
}
// If a product has a barcode that isn't specified in your account,
// bind it using this method. If a product doesn't have a barcode,
// you can create it using the `/v1/barcode/generate` method.
//
// You can't bind barcodes to more than 100 products per request.
// Each product can have up to 100 barcodes.
// You can use the method no more than 20 times per minute.
func (b *Barcodes) Bind(ctx context.Context, params *BindBarcodesParams) (*BindBarcodesResponse, error) {
url := "/v1/barcode/add"
resp := &BindBarcodesResponse{}
response, err := b.client.Request(ctx, http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}

141
ozon/barcodes_test.go Normal file
View File

@@ -0,0 +1,141 @@
package ozon
import (
"context"
"net/http"
"testing"
core "github.com/diphantxm/ozon-api-client"
)
func TestGenerateBarcodes(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *GenerateBarcodesParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GenerateBarcodesParams{
ProductIds: []int64{123456789},
},
`{
"errors": [
{
"code": "code 200",
"error": "no error",
"barcode": "456",
"product_id": 123456789
}
]
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GenerateBarcodesParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
resp, err := c.Barcodes().Generate(ctx, test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
if resp.StatusCode == http.StatusOK {
if len(resp.Errors) != 0 {
if resp.Errors[0].ProductId != test.params.ProductIds[0] {
t.Errorf("Product ids are not equal")
}
}
}
}
}
func TestBindBarcodes(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *BindBarcodesParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&BindBarcodesParams{
Barcodes: []BindBarcode{
{
Barcode: "some barcode",
SKU: 123456789,
},
},
},
`{
"errors": [
{
"code": "code 200",
"error": "no error",
"barcode": "some barcode",
"sku": 123456789
}
]
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&BindBarcodesParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
resp, err := c.Barcodes().Bind(ctx, test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
if resp.StatusCode == http.StatusOK {
if len(resp.Errors) != 0 {
if resp.Errors[0].Barcode != test.params.Barcodes[0].Barcode {
t.Errorf("Barcodes are not equal")
}
if resp.Errors[0].SKU != test.params.Barcodes[0].SKU {
t.Errorf("Barcodes are not equal")
}
}
}
}
}

View File

@@ -12,17 +12,14 @@ type Categories struct {
} }
type GetProductTreeParams struct { type GetProductTreeParams struct {
// Category identifier
CategoryId int64 `json:"category_id"`
// Response language // Response language
Language Language `json:"language" default:"DEFAULT"` Language Language `json:"language"`
} }
type GetProductTreeResponse struct { type GetProductTreeResponse struct {
core.CommonResponse core.CommonResponse
// Category list // Categories list
Result []GetProductTreeResult `json:"result"` Result []GetProductTreeResult `json:"result"`
} }
@@ -30,19 +27,29 @@ type GetProductTreeResult struct {
// Category identifier // Category identifier
CategoryId int64 `json:"category_id"` CategoryId int64 `json:"category_id"`
// Subcategory tree
Children []GetProductTreeResponse `json:"children"`
// Category name // Category name
Title string `json:"title"` CategoryName string `json:"category_name"`
// `true`, if you can't create products in the category. `false`, if you can
Disabled bool `json:"disabled"`
// Product type identifier
TypeId int64 `json:"type_id"`
// Product type name
TypeName string `json:"type_name"`
// Subcategory tree
Children []GetProductTreeResult `json:"children"`
} }
// Returns product categories in the tree view. // Returns product categories in the tree view.
//
// New products can be created in the last level categories only. // New products can be created in the last level categories only.
// This means that you need to match these particular categories with the categories of your site. // This means that you need to match these particular categories with the categories of your site.
// It is not possible to create categories by user request // We don't create new categories by user request.
func (c Categories) Tree(ctx context.Context, params *GetProductTreeParams) (*GetProductTreeResponse, error) { func (c *Categories) Tree(ctx context.Context, params *GetProductTreeParams) (*GetProductTreeResponse, error) {
url := "/v2/category/tree" url := "/v1/description-category/tree"
resp := &GetProductTreeResponse{} resp := &GetProductTreeResponse{}
@@ -56,14 +63,14 @@ func (c Categories) Tree(ctx context.Context, params *GetProductTreeParams) (*Ge
} }
type GetCategoryAttributesParams struct { type GetCategoryAttributesParams struct {
// Filter by characteristics
AttributeType AttributeType `json:"attribute_type" default:"ALL"`
// Category identifier // Category identifier
CategoryId []int64 `json:"category_id"` CategoryId int64 `json:"category_id"`
// Response language // Response language
Language Language `json:"language" default:"DEFAULT"` Language Language `json:"language"`
// Product type identifier
TypeId int64 `json:"type_id"`
} }
type GetCategoryAttributesResponse struct { type GetCategoryAttributesResponse struct {
@@ -74,19 +81,6 @@ type GetCategoryAttributesResponse struct {
} }
type GetCategoryAttributesResult struct { type GetCategoryAttributesResult struct {
// Array of product characteristics
Attributes []GetCategoryAttributesResultAttribute `json:"attributes"`
// Category identifier
CategoryId int64 `json:"category_id"`
}
type GetCategoryAttributesResultAttribute struct {
// Indication that the dictionary attribute values depend on the category:
// - true — the attribute has its own set of values for each category.
// - false — the attribute has the same set of values for all categories
CategoryDependent bool `json:"category_dependent"`
// Characteristic description // Characteristic description
Description string `json:"description"` Description string `json:"description"`
@@ -99,26 +93,29 @@ type GetCategoryAttributesResultAttribute struct {
// Characteristics group name // Characteristics group name
GroupName string `json:"group_name"` GroupName string `json:"group_name"`
// Document generation task number // Number of document generation task
Id int64 `json:"id"` Id int64 `json:"id"`
// Indicates that the attribute is aspect. An aspect attribute is a characteristic that distinguishes products of the same model. // Indicates that the attribute is aspect. An aspect attribute is a characteristic that distinguishes products of the same model.
// //
// For example, clothes and shoes of the same model may have different colors and sizes. That is, color and size are aspect attributes. // For example, clothes or shoes of the same model may have different colors and sizes. That is, color and size are aspect attributes.
// //
// Values description: // Values description:
// - true — the attribute is aspect and cannot be changed after the products are delivered to the warehouse or sold from the seller's warehouse. //
// - false — the attribute is not aspect and can be changed at any time // - `true`—the attribute is aspect and can't be changed after the products are delivered to the warehouse or sold from the seller's warehouse.
// - `false`—the attribute is not aspect and can be changed at any time
IsAspect bool `json:"is_aspect"` IsAspect bool `json:"is_aspect"`
// Indicates that the characteristic is a set of values: // Indicates that the characteristic is a set of values:
// - true — the characteristic is a set of values, //
// - false — the characteristic consists of a single value // - `true`—the characteristic is a set of values,
// - `false`—the characteristic consists of a single value
IsCollection bool `json:"is_collection"` IsCollection bool `json:"is_collection"`
// Indicates that the characteristic is mandatory: // Indicates that the characteristic is mandatory:
// - true — a mandatory characteristic, //
// - false — you can leave the characteristic out // - `true`—a mandatory characteristic,
// - `false`—an optional characteristic
IsRequired bool `json:"is_required"` IsRequired bool `json:"is_required"`
// Name // Name
@@ -128,15 +125,13 @@ type GetCategoryAttributesResultAttribute struct {
Type string `json:"type"` Type string `json:"type"`
} }
// Getting characteristics for specified product category. // Getting characteristics for specified product category and type.
// //
// Pass up to 20 category identifiers in the `category_id` list. // If the dictionary_id value is 0, there is no directory.
// // If the value is different, there are directories.
// You can check whether the attribute has a nested directory by the `dictionary_id` parameter. // Get them using the `/v1/description-category/attribute/values` method.
// The 0 value means there is no directory. If the value is different, then there are directories. func (c *Categories) Attributes(ctx context.Context, params *GetCategoryAttributesParams) (*GetCategoryAttributesResponse, error) {
// You can get them using the `/v2/category/attribute/values` method url := "/v1/description-category/attribute"
func (c Categories) Attributes(ctx context.Context, params *GetCategoryAttributesParams) (*GetCategoryAttributesResponse, error) {
url := "/v3/category/attribute"
resp := &GetCategoryAttributesResponse{} resp := &GetCategoryAttributesResponse{}
@@ -157,39 +152,55 @@ type GetAttributeDictionaryParams struct {
CategoryId int64 `json:"category_id"` CategoryId int64 `json:"category_id"`
// Response language // Response language
// The default language is Russian Language Language `json:"language"`
Language Language `json:"language" default:"DEFAULT"`
// Identifier of the directory to start the response with.
// If `last_value_id` is 10, the response will contain directories starting from the 11th
LastValueId int64 `json:"last_value_id"` LastValueId int64 `json:"last_value_id"`
// Number of values in the response: // Number of values in the response:
// - maximum — 5000 //
// - minimum — 1 // - maximum—5000,
// - minimum—1.
Limit int64 `json:"limit"` Limit int64 `json:"limit"`
// Product type identifier
TypeId int64 `json:"type_id"`
} }
type GetAttributeDictionaryResponse struct { type GetAttributeDictionaryResponse struct {
core.CommonResponse core.CommonResponse
// Indication that only part of characteristic values was returned in the response:
//
// - true—make a request with a new last_value_id parameter value for getting the rest of characteristic values;
// - false—all characteristic values were returned
HasNext bool `json:"has_next"` HasNext bool `json:"has_next"`
// Method result // Characteristic values
Result []GetAttributeDictionaryResult `json:"result"` Result []GetAttributeDictionaryResult `json:"result"`
} }
type GetAttributeDictionaryResult struct { type GetAttributeDictionaryResult struct {
// Characteristic value identifier
Id int64 `json:"id"` Id int64 `json:"id"`
// Additional description
Info string `json:"info"` Info string `json:"info"`
// Image link
Picture string `json:"picture"` Picture string `json:"picture"`
// Product characteristic value // Product characteristic value
Value string `json:"value"` Value string `json:"value"`
} }
// You can use the `/v3/category/attribute` method to check if an attribute has a nested directory. // Returns characteristics value directory.
// If there are directories, get them using this method //
func (c Categories) AttributesDictionary(ctx context.Context, params *GetAttributeDictionaryParams) (*GetAttributeDictionaryResponse, error) { // To check if an attribute has a nested directory,
url := "/v2/category/attribute/values" // use the `/v1/description-category/attribute` method.
func (c *Categories) AttributesDictionary(ctx context.Context, params *GetAttributeDictionaryParams) (*GetAttributeDictionaryResponse, error) {
url := "/v1/description-category/attribute"
resp := &GetAttributeDictionaryResponse{} resp := &GetAttributeDictionaryResponse{}

View File

@@ -22,14 +22,17 @@ func TestGetProductTree(t *testing.T) {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetProductTreeParams{ &GetProductTreeParams{
CategoryId: 17034410, Language: English,
}, },
`{ `{
"result": [ "result": [
{ {
"category_id": 17034410, "category_id": 0,
"title": "Развивающие игрушки", "category_name": "string",
"children": [] "children": [],
"disabled": true,
"type_id": 0,
"type_name": "string"
} }
] ]
}`, }`,
@@ -58,14 +61,6 @@ func TestGetProductTree(t *testing.T) {
if resp.StatusCode != test.statusCode { if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode) t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
} }
if resp.StatusCode == http.StatusOK {
if len(resp.Result) > 0 {
if resp.Result[0].CategoryId != test.params.CategoryId {
t.Errorf("First category ids in request and response are not equal")
}
}
}
} }
} }
@@ -83,25 +78,23 @@ func TestGetCategoryAttributes(t *testing.T) {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetCategoryAttributesParams{ &GetCategoryAttributesParams{
CategoryId: []int64{17034410}, CategoryId: 12345,
Language: English,
TypeId: 2,
}, },
`{ `{
"result": [ "result": [
{ {
"category_id": 17034410, "description": "string",
"attributes": [ "dictionary_id": 0,
{
"id": 85,
"name": "Бренд",
"description": "Укажите наименование бренда, под которым произведен товар. Если товар не имеет бренда, используйте значение \"Нет бренда\"",
"type": "String",
"is_collection": false,
"is_required": true,
"group_id": 0, "group_id": 0,
"group_name": "", "group_name": "string",
"dictionary_id": 28732849 "id": 0,
} "is_aspect": true,
] "is_collection": true,
"is_required": true,
"name": "string",
"type": "string"
} }
] ]
}`, }`,
@@ -130,17 +123,6 @@ func TestGetCategoryAttributes(t *testing.T) {
if resp.StatusCode != test.statusCode { if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode) t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
} }
if resp.StatusCode == http.StatusOK {
if len(resp.Result) != len(test.params.CategoryId) {
t.Errorf("Length of categories in request and response are not equal")
}
if len(resp.Result) > 0 {
if resp.Result[0].CategoryId != test.params.CategoryId[0] {
t.Errorf("Category ids in request and response are not equal")
}
}
}
} }
} }
@@ -158,33 +140,23 @@ func TestGetAttributeDictionary(t *testing.T) {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetAttributeDictionaryParams{ &GetAttributeDictionaryParams{
AttributeId: 10096, AttributeId: 123456,
CategoryId: 17028968, CategoryId: 12,
LastValueId: 0, Language: English,
Limit: 3, LastValueId: 1,
Limit: 5,
TypeId: 6,
}, },
`{ `{
"has_next": true,
"result": [ "result": [
{ {
"id": 61571, "id": 0,
"value": "белый", "info": "string",
"info": "", "picture": "string",
"picture": "" "value": "string"
},
{
"id": 61572,
"value": "прозрачный",
"info": "",
"picture": ""
},
{
"id": 61573,
"value": "бежевый",
"info": "",
"picture": ""
} }
], ]
"has_next": true
}`, }`,
}, },
// Test No Client-Id or Api-Key // Test No Client-Id or Api-Key

View File

@@ -540,3 +540,50 @@ const (
// pound sterling // pound sterling
InvoiceCurrencyGBP InvoiceCurrency = "GBP" InvoiceCurrencyGBP InvoiceCurrency = "GBP"
) )
type ReportType string
const (
// products report
ReportTypeSellerProducts ReportType = "SELLER_PRODUCTS"
// transactions report
ReportTypeSellerTransactions ReportType = "SELLER_TRANSACTIONS"
// product prices report
ReportTypeSellerProductPrices ReportType = "SELLER_PRODUCT_PRICES"
// stocks report
ReportTypeSellerStock ReportType = "SELLER_STOCK"
// products movement report
ReportTypeSellerProductMovement ReportType = "SELLER_PRODUCT_MOVEMENT"
// returns report
ReportTypeSellerReturns ReportType = "SELLER_RETURNS"
// shipments report
ReportTypeSellerPostings ReportType = "SELLER_POSTINGS"
// financial report
ReportTypeSellerFinance ReportType = "SELLER_FINANCE"
)
type ReportInfoStatus string
const (
ReportInfoWaiting ReportInfoStatus = "waiting"
ReportInfoProcessing ReportInfoStatus = "processing"
ReportInfoSuccess ReportInfoStatus = "success"
ReportInfoFailed ReportInfoStatus = "failed"
)
type SKUAvailability string
const (
SKUAvailabilityHidden = "HIDDEN"
SKUAvailabilityAvailable = "AVAILABLE"
// SKU is deleted
SKUAvailabilityUnavailable = "UNAVAILABLE"
)

View File

@@ -306,7 +306,7 @@ type FBSRequirements struct {
// //
// To pack the shipment, pass the CCD number for all listed SKUs. // To pack the shipment, pass the CCD number for all listed SKUs.
// If you do not have a CCD number, pass the value `is_gtd_absent` = true // If you do not have a CCD number, pass the value `is_gtd_absent` = true
// via the `/v3/posting/fbs/ship/package` or `/v3/posting/fbs/ship` method // via the `/v3/posting/fbs/ship/package`
ProductsRequiringGTD []string `json:"products_requiring_gtd"` ProductsRequiringGTD []string `json:"products_requiring_gtd"`
// Array of Ozon Product IDs (SKU) for which // Array of Ozon Product IDs (SKU) for which

View File

@@ -21,12 +21,12 @@ type ReportOnSoldProductsResponse struct {
core.CommonResponse core.CommonResponse
// Query result // Query result
Result []ReportonSoldProductsResult `json:"result"` Result ReportonSoldProductsResult `json:"result"`
} }
type ReportonSoldProductsResult struct { type ReportonSoldProductsResult struct {
// Report title page // Report title page
Header []ReportOnSoldProductsResultHeader `json:"header"` Header ReportOnSoldProductsResultHeader `json:"header"`
// Report table // Report table
Rows []ReportOnSoldProductsResultRow `json:"rows"` Rows []ReportOnSoldProductsResultRow `json:"rows"`
@@ -272,7 +272,7 @@ type ListTransactionsFilter struct {
Date ListTransactionsFilterDate `json:"date"` Date ListTransactionsFilterDate `json:"date"`
// Operation type // Operation type
OperationType string `json:"operation_type"` OperationType []string `json:"operation_type"`
// Shipment number // Shipment number
PostingNumber string `json:"posting_number"` PostingNumber string `json:"posting_number"`

View File

@@ -26,10 +26,8 @@ func TestReportOnSoldProducts(t *testing.T) {
Date: "2022-09", Date: "2022-09",
}, },
`{ `{
"result": [ "result": {
{ "header": {
"header": [
{
"doc_date": "2022-09-22", "doc_date": "2022-09-22",
"num": "string", "num": "string",
"start_date": "2022-09-02", "start_date": "2022-09-02",
@@ -45,8 +43,7 @@ func TestReportOnSoldProducts(t *testing.T) {
"doc_amount": 1, "doc_amount": 1,
"vat_amount": 1, "vat_amount": 1,
"currency_code": "string" "currency_code": "string"
} },
],
"rows": [ "rows": [
{ {
"row_number": 0, "row_number": 0,
@@ -71,7 +68,6 @@ func TestReportOnSoldProducts(t *testing.T) {
} }
] ]
} }
]
}`, }`,
"", "",
}, },

View File

@@ -31,6 +31,7 @@ type Client struct {
chats *Chats chats *Chats
certificates *Certificates certificates *Certificates
strategies *Strategies strategies *Strategies
barcodes *Barcodes
} }
func (c Client) Analytics() *Analytics { func (c Client) Analytics() *Analytics {
@@ -105,6 +106,10 @@ func (c Client) Strategies() *Strategies {
return c.strategies return c.strategies
} }
func (c Client) Barcodes() *Barcodes {
return c.barcodes
}
func NewClient(httpClient core.HttpClient, clientId, apiKey string) *Client { func NewClient(httpClient core.HttpClient, clientId, apiKey string) *Client {
coreClient := core.NewClient(httpClient, DefaultAPIBaseUrl, map[string]string{ coreClient := core.NewClient(httpClient, DefaultAPIBaseUrl, map[string]string{
"Client-Id": clientId, "Client-Id": clientId,
@@ -131,6 +136,7 @@ func NewClient(httpClient core.HttpClient, clientId, apiKey string) *Client {
chats: &Chats{client: coreClient}, chats: &Chats{client: coreClient},
certificates: &Certificates{client: coreClient}, certificates: &Certificates{client: coreClient},
strategies: &Strategies{client: coreClient}, strategies: &Strategies{client: coreClient},
barcodes: &Barcodes{client: coreClient},
} }
} }
@@ -157,5 +163,6 @@ func NewMockClient(handler http.HandlerFunc) *Client {
chats: &Chats{client: coreClient}, chats: &Chats{client: coreClient},
certificates: &Certificates{client: coreClient}, certificates: &Certificates{client: coreClient},
strategies: &Strategies{client: coreClient}, strategies: &Strategies{client: coreClient},
barcodes: &Barcodes{client: coreClient},
} }
} }

View File

@@ -85,27 +85,3 @@ func (c Polygons) Link(ctx context.Context, params *LinkDeliveryMethodToPolygonP
return resp, nil return resp, nil
} }
type DeletePolygonParams struct {
// Polygons identifiers list
PolygonIds []int64 `json:"polygon_ids"`
}
type DeletePolygonResponse struct {
core.CommonResponse
}
// Delete polygon
func (c Polygons) Delete(ctx context.Context, params *DeletePolygonParams) (*DeletePolygonResponse, error) {
url := "/v1/polygon/delete"
resp := &DeletePolygonResponse{}
response, err := c.client.Request(ctx, http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}

View File

@@ -109,48 +109,3 @@ func TestLinkDeliveryMethodToPolygon(t *testing.T) {
} }
} }
} }
func TestDeletePolygon(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *DeletePolygonParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&DeletePolygonParams{
PolygonIds: []int64{1323},
},
`{}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&DeletePolygonParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
resp, err := c.Polygons().Delete(ctx, test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}

View File

@@ -128,7 +128,7 @@ type ProductDetails struct {
BuyboxPrice string `json:"buybox_price"` BuyboxPrice string `json:"buybox_price"`
// Category identifier // Category identifier
CategoryId int64 `json:"category_id"` DescriptionCategoryId int64 `json:"description_category_id"`
// Marketing color // Marketing color
ColorImage string `json:"color_image"` ColorImage string `json:"color_image"`
@@ -420,6 +420,9 @@ type GetProductDetailsResponseItemError struct {
} }
// Get product details // Get product details
//
// Check a minimum product price with all promotions applied in your personal account.
// The min_price parameter from the method response is in development and returns 0
func (c Products) GetProductDetails(ctx context.Context, params *GetProductDetailsParams) (*GetProductDetailsResponse, error) { func (c Products) GetProductDetails(ctx context.Context, params *GetProductDetailsParams) (*GetProductDetailsResponse, error) {
url := "/v2/product/info" url := "/v2/product/info"
@@ -641,12 +644,24 @@ type UpdatePricesPrice struct {
OfferId string `json:"offer_id"` OfferId string `json:"offer_id"`
// Price before discounts. Displayed strikethrough on the product description page. // Price before discounts. Displayed strikethrough on the product description page.
// Specified in rubles. The fractional part is separated by decimal point, up to two digits after the decimal point. // Specified in rubles.
// The fractional part is separated by decimal point,
// up to two digits after the decimal point.
//
// If there are no discounts on the product, pass 0 to this field and specify the correct price in the price field
OldPrice string `json:"old_price"` OldPrice string `json:"old_price"`
// Product price including discounts. This value is displayed on the product description page. // Product price including discounts. This value is displayed on the product description page.
// //
// If the current price of the product is from 400 to 10 000 rubles inclusive, the difference between the values of price and old_price fields should be more than 5%, but not less than 20 rubles. // If the old_price parameter value is greater than 0,
// there should be a certain difference between price and old_price.
// It depends on the price value
//
// < 400 - min diff. 20 rubles
//
// 400-10,000 - min diff. 5%
//
// > 10,000 - min diff. 500 rubles
Price string `json:"price"` Price string `json:"price"`
// Attribute for enabling and disabling pricing strategies auto-application // Attribute for enabling and disabling pricing strategies auto-application
@@ -721,7 +736,7 @@ type CreateOrUpdateProductItem struct {
Barcode string `json:"barcode"` Barcode string `json:"barcode"`
// Category identifier // Category identifier
CategoryId int64 `json:"category_id"` DescriptionCategoryId int64 `json:"description_category_id"`
// Marketing color. // Marketing color.
// //
@@ -1363,7 +1378,7 @@ type GetDescriptionOfProductResult struct {
Barcode string `json:"barcode"` Barcode string `json:"barcode"`
// Category identifier // Category identifier
CategoryId int64 `json:"category_id"` DescriptionCategoryId int64 `json:"description_category_id"`
// Marketing color // Marketing color
ColorImage string `json:"color_image"` ColorImage string `json:"color_image"`
@@ -2106,6 +2121,10 @@ type GetProductPriceInfoResultItemPriceIndexesSelfMarketplace struct {
} }
// You can specify up to 1000 products in the request // You can specify up to 1000 products in the request
//
// Check minimum and maximum commissions for FBO pipeline in your personal account.
// The `fbo_direct_flow_trans_max_amount` and `fbo_direct_flow_trans_min_amount` parameters
// from the method response are in development and return 0
func (c Products) GetProductPriceInfo(ctx context.Context, params *GetProductPriceInfoParams) (*GetProductPriceInfoResponse, error) { func (c Products) GetProductPriceInfo(ctx context.Context, params *GetProductPriceInfoParams) (*GetProductPriceInfoResponse, error) {
url := "/v4/product/info/prices" url := "/v4/product/info/prices"
@@ -2316,3 +2335,64 @@ func (c Products) UpdateCharacteristics(ctx context.Context, params *UpdateChara
return resp, nil return resp, nil
} }
type GetRelatedSKUsParams struct {
// List of SKUs
SKUs []string `json:"sku"`
}
type GetRelatedSKUsResponse struct {
core.CommonResponse
// Related SKUs information
Items []GetRelatedSKUsItem `json:"items"`
// Errors
Errors []GetRelatedSKUsError `json:"errors"`
}
type GetRelatedSKUsItem struct {
// Product availability attribute by SKU
Availability SKUAvailability `json:"availability"`
// Date and time of deletion
DeletedAt time.Time `json:"deleted_at"`
// Delivery scheme
DeliverySchema string `json:"delivery_schema"`
// Product identifier
ProductId int64 `json:"product_id"`
// Product identifier in the Ozon system, SKU
SKU int64 `json:"sku"`
}
type GetRelatedSKUsError struct {
// Error code
Code string `json:"code"`
// SKU, in which the error occurred
SKU int `json:"sku"`
// Error text
Message string `json:"message"`
}
// You can pass any SKU in the request, even a deleted one.
// The response will contain all SKUs related to the passed ones.
//
// In one request, you can pass up to 200 SKUs.
func (c Products) GetRelatedSKUs(ctx context.Context, params *GetRelatedSKUsParams) (*GetRelatedSKUsResponse, error) {
url := "/v1/product/related-sku/get"
resp := &GetRelatedSKUsResponse{}
response, err := c.client.Request(ctx, http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}

View File

@@ -124,7 +124,7 @@ func TestGetProductDetails(t *testing.T) {
"7533900005" "7533900005"
], ],
"buybox_price": "", "buybox_price": "",
"category_id": 17038062, "description_category_id": 17038062,
"created_at": "2021-10-21T15:48:03.529178Z", "created_at": "2021-10-21T15:48:03.529178Z",
"images": [ "images": [
"https://cdn1.ozone.ru/s3/multimedia-5/6088931525.jpg", "https://cdn1.ozone.ru/s3/multimedia-5/6088931525.jpg",
@@ -286,7 +286,7 @@ func TestGetProductDetails(t *testing.T) {
if resp.Result.OfferId == "" { if resp.Result.OfferId == "" {
t.Errorf("Offer id cannot be empty") t.Errorf("Offer id cannot be empty")
} }
if resp.Result.CategoryId == 0 { if resp.Result.DescriptionCategoryId == 0 {
t.Errorf("Category id cannot be 0") t.Errorf("Category id cannot be 0")
} }
if resp.Result.CurrencyCode == "" { if resp.Result.CurrencyCode == "" {
@@ -659,7 +659,7 @@ func TestCreateOrUpdateProduct(t *testing.T) {
}, },
}, },
Barcode: "112772873170", Barcode: "112772873170",
CategoryId: 17033876, DescriptionCategoryId: 17033876,
CurrencyCode: "RUB", CurrencyCode: "RUB",
Depth: 10, Depth: 10,
DimensionUnit: "mm", DimensionUnit: "mm",
@@ -1339,7 +1339,7 @@ func TestListProductsByIDs(t *testing.T) {
"7533900005" "7533900005"
], ],
"buybox_price": "", "buybox_price": "",
"category_id": 93726157, "description_category_id": 93726157,
"created_at": "2021-06-03T03:40:05.871465Z", "created_at": "2021-06-03T03:40:05.871465Z",
"images": [], "images": [],
"has_discounted_item": true, "has_discounted_item": true,
@@ -1536,7 +1536,7 @@ func TestGetDescriptionOfProduct(t *testing.T) {
{ {
"id": 213761435, "id": 213761435,
"barcode": "", "barcode": "",
"category_id": 17038062, "description_category_id": 17038062,
"name": "Пленка защитная для Xiaomi Redmi Note 10 Pro 5G", "name": "Пленка защитная для Xiaomi Redmi Note 10 Pro 5G",
"offer_id": "21470", "offer_id": "21470",
"height": 10, "height": 10,
@@ -2600,3 +2600,69 @@ func TestUpdateCharacteristics(t *testing.T) {
} }
} }
} }
func TestGetRelatedSKUs(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *GetRelatedSKUsParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetRelatedSKUsParams{
SKUs: []string{"321", "322"},
},
`{
"items": [
{
"availability": "HIDDEN",
"deleted_at": "2019-08-24T14:15:22Z",
"delivery_schema": "fbs",
"product_id": 123,
"sku": 321
}
],
"errors": [
{
"code": "test_code",
"sku": 322,
"message": "test_message"
}
]
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GetRelatedSKUsParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
resp, err := c.Products().GetRelatedSKUs(ctx, test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
if len(resp.Errors)+len(resp.Items) != len(test.params.SKUs) {
t.Errorf("expected equal length of skus in request and response")
}
}
}

View File

@@ -126,21 +126,11 @@ type GetReportDetailResult struct {
// Array with the filters specified when the seller created the report // Array with the filters specified when the seller created the report
Params map[string]string `json:"params"` Params map[string]string `json:"params"`
// Report type: // Report type
// - SELLER_PRODUCTS — products report, ReportType ReportType `json:"report_type"`
// - SELLER_TRANSACTIONS — transactions report,
// - SELLER_PRODUCT_PRICES — product prices report,
// - SELLER_STOCK — stocks report,
// - SELLER_PRODUCT_MOVEMENT — products movement report,
// - SELLER_RETURNS — returns report,
// - SELLER_POSTINGS — shipments report,
// - SELLER_FINANCE — financial report
ReportType string `json:"report_type"`
// Report generation status: // Report generation status
// - success Status ReportInfoStatus `json:"status"`
// - failed
Status string `json:"status"`
} }
// Returns information about a created report by its identifier // Returns information about a created report by its identifier