Prestashop Web service to return JSON

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Prestashop Web service to return JSON



After extensive search over internet i am sure that Prestashop does not return data in JSON format, it only returns in XML format (which leads to cross domain accessing issue unfortunately).



Now, I am trying to convert XML(returned by Prestashop) to JSON. I want to write php code which could take XML from web service and sent back JSON. For this purpose i tried many tutorial but in vain. The converted JSON does not have value in it, so is useless.
The methods i tried are listed below.



http://www.sitepoint.com/php-xml-to-json-proxy/
PHP convert XML to JSON



XML to convert:


<name>
<language id="1" xlink:href="http://localhost/prestashop/api/languages/1">
<![CDATA[ iPod Nano ]]>
</language>
</name>



Returned JSON:


"name":{"language":{"@attributes":{"id":"1"}}}



I hope for the help in this regard. Thank you.





I've never used the Prestashop webservice, but it may be easier to bypass the code where Prestashop creates the XML and replace it with a code where you create the json you need. This is just an idea though.
– romainberger
May 30 '13 at 12:01




3 Answers
3



I don't know about historical support for this, but...



In the latest version of Prestashop (currently v1.6.0.9), you can get a JSON response from any WebService API request by appending output_format=JSON to your request query string.


output_format=JSON



E.g.
http://example.prestashop.com/api/products?output_format=JSON


http://example.prestashop.com/api/products?output_format=JSON





Still works in 1.7.2, this answer should be accepted.
– mikiqex
Nov 1 '17 at 8:59





FYI, output_format value is case sensitive. So, if it doesn't work, make sure you use JSON instead of json.
– Kiddo
Jan 13 at 0:46





Using php pear "XML_Serializer":



{
"product": {
"id_category_default": "XXX",
"id_tax_rules_group": "1",
"type": "simple",
"id_shop_default": "1",
"reference": "XXXXXXXX",
"price": "XX.XXXXXX",
"active": "1",
"redirect_type": "404",
"id_product_redirected": "0",
"available_for_order": "1",
"condition": "new",
"show_price": "1",
"indexed": "0",
"visibility": "both",
"advanced_stock_management": "0",
"link_rewrite": {
"language": {
"_attributes": {
"id": "1"
},
"_content": "ipod-nano"
}
},
"name": {
"language": {
"_attributes": {
"id": "1"
},
"_content": "iPod Nano"
}
},
"associations": {
"categories": {
"category": {
"id": "XXX"
}
},
"stock_availables": {
"stock_available": {
"id": "XXXX",
"id_product_attribute": "X"
}
}
}
}
}



See this link: https://www.prestashop.com/forums/topic/602449-aporte-webservice-prestashop-16-json-request-post-y-put/#elComment_2930631



Greetings!!



Prestashop has die(Tools::jsonEncode([Associative Array])) for ajax return or just remove die for non ajax return.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived