allegro / allegro-api

Issue tracker and wiki for Allegro REST API
https://developer.allegro.pl/
213 stars 39 forks source link

JsonMappingException #9368

Open bartflow opened 3 months ago

bartflow commented 3 months ago

Hi,

I want to add an offer with a not existing product, and according to the docs it should be like this:

          'productSet' => [
                [
                    'product' => [
                        'name' => 'Produkt testowy',
                        'category' => [
                            'id' => '89060'
                        ],
                        'parameters' => [
                            [
                                'name' => 'EAN',
                                'values' => [
                                    '5435435454556'
                                ]
                            ],
                            [
                                'id' => '237218',
                                'values' => [
                                    'Testowy tytuł'
                                ]
                            ]
                        ],
                        'images' => [
                            'https://...adres-pierwszego-obrazka.jpeg'
                        ]
                    ]
                ]
            ],
            'sellingMode' => [
                'price' => [
                    'amount' => '220.85',
                    'currency' => 'PLN'
                ]
            ],
            'stock' => [
                'available' => 10
            ]
        ];

But if i send this to the api, i get an 'JsonMappingException', before sending i encode the above code to json.

Could you see what the issue is?

Lukasz-Zurek commented 3 months ago

@bartflow Please send me a trace-id of this request - I will check it out closely.

bartflow commented 3 months ago

b42727a3-2560-4c7d-975c-b0f8078f44a2

Lukasz-Zurek commented 3 months ago

@bartflow It is not a trace-id. You can find it in your response headers.

bartflow commented 3 months ago

Yeah you're right, here is the trace id from the request: 51b1bfe446056a6e

Lukasz-Zurek commented 3 months ago

@bartflow I see that you:

[ - you should remove it
   {
      "productSet":[
         {
            "product":{
               "name":"Produkt testowy",
               "category":{
                  "id":"89060"
               },
               "parameters":[
                  {
                     "name":"EAN",
                     "values":[
                        "5435435454556"
                     ]
                  },
                  {
                     "id":"237218",
                     "values":[
                        "Testowy tytu"
                     ]
                  }
               ],
               "images": **[**">>HIDDEN<<"**] - an array should be added
            }
         }
      ],
      "sellingMode":{
         "price":{
            "amount":"220.85",
            "currency":"PLN"
         }
      },
      "stock":{
         "available":10
      }
   }
] - you should remove it
bartflow commented 3 months ago

Okay so i removed the outside array from productset, but i think it's still going wrong in the images array, this is the trace-id: 46b4a3bf00827147.

But do we need an extra array? Because in my php code i have

              'productSet' => [
                    'product' => [
                        'name' => 'Produkt testowy',
                        'category' => [
                            'id' => '89060',
                        ],
                        'parameters' => [
                            [
                                'name' => 'EAN',
                                'values' => ['5435435454556'],
                            ],
                            [
                                'id' => '237218',
                                'values' => ['Testowy tytuł'],
                            ],
                        ],
                        'images' => [
                            'https://fastly.picsum.photos/id/237/200/300.jpg?hmac=TmmQSbShHz9CdQm0NkEjx1Dyh_Y984R9LpNrpvH2D_U',
                            // Add more image URLs as needed
                        ],
                    ],
                ],
Lukasz-Zurek commented 3 months ago

@bartflow Right now I see:

{
   "productSet":{
      "product":{
         "name":"Produkt testowy",
         "category":{
            "id":"89060"
         },
         "parameters":[
            {
               "name":"EAN",
               "values":[
                  "5435435454556"
               ]
            },
            {
               "id":"237218",
               "values":[
                  "Testowy tytuu0142"
               ]
            }
         ],
         "images":">>HIDDEN<<"
      } - it should be removed
   },
   "sellingMode":{
      "price":{
         "amount":"220.85",
         "currency":"PLN"
      }
   },
   "stock":{
      "available":10
   }
}

So the problem is still with "images" field.

bartflow commented 3 months ago

Okay so i think above is fixed, thanks for that, but now i get a ProductValidationException, but i filled in all the fields i think. This is the trace-id: 73d641fb67bcd0c5

Lukasz-Zurek commented 2 months ago

@bartflow You did not provide one required (for a product) parameter: 246845 (Medium).

This is why we have returned this error: Unable to create product without proper values in all required parameters: [Nośnik] in category: 89060

bartflow commented 2 months ago

Okay above is fixed i think, so now i get the following exception ConstraintViolationException.ValidCzechPrice

Trace-id: 4461079aa6455178

Lukasz-Zurek commented 2 months ago

@bartflow I see that your base marketplace is allegro-cz, so you should provide a price in CZK.

You can find more information about foreign Allegro marketplaces in our tutorial.

bartflow commented 2 months ago

Okay but i didn't put it on CZ? Could you change that for me or where do i change it?

Lukasz-Zurek commented 2 months ago

@bartflow You should change it here:

   "sellingMode":{
      "format":"BUY_NOW",
      "price":{
         "amount":"220.85", <- the amount should be without decimal
         "currency":"PLN" <- it should be CZK
      }
   },

The offer will be listed on allegro-cz as a base marketplace.

bartflow commented 2 months ago

Sorry that's not what i meant. I already changed that, but how can i change the base marketplace? Because i want the base marketplace at PL, because i registered on the sandbox PL.

Lukasz-Zurek commented 2 months ago

Ok, I understand now. But base marketplace for the account cannot be changed so you will have to register another account but directly on allegro-pl, so in this situation - on allegro sandbox environment: https://allegro.pl.allegrosandbox.pl

bartflow commented 2 months ago

I did it through that url, so that's the strange thing. I never used or visited the cz url.

Lukasz-Zurek commented 2 months ago

This account has been registered on July 2 and I see that registration marketplace is: allegro-cz, but I do not have any specific details. If you want to use an account on allegro.pl account, please register another one. Hopefully there will be no problem with that.

I am sorry for any inconvenience.

bartflow commented 2 months ago

Okay thanks i will look at that.

I have only 3 errors left for making a offer based on a product.

{ "errors": [ { "code": "ConstraintViolationException.ValidSelectedCategory", "message": "This category is not the lowest-level category.", "details": "ConstraintViolationException.ValidSelectedCategory", "path": "category", "userMessage": "Tato kategorie není kategorií nejnižší úrovně.", "metadata": {} }, { "code": "ConstraintViolationException.BaseProductizedMarketplaceWithProductOnly", "message": "Platforms other than allegro.pl only support offers with a product linked.", "details": "ConstraintViolationException.BaseProductizedMarketplaceWithProductOnly", "path": "null", "userMessage": "Platformy jiné než allegro.pl podporují pouze nabídky propojené s produktem.", "metadata": {} }, { "code": "ConstraintViolationException.ProductizationMinLimitReached", "message": "You cannot activate an offer without a product on platforms other than allegro.pl.", "details": "ConstraintViolationException.ProductizationMinLimitReached", "path": "null", "userMessage": "Nabídku bez produktu nemůžete aktivovat na jiných platformách než na allegro.pl.", "metadata": {} } ] }

The first error, i want to know if there's a list of all categories and subcategories, because i think i had the lowest category.

The other errors, i have no idea what to do, so i hope you could help.

This is the trace-id: 3fbacae098f08d49

Lukasz-Zurek commented 2 months ago
  1. "This category is not the lowest-level category." - you are providing an incorrect category id (which is not the lowest-level category): a408e75a-cede-4587-8526-54e9be600d9f.

In Allegro API you can retrieve categories using GET /sale/categories and drill down into lower-level categories using the parent.id parameter.

For example, you send a request: GET sale/categories?parent.id=a408e75a-cede-4587-8526-54e9be600d9f, select the subcategories for which you would like to get lower categories, e.g. 6 (GET sale/categories?parent.id=6). Therefore, this way you will be able to get all the information. You don't need the shortest child's ID. You only need parent.id, thanks to which you get all the lists of lower categories, in order, according to the above diagram.

  1. Please change the category in your request first, then I think you should not receive that kind of error.
  2. Same as above.
bartflow commented 2 months ago

Okay thanks! The next error is about the valuesIds within the parameter. But if i get the category parameters this should be the value according to wat i get back: 11323_1

{
    "errors": [
        {
            "code": "DictionaryParameterIdNotFound",
            "message": "Requested valueId not found in parameter 'Stav zboží' dictionary (id: 11323).",
            "details": null,
            "path": "parameters",
            "userMessage": "Invalid dictionary value identifier was specified for the `Stav zboží` parameter.",
            "metadata": {}
        }
    ]
}

Trace-id: 1489a470f74ff991

Lukasz-Zurek commented 2 months ago

You are right, but in your request I still see an incorrect category_id: a408e75a-cede-4587-8526-54e9be600d9f. Maybe it causes the problem here (as 11323_1 value is correct).

bartflow commented 2 months ago

Hm that's strange this is my request:

'productSet' => [
                    [
                        'product' => [
                            'name' => 'Produkt testowy',
                            'category' => [
                                'id' => '321817'
                            ],
                            'parameters' => [
                                [
                                    'id' => '225693',
                                    'values' => [
                                        '0799439112766'
                                    ],
                                ],
                                [
                                    'id' => '17448',
                                    'values' => [
                                        '98.0'
                                    ]
                                ],
                            ],
                            'images' => [
                                'https://fastly.picsum.photos/id/237/200/300.jpg?hmac=TmmQSbShHz9CdQm0NkEjx1Dyh_Y984R9LpNrpvH2D_U',
                            ],
                        ],
                    ],
                ],

This is wat the request looks like after the json encode:

 "body" => "{"productSet":[{"product":{"name":"Produkt testowy","category":{"id":"321817"},"parameters":[{"id":"225693","values":["0799439112766"]},{"id":"17448","values":["98.0"]}],"images":["https:\/\/fastly.picsum.photos\/id\/237\/200\/300.jpg?hmac=TmmQSbShHz9CdQm0NkEjx1Dyh_Y984R9LpNrpvH2D_U"]}}],"parameters":[{"id":"11323","valuesIds":["11323_1"]},{"id":"229205","valuesIds":["229205_340245"]}],"sellingMode":{"price":{"amount":"629","currency":"CZK"}},"delivery":{"shippingRates":{"id":"24a3f071-80ae-453b-89fb-b5f504cf3800"}},"stock":{"available":10}}"
]

My trace-id:

f60b247f8339e1a2

Lukasz-Zurek commented 2 months ago

Ok, now the category: 321817 is correct and you are choosing an incorrect value for it. Available values are:

            "dictionary": [
                {
                    "id": "11323_253798",
                    "value": "For restoration",
                    "dependsOnValueIds": []
                },
                {
                    "id": "11323_253802",
                    "value": "Refurbished",
                    "dependsOnValueIds": []
                },
                {
                    "id": "11323_253806",
                    "value": "Needs no refurbishment",
                    "dependsOnValueIds": []
                }
            ],

You can check it using GET /sale/categories/321817/parameters

I also recommend our tutorial.

bartflow commented 2 months ago

Thanks for the help. I've successfully added the products.

stale[bot] commented 2 months ago

W tym wątku nie pojawiła się żadna nowa odpowiedź w ciągu 7 dni, dlatego automatycznie oznaczamy go jako przeterminowany. Jeśli w ciągu kolejnych 7 dni nie pojawi się żadna odpowiedź, wątek zostanie zamknięty. Dziękujemy za zaangażowanie w dyskusję i zachęcamy Cię do wypełnienia ankiety dotyczącej naszego wsparcia na forum.


There was no new reply in this thread within 7 days, therefore, we automatically marked it as expired. If no response is received within the next 7 days, this thread will be closed. Thank you for engaging in the discussion. We encourage you to complete our forum support survey.