Can we use JSON body format when doing Opencart API - php

right now im learning about Opencart API. form opencart documentation Documentation every example write with json format.
however when i test it on postman. i test API for add product to cart. i can't put the json raw format body. i need to put the data on form-data.
this example result when i put raw json body format. and return empty array
and this result wheni put data on form-data
does opencart can't receive json format when do API call?

opencart documentation Documentation every example write with json format.
No, it doesn't.
The examples use a Python library and Python syntax.
The value of data looks superficially like JSON but is Python. The library takes that data and, according to the docs, converts it to form encoded data.
data – the body to attach to the request. If a dictionary or list of tuples [(key, value)] is provided, form-encoding will take place.
The API doesn't appear to support JSON.

Related

How to encode dates in a JSON response in PHP like '/Date(1365004652303-0500)/'?

I see that .NET can encode the dates like /Date(1365004652303-0500)/ when it generate the JSON response for a RestFull API response (for example read here).
My question is how can I generate the same output for my date properties inside an object when I use json_encode function to encode that object in the PHP.
I don't mean how to do it with an algorithm. I know how to write the algorithm! I would like to do it in a way that the front-end could understand this property is a date! I don't want to transfer it as a simple text!

Is it possible to update products with Prestashop web service in JSON format?

I am having difficulties updating categories associated to a product with their web service. I have read in this answer that is possible to get a JSON response.
I wonder if you can update the product using this format (it seems that nobody wonders it, because I cannot find how to).
Prestashop doc does not even talk about the JSON format...
So, does anybody knows how to do it, or should I start searching how to build my own prestashop component to sync data?
To retrieve data you can append ?output_format=JSON to your web service URL to let Prestashop return data in JSON instead of the default XML format.
http://www.myprestashop.com/api/products?output_format=JSON
To update data Prestashop Web service uses XML. If you want to use JSON, you need to modify Webservice and convert JSON to XML or directly JSON to data.

How to pass field values from database hosted on a server to android app using php?

I have a database hosted on server whose field values have to be passed to my app. I would like to do with PHP. But people suggest me to use JSON too. Is JSON required? Please guide me how to pass the field values to android app.
JSON means JavaScript Object Notation and it's just a way of formatting your output in a standard way.
So, if you'd like to pass data from a database to an application, you'd need to implement a small API. This can be done using PHP. At this point, you can access data from your database using a browser and parametrizing your queries using url parameters.
PHP can render the data in a simple HTML table for example, but this is just a way of presenting your data. You can also use JSON.
This means that if you need the badges a user has earned, you'll use something like this:
<link_to_your_api>/index.php?method=getBadges&user=<user>
This in turn, will make a request to the database
<?php
// 1. connect to database
// 2. query for the information
// 3. get the result as array
$result = $db->getData();
echo json_encode($result);
?>
This is just an example, hope it helps.
link to json documentation: http://www.json.org/
You pass the data to your app, when it makes a request to your PHP script. JSON is handy because you can package your data in a format, that is both well readable by humans and machines. You can use the gson library then, to process the JSON data in your app.
Create REST api using any server side script PHP,nodejs or any you like which returns JSON response
call the rest api using http request which returns JSOn text
decode the JSON string to JSON object and use with your android code

Class to integrate emberjs <-> PHP with JSON data

I am looking something like emberjs-data but for PHP?
Longest description:
I am looking class in PHP to generate JSON for emberjs in standard format and get this data in emberjs. And with other side, i want send data from emberjs to PHP using the same JSON standard.
In fact, you are looking for the PHP equivalent of ActiveModelSerializers.
Did you looked at http://www.phpactiverecord.org/docs/ActiveRecord/Serialization?

shall i retrieve database records with JSON ?

i'm a little bit confused here. i've PHP file that retrieve database records . i'll call it with an Ajax call from my frontend . do i need to convert the records to JSON ? if no when do i need to do that
You don't "need" to return the results as JSON. But I would recommend it. JSON is very portable, so it will be easier for other applications to interact with your application. It's also much easier to parse JSON than it is records separated by simple delimiters.
For example, you can use Crockford's JSON parser: http://www.json.org/js.html
As for JSON vs XML: Why need to use JSON in php and AJAX
You don't have to use JSON but you can encode any associative array using the function json_encode:
http://php.net/manual/en/function.json-encode.php
If your client is requesting the data in JSON format, then it's probably best to take the results from your database call and convert them to a JSON-formatted string before returning it to your client.
But your client's AJAX call could also be requesting the data in XML format, too.
So the answer depends on what the client is expecting.

Categories