Web plugins examples do not work

  • 9 May 2022
  • 1 reply
  • 28 views

Copy and pasting the web-plugin examples do not work.

I tried this example, and it give an error relating to ‘create’ being undefined.

const viewport = await miro.board.viewport.get()
const centeredX = viewport.x + viewport.width / 2
const centeredY = viewport.y + viewport.height / 2
miro.board.widgets.create({type:'sticker', x:centeredX, y:centeredY})

I looked through the miro.board object properties in the console, and ‘widgets’ does not exist.

I do however have a bunch of functions like ‘miro.board.createSticker’. Am i on and old version or something? How do i get these examples working?


1 reply

Userlevel 7
Badge +4

@samsamm777 
Indeed. You are probably using SDK v2 and these code examples are from v1
v2 is nearly deprecated if not fully, and the platform team has shifted their focus entirely onto v2. So v2 is the one to learn.


The code looks similar and the platform team will have their work cut out for them to clean up this forum WRT code examples … but here’s some help telling them apart in the meantime.

V1 Reference here

V2 Reference here (plenty of code examples here)

  • SDK V2 wasn’t released until approx 2022. So anything in the forum before that point you can assume is v1. 
  • v1 calls board items “widgets” (as you have discovered) and v2 calls them ‘items
  • all of the create methods are unique to each item in v2 createStickyNote() whereas in v1 there was one monolithic function for creating any board ‘widget’ (try to call them ‘item’ as that is going -forward term for them)  miro.board.widgets.create()
  • all of the updates in v2 are done with item.sync() whereas in v1 they were done with miro.board.widgets.update()

Hope this helps. 
Reach back out if you need further guidance. 

Max

Reply