• 0
fsolari

Items JSON validator improvements

Question


We're adding a new JSON schema validation on the Items API. Some of the attributes you used to send 'null' will now be validated, so if you don't send some required Arrays and Objets you'll be getting a 400 error code with explicit detail of what's wrong. We're also replacing the old 500 error code outputs for these new 400 error code detailed outputs.

 

Some of the attributes we used to accept as null but we wont be accepting nulled anymore are:

"pictures", "shipping", "seller_address", "seller contact", "location", "attributes", "variations", etc.

 

Also, we'll start validating the data type of the values you send. So if we require a number and you send a String, you'll get an error.

 

For example, if you make a PUT to the Items API with a body like this:


 



{
"seller_id":,
"id",
"price":"p",
"seller_contact":null,
"pictures": [[1,2,3]] 
}


 

You'll get this output:

 



{
"message":"body.invalid_field_types",
"error":"[invalid property type: [price] expected Number but was String value: p,
invalid property type: [seller_contact] expected Map but was Null value: null,
invalid property type: [pictures[0]] expected Map but was JSONArray value: [1, 2, 3],
invalid property type: [seller_id] expected Number but was String value: id]",
   "status":400,
   "cause":[


   ]
}

nasatome likes this

Share this post


Link to post
Share on other sites

8 answers to this question

  • 0

muchas gracias por tu ayuda!

elimine YOUTUBE_ID_HERE y ahora me aparece el siguiente error:

[invalid property type: [pictures] expected List but was JSONObject value: [source:http://mla-s2-p.mlstatic.com/968521-MLA20805195516_072016-O.jpg]]

 

perdon que no coloque el error antes!

Probablemente tu problema sea que te hace falta meter el array de imágenes dentro de otro array ....

 

'pictures' => array(
        array(
          'source' => 'http://mla-s2-p.mlstatic.com/968521-MLA20805195516_072016-O.jpg'
        )
      )

______________

 

Edito: tal como comenta @rodrigojob

Edited by nasatome

Share this post


Link to post
Share on other sites
  • 0

Buenas! muchas gracias por su atención, mi nombre es Jonathan y vengo bastante bien con la api de mercadolibre, pero ahora quería publicar un item (logre hacerlo desde Advance REST client) desde mi aplicacion PHP. pero no tengo idea como pasar los parámetros que en Advance REST client paso escribiendo el json…

estoy escribiendo así pero no funciona:

$detallesART = array(
'title' => 'item numero 2', 
'category_id'=> 'MLA3530',
'price'=> 10,
'currency_id'=> 'ARS',
'available_quantity'=> 1,
'buying_mode'=> 'buy_it_now',
'listing_type_id'=> 'gold_special',
'condition'=> 'new',
'description'=>  'Item de test - No Ofertar',
'video_id'=> 'YOUTUBE_ID_HERE',
'warranty'=> '12 months',
'pictures' => array('source' => 'http://mla-s2-p.mlstatic.com/968521-MLA20805195516_072016-O.jpg')
);

$crear= $meli->postWithAccessToken('/items', $detallesART);

echo "<hr>".$crear['json']['permalink'];

Tambien intente poniendo el JSON como un string... llevo horas peleando con esto, agradeceria su ayuda!

Share this post


Link to post
Share on other sites
  • 0

perceba que no exemplo da publicação do item, para as imagens, há um array multidimensional, é muito ruim de ver no código, e é por isso que estou escrevendo o be-a-bá

'{
"title":"Item de test - No Ofertar",
"category_id":"MLA3530",
"price":10,
"currency_id":"ARS",
"available_quantity":1,
"buying_mode":"buy_it_now",
"listing_type_id":"gold_special",
"condition":"new",
"description": "Item de test - No Ofertar",
"video_id": "YOUTUBE_ID_HERE",
"warranty": "12 months",
"pictures":[
{"source":"http://mla-s2-p.mlstatic.com/968521-MLA20805195516_072016-O.jpg"}
 ]
}'

(  http://developers.mercadolibre.com/pt-br/publicacao-de-produtos/#Publicação-de-um-anúncio )

"pictures":[
    {"source":"http://mla-s2-p.mlstatic.com/968521-MLA20805195516_072016-O.jpg"}
 ]

são 2 arrays [ ... {  ...  }, ... ] 

"pictures" = array(
              array(
                  "source"=> "http://mla-s2-p.mlstatic.com/968521-MLA20805195516_072016-O.jpg"
               ),
            )
 
      array(
      ),
 
      array(
      )

)

O sistema deve ter sido desenvolvido para que se enviasse o nome da variável e o valor.
Se fosse só um array os campos deveriam ter nomes diferentes.

Share this post


Link to post
Share on other sites
  • 0

buenas, tengo un nuevo problema, si quiero poner varias imagenes en el item, como deberia armar el json? porque me toma solamente la ultima imagen.

 

saludos!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now