REST API smart client - new view

Hi, I’m coding in Python, and while working with the REST API, I noticed that it’s possible to control Smart Client views, add screens and views, and even move cameras within a view. However, after many attempts, I couldn’t find a way to add a channel to a view or change its position.

I also tried using PATCH and PUT requests to intentionally trigger errors and see if I could discover the correct endpoint or payload, but I wasn’t able to make any progress.

Is there a supported way to add a channel to a Smart Client view and control its position through the REST API?

Hi,

You can update views in the Smart Client through standard PATCH. The simplest is to try to create a view in the SC and then fetch it out using GET to see the format. Then you can pick out the parts you want to change and provide them in a PATCH.

Just be aware that to update the view items you need to provide the full list of view items, so you cannot just send a PATCH with one of them. You will have to read out the existing value and then PATCH with the full modified list.
Also, to ensure that all Smart Clients are automatically updated make sure that you provide your own value for the clientId property as if you don’t change it in the PATCH the Smart Client who did the last change will not notice that the view has been updated.

Hi, thanks for the reply.

I used the PATCH and GET requests to retrieve the required fields. When I tested it in Postman, I was able to create a view successfully. I used the same client ID, generated a new UUID for the viewItem, and provided the camera ID and name. The view appeared immediately.

However, when I implemented the same logic in code using the exact same fields, the PATCH request returned 200 OK, but the new view did not appear until I logged out and logged back in.

Interestingly, when I changed the client ID to a newly generated UUID, the view appeared immediately, but the application displayed the message “Camera is unavailable.”

After logging in again, the view worked correctly and the camera was available.

Do you know what could be causing this, or is there something else I need to do after the PATCH request to make the new view appear immediately without requiring a re-login?

As mentioned in my previous reply the clientId is what tells the different clients whether the view has been updated by themselves or something else. Thus, if you do a patch without clientId it will stay the same and the Smart Client that did the last update will think that it is an update it can ignore.
What is causing the problem with the camera load is hard to say. I just tried copying the exact content of a viewItemDefinitionXml property into one of the entries in the viewItem property on a patch (and updated clientId), just ensuring that the id attribute on the viewitem node in the xml matched the id property on the viewItem, and it worked fine - Smart Client updated right away. Please try to have a close look at the XML you are sending and compare with another one updated manually through Smart Client.

I know the XML is correct because after I log out and log back in, I can see the camera, so the details seem to be fine.

One thing I’m not sure about is the new clientId. Where did you get that value? Did you just generate a random UUID? If so, did you replace the clientId with that new UUID in all of the itemList entries as well?

I just generated one. It just has to be different from the ones used by other clients. Each SC generates one once it starts and use that throughout its session.
I only changed the overall clientId and nowhere else. Not sure what you mean by itemList (I see no such property) and there is no other clientId property in the entire json but in any case I did not change anything else.

Hi, I’m really starting to lose hope.

I’ve followed all the steps:

  1. Sent a GET request to retrieve the view and its view items.

  2. Added the CameraItem to the XML using the correct structure (I used the XML from the GET response as a template).

  3. Generated a new GUID for the client ID.

  4. Sent a PATCH request.

Sometimes it works, but most of the time it doesn’t.

The error I get most often is: “Camera is not available.”

I honestly can’t figure out what I’m doing wrong. Do I need to re-authenticate before sending the PATCH request? Is there anything else I need to include or update?

I managed to get it working only once using Postman. Every other attempt has resulted in the same error.

I still suspect that it is an issue with the XML. Could you try simply switch the XML of two of the items in the viewItem property list (and update the clientId of course), just to rule out whether it is due to the XML or not?

I’ll give it another try, but so far none of my attempts - either in Postman or in code - have worked.

Could you please send me the exact command, along with the XML request and response examples (before and after)? That would be extremely helpful.