Jump to content


Photo
- - - - -

Items JSON validator improvements


Best Answer nasatome , 25 January 2017 - 12:42 AM

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.mlst..._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

Go to the full post


  • Please log in to reply
8 replies to this topic

#1 fsolari

fsolari

    Jedi Knight

  • Administrators
  • 147 posts

Posted 24 June 2014 - 08:09 PM

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

#2 JonathanPHP

JonathanPHP

    Padawan

  • Members
  • PipPip
  • 13 posts

Posted 20 January 2017 - 10:37 PM

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!



#3 rodrigojob

rodrigojob

    Yoda

  • Members
  • PipPipPipPipPip
  • 715 posts

Posted 22 January 2017 - 11:15 PM

retire o 'video_id'=> 'YOUTUBE_ID_HERE',
e quando postar algo que tem dúvida também coloque a mensagem de erro


Até mais,

Rodrigo

 

SDK-PHP - Aptana Studio 3 - Linux

Não me peça código.

Evite fazer perguntas simples, leia a documentação: http://developers.mercadolibre.com


#4 JonathanPHP

JonathanPHP

    Padawan

  • Members
  • PipPip
  • 13 posts

Posted 24 January 2017 - 07:38 PM

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.mlst..._072016-O.jpg]]

 

perdon que no coloque el error antes!



#5 rodrigojob

rodrigojob

    Yoda

  • Members
  • PipPipPipPipPip
  • 715 posts

Posted 24 January 2017 - 11:41 PM

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.me...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(
         "source"=> "http://mla-s2-p.mlst...072016-O.jpg"),
      ),
 
      array(
         "source"=> "http://mla-s2-p.mlst..._00000-O.jpg"),
      )

)

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.


Até mais,

Rodrigo

 

SDK-PHP - Aptana Studio 3 - Linux

Não me peça código.

Evite fazer perguntas simples, leia a documentação: http://developers.mercadolibre.com


#6 nasatome

nasatome

    Padawan

  • Members
  • PipPip
  • 10 posts

Posted 25 January 2017 - 12:42 AM   Best Answer

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.mlst..._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, 25 January 2017 - 12:44 AM.


#7 JonathanPHP

JonathanPHP

    Padawan

  • Members
  • PipPip
  • 13 posts

Posted 25 January 2017 - 03:20 PM

efectivamente es eso! muchas gracias a ambos! ahora si funciono perfecto!


  • Leandro Bertalot likes this

#8 JonathanPHP

JonathanPHP

    Padawan

  • Members
  • PipPip
  • 13 posts

Posted 01 February 2017 - 05:08 PM

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!



#9 rodrigojob

rodrigojob

    Yoda

  • Members
  • PipPipPipPipPip
  • 715 posts

Posted 01 February 2017 - 09:35 PM

o que você já tentou?


Até mais,

Rodrigo

 

SDK-PHP - Aptana Studio 3 - Linux

Não me peça código.

Evite fazer perguntas simples, leia a documentação: http://developers.mercadolibre.com





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users