We try to search items with use API: /api/library
Try via Postman and oauth2-xibo-cms.
In all cases library ignore any params (mediaId, media etc) and output images without filter.
In all cases library output only first 10 items. How get more than, or use something as shift, offset etc?
Peter
November 20, 2017, 10:14am
2
I’ll try to explain.
Melna_ru:
In all cases library ignore any params (mediaId, media etc) and output images without filter.
Via postman it should be something like for example:
{{url}}/api/layout?layout=default layout
you’re adding those after ? in the call not in the headers.
the same using oauth wrapper would be for example:
$layout = (new XiboLayout($this->getEntityProvider()))->get(['layout' => 'default layout']);
In both cases you can of course add more parameters.
It is useful to add embed parameter as well, depending on what information you need, it can be added the same way ie for example:
{{url}}/api/layout?layout=default layout&embed=regions,playlists
You will want to use start and length parameters ie for example:
{{url}}/api/layout?start=0&length=100
https://xibo.org.uk/manual/en/cms_api.html#grid_data_-_lists_of_records
Thanks again for previouse answer!
Next problem:
I don’t understand which format use for set params while adding new row in Dataset?
My code:
$access_uri = "/api/dataset/data/".$datasetId;
try {
$guzzle = $provider->getHttpClient();
$response = $guzzle->request('POST', $url.$access_uri, [
'headers' => [
'Authorization' => 'Bearer '.$token,
],
'form_params' => [
'vk_id' => $id, //column in dataset
'vk_title' => $title,
'vk_description' => $description,
]
]);
$result = json_decode($response->getBody());
}
However don’t work params after “?”. Also don’t work headers…
Probably I use wrong formatting or anything also…
Help please… very need example on PHP.
Peter
November 20, 2017, 2:00pm
5
I’ve explained that here, if you could take a look and let me know if that answers your question please - Problem while Adding or Editing Rows in a Dataset via API
As for php and wrappers, you can have a look at my tests here https://github.com/xibosignage/xibo-cms/blob/develop/tests/integration/DataSetTest.php#L351
You can look at the testRowAdd and testRowEdit to see how does that work there.
Also just to clarify, the parameters after ? (ie filters pretty much) are added like that in GET calls
in add/edit all parameters must be passed in body.
I solve problem!
Your link: Problem while Adding or Editing Rows in a Dataset via API
has help me.
It was not obvious to refer to columns by name “DatasetColumnId_xxx”.
Now part of code:
'form_params' => [
'dataSetColumnId_'.$columns[0]->dataSetColumnId => $tovar->id,
'dataSetColumnId_'.$columns[2]->dataSetColumnId => $tovar->title,
'dataSetColumnId_'.$columns[3]->dataSetColumnId => $tovar->description,
'dataSetColumnId_'.$columns[4]->dataSetColumnId => $tovar->price->text
]
However, tell me how format params for image assignment?
First upload:
$access_uri = “/api/library”;
$guzzle = $provider->getHttpClient();
$img_response = $guzzle->request(‘POST’, $url.$access_uri, [
‘headers’ => [
‘Authorization’ => 'Bearer '.$token,
‘Content-Type’ => ‘multipart/form-data’
],
‘multipart’ => [
[
‘name’ => ‘name’,
‘contents’ => ‘API UPLOAD’
],
[
‘name’ => ‘files’,
‘contents’ => fopen($tovar->thumb_photo, ‘r’) //<=== ???
]
]
$img = json_decode($img_response->getBody());
Second assign image to dataset:
'form_params' => [
...
'dataSetColumnId_'.$columns[8]->dataSetColumnId => $tovar->availability,
'dataSetColumnId_'.$columns[9]->dataSetColumnId => $img // <==== ???????
]
Peter
November 21, 2017, 8:42am
10
If you want an image from CMS library to the dataSet, then:
You will need a column with library image data type
In API add/edit row you will want to pass mediaId of the image you want to add as a value for the dataSetColumn_{dataSetColumnId} ie something like that:
where 177 is the mediaId I want to add to a new row in my dataSet (id 1) and column (id8).
Peter, you don’t understand me.
I wrote: we already have dataset with all fields.
We simply must do two thing:
Upload file in library;
Assign new image to dataset field.
Problems where are in both cases. I write symbols “<===???”
From tomorroy I almoust understand first problem.
But don’t understand format when assign image to field.
Peter
November 21, 2017, 1:19pm
12
I’m not sure where the problem is I’m afraid, I thought everything was already explained.
Library POST
You get the mediaId in the response.
Then you pass that mediaId as a value of dataSetColumn_{dataSetColumnId}
as I described in my previous post.
There is also example upload in the oauth repository, which can help you, if haven’t looked at it yet oauth2-xibo-cms/file.php at master · PeterMis/oauth2-xibo-cms · GitHub
You can also create the providers and then use wrapper to upload a file, which could be easier oauth2-xibo-cms/XiboLibrary.php at master · PeterMis/oauth2-xibo-cms · GitHub
an example of using this wrapper is in my tests, for example xibo-cms/LibraryTest.php at develop · PeterMis/xibo-cms · GitHub
if your $img
does have correct information about that uploaded image including mediaId, then you can use that to assign it to the dataset.
Thank you very match.
I use example: oauth2-xibo-cms/example/file.php