1.8 Alpha 3 - Change Widget Duration Via API

Is there a way to set the duration on a widget? It looks possible through the CMS.

They all have a useDuration parameter and a duration parameter. You want to set useDuration to 1 or on and then set the duration to whatever you need.

I will try and work out how to document the Widget calls properly - or at the very least document them with the parameters they all share.

1 Like

Thank you.:slight_smile: 20 Char.

1 Like

Am I doing something wrong?

I was able to get this from the log (Ran into a few problems when searching the log):

23	efd8d39	2016-05-01 00:00	API	POST	INFO		/playlist/library/assign/:id	PDO stats: {"connections":2,"selects":6,"inserts":0,"updates":0}.
22	efd8d39	2016-05-01 00:00	API	POST	ERROR		/playlist/library/assign/:id	array_map(): Argument #2 should be an array Exception Type: ErrorException
21	efd8d39	2016-05-01 00:00	API	POST	DEBUG		/playlist/library/assign/:id	array_map(): Argument #2 should be an array#0 [internal function]: Slim\Slim::handleErrors(2, 'array_map(): Ar...', 'C:\\wamp\\www\\xib...', 264, Array) #1 C:\wamp\www\xibo18alpha\lib\Service\SanitizeService.php(264): array_map('intval', '17') #2 C:\wamp\www\xibo18alpha\lib\Controller\Playlist.php(389): Xibo\Service\SanitizeService->getIntArray('media') #3 [internal function]: Xibo\Controller\Playlist->libraryAssign('2') #4 C:\wamp\www\xibo18alpha\vendor\akrabat\rka-slim-controller\RKA\Slim.php(79): call_user_func_array(Array, Array) #5 [internal function]: RKA\Slim->RKA\{closure}('2') #6 C:\wamp\www\xibo18alpha\vendor\slim\slim\Slim\Route.php(468): call_user_func_array(Object(Closure), Array) #7 C:\wamp\www\xibo18alpha\vendor\slim\slim\Slim\Slim.php(1357): Slim\Route->dispatch() #8 C:\wamp\www\xibo18alpha\vendor\slim\slim\Slim\Middleware\Flash.php(85): Slim\Slim->call() #9 C:\wamp\www\xibo18alpha\vendor\slim\slim\Slim\Middleware\MethodOverride.php(92): Slim\Middleware\Flash->call() #10 C:\wamp\www\xibo18alpha\lib\Middleware\ApiAuthenticationOAuth.php(84): Slim\Middleware\MethodOverride->call() #11 C:\wamp\www\xibo18alpha\lib\Middleware\State.php(103): Xibo\Middleware\ApiAuthenticationOAuth->call() #12 C:\wamp\www\xibo18alpha\lib\Middleware\Storage.php(46): Xibo\Middleware\State->call() #13 C:\wamp\www\xibo18alpha\lib\Middleware\Xmr.php(38): Xibo\Middleware\Storage->call() #14 C:\wamp\www\xibo18alpha\vendor\slim\slim\Slim\Slim.php(1302): Xibo\Middleware\Xmr->call() #15 C:\wamp\www\xibo18alpha\web\api\index.php(78): Slim\Slim->run() #16 {main}
20	efd8d39	2016-05-01 00:00	API	POST	DEBUG		/playlist/library/assign/:id	SET @playlistId='2'; SELECT playlist.* FROM `playlist` WHERE 1 = 1 AND playlistId = @playlistId
19	efd8d39	2016-05-01 00:00	API	POST	DEBUG		/playlist/library/assign/:id	New Player Action Service from DI
18	efd8d39	2016-05-01 00:00	API	POST	DEBUG		/playlist/library/assign/:id	SET @userId='1'; SELECT * FROM `useroption` WHERE userId = @userId
17	efd8d39	2016-05-01 00:00	API	POST	DEBUG		/playlist/library/assign/:id	SET @userId='1'; SET @isUserSpecific='0'; SET @isEveryone='0'; SELECT `group`.group, `group`.groupId, `group`.isUserSpecific, `group`.isEveryone , `group`.libraryQuota FROM `group` WHERE 1 = 1 AND `group`.groupId IN (SELECT groupId FROM `lkusergroup` WHERE userId = @userId) AND isUserSpecific = @isUserSpecific AND isEveryone = @isEveryone
16	efd8d39	2016-05-01 00:00	API	POST	DEBUG		/playlist/library/assign/:id	Loading 1. All Objects = 0
15	efd8d39	2016-05-01 00:00	API	POST	DEBUG		/playlist/library/assign/:id	SET @clientId='NZMS5H3IHapT0hRPT6RxZHvYvRs7XUzj1G4j2TZt'; SELECT `user`.userId, userName, userTypeId, loggedIn, email, lastAccessed, newUserWizard, retired, CSPRNG, UserPassword AS password, group.groupId, group.group , `pages`.pageId AS homePageId, `pages`.title AS homePage , `user`.firstName, `user`.lastName, `user`.phone, `user`.ref1, `user`.ref2, `user`.ref3, `user`.ref4, `user`.ref5 , IFNULL(group.libraryQuota, 0) AS libraryQuota FROM `user` INNER JOIN lkusergroup ON lkusergroup.userId = user.userId INNER JOIN `group` ON `group`.groupId = lkusergroup.groupId AND isUserSpecific = 1 LEFT OUTER JOIN `pages` ON pages.pageId = `user`.homePageId WHERE 1 = 1 AND user.userId = (SELECT userId FROM `oauth_clients` WHERE id = @clientId) ORDER BY userName
14	efd8d39	2016-05-01 00:00	API	POST	DEBUG		/playlist/library/assign/:id	SET @access_token='50RSmUvBKN3AvRu4L7nJ6xjDHX8ejZz0lNtArewj'; SELECT oauth_sessions.id, oauth_sessions.owner_type, oauth_sessions.owner_id, oauth_sessions.client_id, oauth_sessions.client_redirect_uri FROM oauth_sessions INNER JOIN oauth_access_tokens ON oauth_access_tokens.session_id =oauth_sessions.id WHERE oauth_access_tokens.access_token = @access_token

Ok figured out, I should of had media[0] and not media. I do get a return response, but it doesn’t look like it accepted the duration as it was still added with the default duration and useDuration shows 0.

Those parameters are only available on widget edit, but otherwise you have them correct.

The media parameter is an array (i.e. you can assign as many at once as you like) - which is also why the duration parameters aren’t available.

I was wondering about that. It didn’t make sense to me, but I also did not see documentation for widget yet either.

So for widget, is it just a POST to api/widget?

Update: Looking through the code, it looks like we should be using PUT and the path is api/playlist/widget/:id. However, passing the access_token, useDuration, and duration do not seem to do it. (Will dig somemore to see if I can’t track down what the accepted parameters are)

Update 2: Sending the right information in the headers seems to help…:stuck_out_tongue_winking_eye: Using Authorization in the header for PUT and not using access_token parameter did the trick.

I’d recommend always using the header where possible, makes things simpler to keep track of - personal preference of course :slight_smile:

There isn’t a reason why the duration/use duration couldn’t be included on the Playlist Media Assign API call - it isn’t at the moment because the UI didn’t require it (not a good reason I know).

I can absolutely see why you would want to do the assignment and set a duration in one call - although I’d suggest that if you provided a duration then you want useDuration = 1 and don’t need to set that explicitly.

I’ll create an enhancement for it:

1 Like