I solved this by downloading the image to the computer and putting the file in this command: docRef_O.place(file)
where docRef_O = app.activeDocument
. I get app by using: const { app } = require('indesign')
.
Like medium_jon said I also needed to remove any selection of frame which I did by running this: app.selection = null