REST API does not retrieve correct IDs of widgets

Hello,

we are currently experiencing a problem, in which the REST API does not retrieve the correct widget IDs.
This means that if I check the widget ID through the HTML Inspector in FireFox, I am able to get the correct ID. On the other hand if I perform the get call via the REST API I am getting a other ID for the exact same widget.
This only seems to occure when the layout is in draft mode, which means that if the layout is published
I am able to retrieve the correct widget ID via an API call.
Publish Mode: HTML Inspector Value (correct) - API Value (correct) (Both are equal)
Draft Mode: HTML Inspector Value (correct) - API Value (false) (not equal)
The ID retrieved in draft mode from the API is useless and will not work with any other call trying to edit the widget, while the one retrieved via HTML Inspector will work just fine.

Well…the behavior described above seems to be expected.
This means that there are layouts (childlayouts) that are now shown in the Xibo webGUI. Furthermore all layouts shown by the webGUI are so called parentlayouts.
Theire childlayouts can be queried with the parentId parameter when calling /api/layout.
This way the editable layout should be returned.
This whole thing seems not well documented and it should be noted, that this one possible reason why people are seeing

{ error: 
   { message: 'This Layout is not a Draft, please checkout.',
     code: 422,
     data: { property: 'layoutId' } } }

even though theire layout in the webGUI is in draft mode. The layout is in draftmode, but it is not the editable one.
Keep in mind that this only happens when the layout in the webGUI is in draft mode. If the layout is published there is no childlayout.

@dan
I seem to be hitting this issue now myself.
I create a layout and want to add a subplaylist widget to then assign the playlist.
I get the ‘This Layout is not a Draft, please checkout.’
But if I try to checkout I get the ‘Layout is already checked out’
I’m not sure how to resolve…
Any help is appreciated!!

When a Layout is Published there is only one of them, but you can’t edit anything on it - you can get the Regions, Playlists and Widgets, but you will receive the message “This Layout is not a Draft, please checkout” if you try and edit.

To edit that Layout you need to checkout providing the layoutId of the Layout you want to checkout.

This creates a complete copy of the Layout for editing and returns you the Draft Layout in the response. You can then use the ID of the draft for any operations that you need to take on that Layout.

Draft Layouts have a parentId property, which is the ID of the published version of that Layout. You can get the Draft version of a Layout at any time by calling /layout?parentId=X.

Once you have done your editing, or you want to discard, you need to call publish or discard accordingly. Both of these API routes take the published layoutId and return the final Layout in the call (for the published one this is the draft, now published… for the discard one this is the original published one)

I hope that clears things up - its a fair comment that this could be better documented.

In the Create Layout call is there a way to get the Draft Layout Id right from that call?
Instead of having to then make a subsequent call to get the Id that I will need to modify.

Oddly… no there isn’t. We changed Layout Add in 2.2 to auto checkout the new Layout (see https://github.com/xibosignage/xibo/issues/1925), but we didn’t return the ID. I’ve no idea why, its probably an oversight.

I’ve created an improvement to address that.

Thanks!
At least I know why the issue was happening now. Certainly is a but muddy from the UI and error messages but glad to hear you are working to improve! :slight_smile:

2 Likes