API tempel 1.8 Upload Media items

Hi
Can somebody please help met with a python solution to upload media?

Token etc works but i cannot upload media items.

I have reade the documentation /Library
If i use the
’file’ : ‘picture.jpg’
‘name’ : ‘XX0001’

i receive the message “Filetype not allowed”

Thank you in advance!

GR JAn

This api call is covered in the guide (using Postman) 1.8 API Introduction

In code, you could use oAuth2 wrapper https://github.com/PeterMis/oauth2-xibo-cms/blob/master/src/Entity/XiboLibrary.php#L64

Simple example of using that wrapper - https://github.com/PeterMis/xibo-cms/blob/develop/tests/integration/LibraryTest.php#L69

Have a look here as well https://github.com/PeterMis/oauth2-xibo-cms/blob/master/example/file.php

Perhaps that will give you some ideas

Hi Peter

Thanks for the info.

I am still getting the following message in Postman :

{“files”:[{“name”:“1492523640-7615”,“size”:1316610,“type”:“multipart/form-data; boundary=--------------------------449316675376425057078541”,“error”:“Filetype not allowed”}]}

Do you have any idea what is means?

(I can manually upload the files in Xibo 18)

Best REgards

Jan

Van: Peter Mis [mailto:noreply@xibo.org.uk]
Verzonden: dinsdag 18 april 2017 13:33
Aan: jan@jdt-services.nl
Onderwerp: [Xibo Community] [Support] API tempel 1.8 Upload Media items

https://community.xibo.org.uk/user_avatar/community.xibo.org.uk/peter/45/321_1.png

https://community.xibo.org.uk/users/peter Peter staff
April 18

This api call is covered in the guide (using Postman) https://community.xibo.org.uk/t/1-8-api-introduction/7702 1.8 API Introduction

In code, you could use oAuth2 wrapper https://github.com/PeterMis/oauth2-xibo-cms/blob/master/src/Entity/XiboLibrary.php#L64 https://github.com/PeterMis/oauth2-xibo-cms/blob/master/src/Entity/XiboLibrary.php#L64

Simple example of using that wrapper - https://github.com/PeterMis/xibo-cms/blob/develop/tests/integration/LibraryTest.php#L69 https://github.com/PeterMis/xibo-cms/blob/develop/tests/integration/LibraryTest.php#L69

Have a look here as well https://github.com/PeterMis/oauth2-xibo-cms/blob/master/example/file.php https://github.com/PeterMis/oauth2-xibo-cms/blob/master/example/file.php

Perhaps that will give you some ideas

Could you show me a screenshot of postman with this call and error please?

I assume postman is correctly configured with your CMS and some simple calls work fine?

HI Peter

Simple call work

I receive the token, can request a media list etc.

As I see, it’s incorrect parameter name
you have file, while it should be files

It’s correct in my guide, but indeed is wrong in the API documentation - fixed in my local branch and will be updated probably in the next release when we merge it.

Thank you for bringing this to my attention.

Hi Peter

It works now in Postman

The only problem is how am i going to get it work in python?

Gr Jan

Van: Peter Mis [mailto:noreply@xibo.org.uk]
Verzonden: dinsdag 18 april 2017 16:40
Aan: jan@jdt-services.nl
Onderwerp: [Xibo Community] [Support] API tempel 1.8 Upload Media items

https://community.xibo.org.uk/user_avatar/community.xibo.org.uk/peter/45/321_1.png

https://community.xibo.org.uk/users/peter Peter staff
April 18

As I see, it’s incorrect parameter name
you have file, while it should be files

It’s correct in my guide, but indeed is wrong in the API documentation - fixed in my local branch and will be updated probably in the next release when we merge it.

https://community.xibo.org.uk/uploads/default/original/2X/a/af880c2cd1785a701ce1182cf7f5fafa19a39ae3.png

Thank you for bringing this to my attention.

Hi Peter

How can i filter media items?

e.g. type : ‘image’

Does not work

Gr JAn

you’d need to add ?type=image to the call

GET {{url}}/api/library?type=image http://xibo.org.uk/manual-tempel/api/#!/library/librarySearch

HI Peter

Thanks for the info, it works now.

If i undersand the API structure, it seems to be the following structure:

Layout

        Regions

                    Playlist

                               Widget

                                           Media Item

How can i determine the relation:

Layout- Regions- Playlist

Best Regards

Jan

Hi

Already found the answer:

?embed=regions,playlists

will let you see regions and playlists.

Thanks!!!

GR JAn

Yes, that’s exactly correct, apologies that I didn’t get back to you, but early mornings are usually rather busy :slight_smile:

If you downloaded postman collection linked in my API guide, I believe that the GET layout call there will have
?embed=regions,playlists as well

Hi Peter

Do you know if it is possible to add an owner or ownerId to the media upload api?

Gr JAn

The owner of the file uploaded via API will be set to the owner of the application.

ie for example for postman, if you’ve added that application from your account to the CMS then you’re the owner of it, then if you upload new media via postman, you will be the owner of that media as well.

If you call GET media for that media file then you will see owner in response as well.

Hi Peter

Goal is to have different users with their own Media

Does this means that i have to create seperate applications (API) to upload data?

Gr JAn

Yes, I believe that would be the way to go if it’s required.

So as long as you change the ‘name’ parameter passed with the upload file call, it will be uploaded to the CMS:
For example, I’ve uploaded the same sceenshot 3 times as API Upload 1 API Upload 2 and API Upload 3

then in CMS library:

So if we look at the response code

the /library?file=witcher3_2016_09_17_21_44_13_762.png is the original fileName
on upload it receives a mediaId and is stored as <mediaId>.png

the /library?file=API%20UPLOAD%203 is the name of the media file specified in the upload API call ie API Upload 3 as %20 is encoded space character ' '

Does that makes sense?

The API Library search finds only the first 10 items
Is there a possibility to retrieve ALL item?

Solution:
Add the follwing to the request:
?start=0&length=100

Hi Peter

Is there also an api to assign media to a display?

I have seen the api for displaygroup:

api/displaygroup/10/media/assign

Best Regards

Jan

It is possible, although assigning media files directly to a display (or display group for that matter) is not really recommended, in most cases you want to have all required medias on the layout and schedule that layout to the player.

Anyway, each display has it’s own unique displayGroupId (display specific), which you can see by using the following call
GET {{url}}/api/display?embed=displaygroups

You can also add a display name as a filter like

GET {{url}}/api/display?display=DISPLAYNAME&embed=displaygroups

Once you will have the display specific displayGroupId you can use the call you mentioned to assign media to it.