Answered

How to implement miro.board.widgets.get() or .create()?

  • 13 October 2020
  • 2 replies
  • 1214 views

Userlevel 2
Badge +3

Hi,

Sorry if this is a trivial question or is at some point answered in the documentation. But I have been trying multiple ways of implementing these 2 methods and none seem to work right now. I’m trying to use this functionality in a miro board extension, the biggest problem is that my implementation worked on last friday, but when I tried to follow up on monday, I have this error every time: Uncaught TypeError: Cannot read property 'widgets' of undefined

My attempts to use these methods:

1)

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

2)

let AllWidgetsOnBoard = Promise.resolve(miro.board.widgets.get({

        "type" : "SHAPE"

    })) //returns all widgets on board with shape type

    AllWidgetsOnBoard.then(function(v) {

        console.log("AllWidgetsOnBoard: ", AllWidgetsOnBoard)

    })

3)

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

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

    })

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

4)

 

return miro.board.widgets.create({ 

                    "type": "SHAPE",

                    "title": "Super Object",

                    "id" : "SuperObject",

                    "style": {

                        "backgroundColor": "#ff00ff"

                    }

                })

On Friday miro.board.widgets.get() would give me a list of all widgets on the board so I really don’t understand what went wrong, Thanks for your time

icon

Best answer by Daniela Gavidia 13 October 2020, 14:22

View original

2 replies

Userlevel 4
Badge

Hello Sami,

Could you confirm that the SDK is loaded before you attempt to make these calls? When you load the board, you should see “SDK Loaded” printed in the Javascript console, as mentioned in Step 1.2 here:

https://developers.miro.com/docs/how-to-start

 

If you see “SDK Loaded” and no other suspicious errors, you can try typing in the Javascript console:

await miro.board.widgets.get()

This should return the widgets. Let us know if it works. It is possible that your SDK is not loading for some reason.

 

If getting the widgets works in the Javascript console, but not in your web-plugin, please make sure that the SDK is ready before calling await miro.board.widgets.get(). See Step 2 in the link above. Your calls to the API should be done within the miro.onReady callback.

 

Kind regards.

 

Daniela

Developer Experience Team

Miro

Userlevel 2
Badge +3

Hello Sami,

Could you confirm that the SDK is loaded before you attempt to make these calls? When you load the board, you should see “SDK Loaded” printed in the Javascript console, as mentioned in Step 1.2 here:

https://developers.miro.com/docs/how-to-start

 

If you see “SDK Loaded” and no other suspicious errors, you can try typing in the Javascript console:

await miro.board.widgets.get()

This should return the widgets. Let us know if it works. It is possible that your SDK is not loading for some reason.

 

If getting the widgets works in the Javascript console, but not in your web-plugin, please make sure that the SDK is ready before calling await miro.board.widgets.get(). See Step 2 in the link above. Your calls to the API should be done within the miro.onReady callback.

 

Kind regards.

 

Daniela

Developer Experience Team

Miro

Hi,

 

I solved the issue meanwhile. The problem was that I didn’t encapsulate the commands in a miro.onReady() codeblock like so, if anyone experiences the same issue:

 

miro.onReady(() => {

            miro.board.widgets.get().then(function(theWidgets) {

                widgetFinder(theWidgets) //just a custom function that uses the data

            })

        })

 

I don’t understand why this worked without the on ready codebolck before.

Reply