mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
Support array for json_data posted in rest/json service (#99)
Previous syntax :
```
CURLOPT_POSTFIELDS => array(
'auth_user' => 'admin',
'auth_pwd' => 'admin',
'json_data' => '{
"operation": "core/get",
"class": "Person",
"key": "SELECT Person", "limit": "10", "page": "1"
}'
);
```
Now we can also use :
```
CURLOPT_POSTFIELDS => array(
'auth_user' => 'admin',
'auth_pwd' => 'admin',
"json_data[operation]" => "core/get",
"json_data[class]" => "Person",
"json_data[key]" => "SELECT Person",
"json_data[limit]" => 10,
"json_data[page]" => 1
);
```
This commit is contained in:
@@ -79,7 +79,7 @@ try
|
||||
utils::UseParamFile();
|
||||
|
||||
$oKPI->ComputeAndReport('Data model loaded');
|
||||
|
||||
|
||||
$iRet = LoginWebPage::DoLogin(false, false, LoginWebPage::EXIT_RETURN); // Starting with iTop 2.2.0 portal users are no longer allowed to access the REST/JSON API
|
||||
$oKPI->ComputeAndReport('User login');
|
||||
|
||||
@@ -130,11 +130,26 @@ try
|
||||
{
|
||||
throw new Exception("Missing parameter 'json_data'", RestResult::MISSING_JSON);
|
||||
}
|
||||
$aJsonData = @json_decode($sJsonString);
|
||||
if ($aJsonData == null)
|
||||
|
||||
if (is_string($sJsonString))
|
||||
{
|
||||
throw new Exception("Parameter json_data is not a valid JSON structure", RestResult::INVALID_JSON);
|
||||
}
|
||||
$aJsonData = @json_decode($sJsonString);
|
||||
}
|
||||
elseif(is_array($sJsonString))
|
||||
{
|
||||
$aJsonData = (object) $sJsonString;
|
||||
$sJsonString = json_encode($aJsonData);
|
||||
}
|
||||
else
|
||||
{
|
||||
$aJsonData = null;
|
||||
}
|
||||
|
||||
if ($aJsonData == null)
|
||||
{
|
||||
throw new Exception('Parameter json_data is not a valid JSON structure', RestResult::INVALID_JSON);
|
||||
}
|
||||
|
||||
$oKPI->ComputeAndReport('Parameters validated');
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user