Solved

Getting Graph Sharing Token via REST API


Userlevel 4
Badge

Hello,

I am new member of LogicMonior.    I have created new dashboard and done about adding device graph into dashboard via API, it work!      but now, I want to generate “Widget Embedded URL” and also get “Sharing Token” via REST API, after created graph on Dashboard.     Is it possible to do that?

 

Thank you very much for all recommendation and comment

 

 

icon

Best answer by Stuart Weenig 14 July 2023, 15:44

View original

14 replies

Userlevel 7
Badge +20

It doesn’t appear to be documented, which means it won’t be supported, but you should be able to do it.

You have to do a POST to /setting/admins/sharingtokens?fields=token

The payload should consist of the widget id like this:

{"resourceType":"widget","resourceId":11124,"enable":true,"note":""}

Where 11124 is the widget id in this case. I think you should be able to post in a note as well. The UI doesn’t prompt for the note when you first create it, but it does allow you to edit it afterward and add the note. Main point: note should be doable, but is optional.

Userlevel 4
Badge

Wow, Let me try to do as your recommended. 

i really appreciate your help thank you very much @Stuart Weenig   :) 

 

Userlevel 4
Badge

Hi  @Stuart Weenig 

I have got “415Unsupported Media Type” as following detail 

 

 

Userlevel 7
Badge +20

It looks like you’re trying to post in the token. You don’t post in the token, it’ll be in the response.

Also, add a header called “X-Version” with a value of 3. This ensures you are using API v3 (if you don’t specify it will assume v1 or v2, which might not be backward compatible with a v3 reuqest)..

You might consider manually creating the token with the developer tools for your browser open. This will let you see on the network tab all the details of the request that are made when the UI makes the call.

Userlevel 4
Badge

Wow!  It works!!    i really appreciate your help thank you very very very much Mr. @Stuart Weenig   :) 

Userlevel 4
Badge

I would like to thanks @Stuart Weenig  for helping me to create sharing token last time.      Again, I am looking for 2 things about widget as follwoing;

1)  Once sharing widget has been created with fix time_scale (like 7days, 30days), but Is it possible to get graph with the other time scale via browser like  “starttime=123456&stoptime=56789&auth=LMSTv1%3xxxxx”

2) If we want to share whole dashboard.    Is dashboard also able to create sharing_token like graph widget?   I could not see via LM UI

Thank you very much

Userlevel 7
Badge +20
  1. I don’t know if that’s possible. You’d have to just try it. I’m not sure it is possible since the token is restricted to certain timeframes so you’d need a different token for each timeframe.
  2. Probably not the way you want. You can share the dashboard, and you can do it on a schedule. But the share link would change each time. You might be able to get that out of the API, but I haven’t tried it and it’s probably an undocumented/unsupported endpoint. What you’d do in that case is create a service account in LM with permissions to that dashboard and the devices that populate it. You don’t have to give that service account access to any of the other pages (resources, mapping, websites, alerts, etc. but you could if you wanted). Use that service account to pull up the LM page somewhere else, or embed it in another page using iframe. Understand that you’d just need to log in with the service account. There are autorefresh options in the UI, but those won’t keep you logged in. Look for a browser extension based auto-refresh option to keep the service account logged in and refreshing the page every hour or so.
Userlevel 4
Badge
  1. I don’t know if that’s possible. You’d have to just try it. I’m not sure it is possible since the token is restricted to certain timeframes so you’d need a different token for each timeframe.
  2. Probably not the way you want. You can share the dashboard, and you can do it on a schedule. But the share link would change each time. You might be able to get that out of the API, but I haven’t tried it and it’s probably an undocumented/unsupported endpoint. What you’d do in that case is create a service account in LM with permissions to that dashboard and the devices that populate it. You don’t have to give that service account access to any of the other pages (resources, mapping, websites, alerts, etc. but you could if you wanted). Use that service account to pull up the LM page somewhere else, or embed it in another page using iframe. Understand that you’d just need to log in with the service account. There are autorefresh options in the UI, but those won’t keep you logged in. Look for a browser extension based auto-refresh option to keep the service account logged in and refreshing the page every hour or so.

 

Okay, I understood your comment for both 1) and 2).   I am very new in programing too ^^, but try to do as more as I can.      getting sharing token from API that you recommend last time is very good enough for my team.         Thank you very much @Stuart Weenig  for your advice and help :)

Userlevel 4
Badge

็Hi, @Stuart Weenig  Thanks for helping me to create sharing token last time.     I have found that  “common.timerange” is always be “7days” when created sharing-widget via API with differently timescale)    

 



I am not sure that Is it possible to set “common.timerange” of sharing-widget (like 3months, 30days) according to Default time range (Varies per widget)?


Thank you very much in advance for your support

Vee

Userlevel 7
Badge +20

It looks like sharing a widget only allows you to share the widget with the default timeframe configured in the widget. Probably the easiest would be to create a dashboard with the different timeframes you want and generate a sharing token for each one.

You might be able to generate the sharing token, reconfigure the widget to a different default timeframe, and then generate another sharing token. But i’m not sure that would work. Both tokens would probably end up pointing to the same timeframe since the timeframe is in the widget not in the token.

Userlevel 4
Badge

It looks like sharing a widget only allows you to share the widget with the default timeframe configured in the widget. Probably the easiest would be to create a dashboard with the different timeframes you want and generate a sharing token for each one.

You might be able to generate the sharing token, reconfigure the widget to a different default timeframe, and then generate another sharing token. But i’m not sure that would work. Both tokens would probably end up pointing to the same timeframe since the timeframe is in the widget not in the token.

Thank you very much for your quicks help,    Before posting, I have already created a dashboard with different timeframes, but I still got the same result (time-range still be 7 days)

Anyway, I will try to do it again as your recommendation.      Thank you very much Mr. @Stuart Weenig
 

Userlevel 7
Badge +20

Before posting, I have already created a dashboard with different timeframes

You mean, you edited each widget to have a different default timeframe? That is what I’m suggesting. If that doesn’t work, i’m not sure what to try next.

Do you mean that you made a different dashboard and selected a different timeframe at the top of the dashboard? That won’t work. The timeframe selected at the top of the dashboard has no impact on the configuration of the widget, which is what is used when the widget is displayed externally.

Userlevel 4
Badge

Before posting, I have already created a dashboard with different timeframes

You mean, you edited each widget to have a different default timeframe? That is what I’m suggesting. If that doesn’t work, i’m not sure what to try next.

Do you mean that you made a different dashboard and selected a different timeframe at the top of the dashboard? That won’t work. The timeframe selected at the top of the dashboard has no impact on the configuration of the widget, which is what is used when the widget is displayed externally.

ํYes, I have created each widget to have a different default timeframe and put into dashboard, Then I create sharing widget via API as you guide me.  

Userlevel 7
Badge +20

That’s odd then. If you look at the dashboard and for the dashboard (at the top right) you select “Default timeframe” do the widgets all show the proper timeframe?

Reply