Evalscript to get an RGB image?

Hi,

I want to get an RGB image for my co-ordinates using the API, I use the following evalscript for that:

minVal = 0.0;
let maxVal = 0.4;
let viz = new HighlightCompressVisualizer(minVal, maxVal);
function evaluatePixel(samples) {
let val = [samples[0].B04, samples[0].B03, samples[0].B02];
return viz.processList(val);
}

function setup(ds) {
setInputComponents([ds.B02, ds.B03, ds.B04]);
setOutputComponentCount(3);
}

Which gives me following error:

{"error":{"status":400,"reason":"Bad Request","message":"Script failed to return.","code":"RENDERER_EXCEPTION"}}

I have made sure everything else is fine. I think there’s something wrong with the evalscript.

This script looks good to me and if I go to Sentinel Playground, click Custom and then Advance (yellow switch) and input this code, it works just fine.

How are you trying to do it?

Are you trying to use process API or OGC API? If the former, note that you need to use Version 3 scripts.
Some examples here:
https://docs.sentinel-hub.com/api/latest/#/data/Examples_for_S2L1C

I’m using process API, l just added //VERSION=3 at the top and the error seems pretty much explainable now.

{"error":{"status":400,"reason":"Bad Request","message":"Failed to evaluate script!\\nevalscript.js:13: ReferenceError: setInputComponents is not defined\\n setInputComponents([ds.B02, ds.B03, ds.B04]); \\n ^\\nReferenceError: setInputComponents is not defined\\n at setup (evalscript.js:13:5)\\n","code":"RENDERER_EXCEPTION"}}

I think I can figure out from here.

I see. Yeah, version=3 has a bit different syntax as we have evolved it due to additional features.