Answered

Is there a miro board command to gather all widgets?

  • 9 October 2020
  • 5 replies
  • 898 views

Userlevel 2
Badge +3

What is the best way to get a list of all widgets on miro whiteboard. I would want something like “miro.board.widgets.get.all”. Used this for reference https://developers.miro.com/reference#get-board-widgets-1

 

Edit: deleted the original question, this ^ was pretty much it 

icon

Best answer by Viktor Razumov 9 October 2020, 12:47

View original

5 replies

Userlevel 2
Badge +3

found an answer, can’t delete the question for some reason

Userlevel 1

Hi Sami,

 

You were almost there - calling miro.board.widgets.get() will return a promise, that when resolved, provides a full list of widgets on the board.

 

Hope this answers your question!

Userlevel 2
Badge +3

Hi Viktor,

 

Yes I just found out about it, thanks a lot for your help.

Userlevel 2
Badge +3

Hi Sami,

 

You were almost there - calling miro.board.widgets.get() will return a promise, that when resolved, provides a full list of widgets on the board.

 

Hope this answers your question!

Hi Viktor,

calling miro.board.widgets.get() has worked for me for the past 2 days returning all widgets on board with this syntax: 

    let allWidgets =  miro.board.widgets.get().then(function() {

        console.log("widgets on board: ", allWidgets)

    })

 

or this for only shapes

    let allWidgets =  miro.board.widgets.get({

         “type” : “SHAPE”

}).then(function() {

        console.log("widgets on board: ", allWidgets)

    })

 

but from today morning i’m only getting this error in both cases: Uncaught TypeError: Cannot read property 'widgets' of undefined . Is my syntax wrong or has something that you know of changed on miros side?

 

Thanks for your time.

Userlevel 1

Hi @Sami Ljimari 

miro.board.widgets.get() is an asynchronous function and returns a promise, but not an array of widgets. You need to either await the call, or use an argument in the .then() callback, like this: 

 

let allWidgets = await miro.board.widgets.get()

console.log("widgets on board: ", allWidgets)

 

or this for only shapes

    miro.board.widgets.get({

         “type” : “SHAPE”

    }).then(function(allWidgets) {

        console.log("widgets on board: ", allWidgets)

    })

 

Hope this helps you.

Reply