New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support array for json_data posted in rest/json service #99
Conversation
When using x-www-form-urlencoded we could leverage the possibility to send array instead of raw json as PHP support it.
Actually, JSON is a string by definition, but I like your suggestion. |
@Hipska absolutely JSON is a string. But sending raw JSON through HTTP x-www-form-urlencoded is not a good idea for maintenance/readability. Or we could support application/json instead of x-www-form-urlencoded. That could work too. |
Just a note for when this PR will be reviewed : there is a corresponding Combodo support UR, referenced R-023452 |
Doc has been updated. https://www.itophub.io/wiki/page?id=latest%3Aadvancedtopics%3Arest_json |
This comment has been minimized.
This comment has been minimized.
Please use english :) |
This was submitted in Combodo ticket DB as N°2767, candidate for iTop 2.8. @Ousret sorry it took us so much time to accept this PR... We were (and still are in a way) quite busy with the 2.7.0... We are aiming to integrate this in 2.8.0. |
If this would be implemented, can I suggest that the params would then be like this?
|
Hello, Here is below a PHP caller using current json_data as string. Can you send back a script that would generate the new parameter format ? <?php
$curl = curl_init();
$aStdOptions = array('auth_user' => 'admin','auth_pwd' => 'admin');
// JSON form
$aJsonData = array('json_data' => '{
"operation": "core/get",
"class": "Person",
"key": "SELECT Person", "limit": "10", "page": "1"
}');
curl_setopt_array($curl, array(
CURLOPT_URL => 'http://localhost/itop-dev/webservices/rest.php?version=1.4',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array_merge($aStdOptions, $aJsonData),
CURLOPT_HTTPHEADER => array(
'Cookie: XDEBUG_SESSION=netbeans-ide',
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response; |
When implementing my suggestion, it would be: $aJsonData = array(
"operation" => "core/get",
"class" => "Person",
"key" => "SELECT Person",
"limit" => 10,
"page" => 1
); When the initial suggestion is implemented, it would be: $aJsonData = array(
"json_data[operation]" => "core/get",
"json_data[class]" => "Person",
"json_data[key]" => "SELECT Person",
"json_data[limit]" => 10,
"json_data[page]" => 1
); |
Many thanks Thomas, I was able to test then :) I like your solution... Should be doable with little modification... I'm merging this for now :) |
@Ousret I will add you to the contributors list in our README.md. How would you prefer to be seen ? With your real name, your github name ? |
With my Github name, or both. 👍 |
This was also merged to support/2.7 branch, and will be available in the future 2.7.1 version. |
@Ousret I don't see this reflected in the docs (Also not for 2.7) |
Ousret comment was made in nov 2019... |
Okay, now you make me wonder what he meant. What exactly was updated in the doc? Since I would expect a line somewhere you could also use the array syntax as introduced by this PR.. |
Woops I forgot to answer about the documentation sorry ! I've just published this little extra paragraph : https://www.itophub.io/wiki/page?id=latest%3Aadvancedtopics%3Arest_json#parameters_in_a_php_array_form |
Great, maybe also mention this on the 2.7 wiki pages for people staying on the LTS release? |
When using x-www-form-urlencoded we could leverage the possibility to send array instead of raw json as PHP support it out of the box.
This change/bugfix is not BC-Break.
I do not know if this is a bug or not, when reading current documentation, it is not clearly stated that
json_data
should be a string.instead of
It is more convenient to post json_data[operation]=core/get instead of json_data={"operation": "core/get"..