Photoshop Imaging API - putSelection - Response "Error: Invalid image"

I am trying to read in the image data from my current selection, do some modifications and the rewrite the image data to my current selection. My problem is that even though the input data is the same length as the data i want to write with putSelection, I get the response “Error: Invalid image”.

let testapp = require(‘photoshop’).app;
let em = require(‘photoshop’).core.executeAsModal;
let imaging = require(‘photoshop’).imaging;
em (
async () => {
let layerBounds = layers[0].boundsNoEffects;
let imageData = await imaging.getPixels({
layerID: layers[0].id,
sourceBounds: {
left: layerBounds.left,
right: layerBounds.right,
top: layerBounds.top,
bottom: layerBounds.bottom,
}
});
let pixels = await imageData.imageData.getData();
let selection = await imaging.getSelection({});
let selectionData = await selection.imageData.getData();
let test = await imaging.putSelection({imageData: selectionData});
},{“commandName”:“Test”})

My output from the console:
Promise {}[[Prototype]]: Promise[[PromiseState]]: “rejected”[[PromiseResult]]: “Error: Invalid image”