Format of JSON-BODY

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.

{"CP":[
	{"Item":"test", "Price":"2", "Type":"test", "Remarks":"for testing", "Discount":"2"},
	{"Item":"hey", "Price":"25", "Type":"test", "Remarks":"for testing", "Discount":"5"}
]}

Is there any guideline for JSON import and how to match with current dataset or a new dataset?

I believe that Dan explained it very well here Importjson > malformed - #2 by dan

So let’s use that example here, I’ve created a new dataSet with 4 columns to match the names in Dan’s example.

then in Postman as that’s easiest for me at the moment:

Result in CMS:

Do you know what’s wrong?
Thanks.

{
   "uniqueKeys":[
      "Col1"
   ],
   "rows":[
      {
         "Col1":"value1"
      }
   ]
}

That should work fine, assuming you didn’t change your column name, as that by default is called Col1

so if you have it as col1 in call and Col1 in CMS then it will not work and you will see “No data found in request body” in response.

Thanks for showing Dan’s explanation.
I formatted my JSON according to his post. However it still doesn’t work

It response code 422, “Missing JSON Body”

Here’s my dataset column:

Here’s my JSON file:

{
	"uniqueKeys": [
		"item"
	],
	"rows": [{
			"item": "test",
			"price": "2",
			"type": "test",
			"discount": "0",
			"remarks": "for testing"
		},
		{
			"item": "hey",
			"price": "25",
			"type": "test",
			"discount": "0",
			"remarks": "for testing"
		}
	]
}

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?

Two things.

dataSetId - that’s provided in the path you do not pass that in the Body.

As for data, I’m not 100% sure but I don’t think you can pass json like that in Postman.

You should pass that as in my earlier example ie

Body → raw
Change the content type to JSON (application/json)
paste your json there

ie something like that:

and in CMS it created:

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.

I’m glad that works for you.

As for parameters, that’s all there is to it, dataSetId in the path and then json formatted as in the examples in this topic.

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);

$json = ‘{“uniqueKeys”:[“Col1”],“rows”:[{“Col1”: “value1”}]}’;
$jsonParam = json_decode ($json);

$result = $xiboClient->post(’/dataset/importjson/2’, $jsonParam);

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!