I want to use the API to import a JSON object into a dataset by using /dataset/importjson/{dataSetId}.
My dataset (ID=2) exists of one column “Col1”. I want to add “value1” to the dataset with the PHP-code below.
$provider = new \Xibo\OAuth2\Client\Provider\Xibo([
‘clientId’ => ‘’, // The client ID assigned to you by the provider
’clientSecret’ => ‘’, // The client password assigned to you by the provider
’redirectUri’ => ‘’,
‘baseUrl’ => ‘’
]);
$xiboClient = new \Xibo\OAuth2\Client\Provider\XiboEntityProvider($provider);
$result = $xiboClient->post(’/dataset/importjson/2’,’{uniqueKeys: [col1], rows: [{col1: value1}]}’);
But the last rule gives the following error:
PHP Fatal error: Uncaught exception ‘Xibo\OAuth2\Client\Exception\XiboApiException’ with message '{
“error”: {
“message”: “Missing JSON Body”,
“code”: 422,
“data”: []
}
}
It’s not clear for me how I need to send the JSON-body with the post-method of the xiboClient. Can you help me? Thans a lot.
I have same problem too, tried several JSON format to import, but all failed with “Missing JSON Body”
I tried making a JSON file format same as the dataset which called CP, like the following attachment.
There are columns about Item, Price, Type, Remarks, Discount. (Also I tried importing a JSON file without Discount column.
I tried many methods and searched solutions on the Xibo community and google, still don’t get it why it responses “no JSON body”, could you please help me?
Thanks for help! It works, it should be Postman’s problem.
Apart from uniqueKeys, is there any other parameters to use?
I suggest that the JSON format could be added into Xibo manual for other users as beginners may not know.
Hi Peter, when I run the PHP-code below the response of the API is now:
Xibo\OAuth2\Client\Exception\XiboApiException: {
“error”: {
“message”: “Malformed JSON body, rows and uniqueKeys are required”,
“code”: 422,
“data”: []
}
$provider = new \Xibo\OAuth2\Client\Provider\Xibo([
‘clientId’ => // The client ID assigned to you by the provider
’clientSecret’ => // The client password assigned to you by the provider
’redirectUri’ => ‘’,
‘baseUrl’ =>
]);
$xiboClient = new \Xibo\OAuth2\Client\Provider\XiboEntityProvider($provider);
The description of the post-function can be found on the following link (line 84):
As you can see the second parameter should be an array. For that i use json_decode ($json); but the API doesn’t accept this format (“Malformed JSON body, rows and uniqueKeys are required”).
Do you have an idea what’s going wrong? Thanks a lot!