Cannot replicate Request Builder output in API

I have managed to create an evalscript that works in both Playground and Request builder, however, when I copy the sh_py text and try to run it using API, this does not produce the same result.

I have checked and my sentinelhub python package is 3.5.2, and the Request Builder states that the code should work for versions greater than 3.4.0.

Can someone please explain why the code cannot be used?

Also, the evalscript evaluation fails with this line :
let AvBefore = (samples[1].VV+samples[2].VV+samples[3].VV+samples[4].VV)/4;

The error I get is:
400 Client Error: Bad Request for url:
Server response: “{“error”:{“status”:400,“reason”:“Bad Request”,“message”:“Failed to evaluate script!\nevalscript.js:39: TypeError: Cannot read property ‘VV’ of undefined\n let AvBefore = (samples[1].VV+samples[2].VV+samples[3].VV+samples[4].VV)/4;\n ^\nTypeError: Cannot read property ‘VV’ of undefined\n at evaluatePixel (evalscript.js:39:29)\n at executeForMultipleScenes (:1153:14)\n”,“code”:“RENDERER_EXCEPTION”}}”

However this works fine in the Request Builder and returns the expected output.

Ideally I want to replicate the code in an API request so that I can pull the requests locally, but I am very confused as to why this isn’t working. Can someone please advise.

Hi Alisdair,

Having looked into your script in more detail, we see that are using the filterScenes function still. This feature is depreciated and we would recommend using the preprocess scenes function instead. This is probably the cause of the errors in different applications.

There are plenty of examples in the linked documentation link but if you are still encountering issues then please let us know in the thread :slight_smile:

Thanks Will.

I re-ran the script with the revised preProcessScenes function, but still encountered the same error as before.

Failed to evaluate script!
evalscript.js:36: TypeError: Cannot read property ‘VV’ of undefined
let Before = (samples[1].VV+samples[2].VV+samples[3].VV+samples[4].VV);
TypeError: Cannot read property ‘VV’ of undefined
at evaluatePixel (evalscript.js:36:27)
at executeForMultipleScenes (:1153:14)

I will now paste my script below.

This is script may only work with sentinelhub.version >= ‘3.4.0’

from sentinelhub import SentinelHubRequest, DataCollection, MimeType, CRS, BBox, SHConfig, Geometry


config = SHConfig()
config.sh_client_id = ‘’
config.sh_client_secret = ‘’
evalscript = “”"

// Selection of polarization
function setup() {
return {
input: [{
bands: [
output: { bands: 1 },
mosaicking: “ORBIT”

function preProcessScenes (collections) {
var allowedDates = [“2022-01-07”, “2022-01-19”, “2022-01-31”, “2022-02-12”, “2022-02-24”];
collections.scenes.orbits = collections.scenes.orbits.filter(function (orbit) {
var orbitDateFrom = orbit.dateFrom.split(“T”)[0];
return allowedDates.includes(orbitDateFrom);
return collections

function dateformat(d){
var dd = d.getDate();
var mm = d.getMonth()+1;
var yyyy = d.getFullYear();
var isodate = yyyy+’-’+mm+’-’+dd;
return isodate;

function evaluatePixel(samples,scenes) {
let Before = (samples[1].VV+samples[2].VV+samples[3].VV+samples[4].VV);
let Post = (samples[0].VV)*4
let dNBR = (Before - Post)
return [dNBR]

bbox = BBox(bbox=[ -121.835721, 50.858266, -121.535212, 50.972553], crs=CRS.WGS84)

request = SentinelHubRequest(
time_interval=(‘2022-01-07’, ‘2022-02-24’),
other_args={“processing”: {“speckleFilter”: {“type”: “LEE”,“windowSizeX”: 5,“windowSizeY”: 5},“orthorectify”: true,“demInstance”: “COPERNICUS”}}
SentinelHubRequest.output_response(‘default’, MimeType.TIFF),
size=[1594.217662666533, 694.2328723833024],

response = request.get_data()

Hi @alisdair.cunningham ,

I investigated a bit and I found that there is no Sentinel-1 data for your area of interest within the time period you set. I also checked with scihub and they don’t have data either, meaning that this is not a missing data issue in our system. The potential reason for this could be the anomaly of Sentinel-1B starting from the beginning of this year that leads to a reduced coverage of Sentinel-1.

Best Regards

Hi, thanks for responding Chung.
I should point out that yes, the bounding box is incorrect, I copied the wrong text which had an old AOI. The AOI I was originally using was in England, UK.
For more context, the method should, and did work.
I initially created the method in Sentinel Playground, where I was able to visualise my result on the map. It worked as expected everywhere on the globe for the date selected in the Playground.
I then transferred the method over to the Request Builder to see if I could develop the API code to pull down the result via API commands.
Annoyingly, I got this to work too, though it did require a bit of tweaking. I know it was working because I was able to submit the request, and the data could be viewer in the map window, and when I downloaded the request, it was as expected.
I then tried to run the code via API commands using the script created in the request builder. This failed with the errors mentioned in the posts above. So I went back to Request Builder and tried to recreate the original working method and now cannot do this either.

Can someone please help me understand how:

  1. I capture a set of dates, and use these multiple dates in a function to create a single output
  2. How the above script (please ignore the bbox - use a different one) isn’t working when it did once work?

Ultimately I am trying to do multi-date analysis, and am struggling to write the code to achieve this. The custom scripts help to come extent, but mostly with 2 dates, rarely more. I used bits from a couple of customer scripts to create my script, and as I said, it worked both in the Playground and in the Request Builder, but now I cannot get it to work in the Request Builder, and in the API. I would really appreciate help as I cannot proceed to use SentinelHub for this application if I cannot resolve this issue.

Feel free to use this bounding box instead: [ -2.441919,51.758684,-2.339074,51.794282]

Hi Alisdair,

The error of the script above indicates the api cannot read VV band. It is because there’s no data in your old bounding box, so there’s no VV band either (the object is empty). This should answer your second question.

I will investigate with the new bounding box and get back to you asap.

Best Regards

Many thanks. Thankfully I went back to the Request Builder and got it working. I was not calling a range of imagery at the beginning. Only filtering my selection to pre-defined dates, but due to their being no dates on the input, this did not work. I have now got the method working in both Request Builder and via the API download.
Thank you for the support, knowing it was the empty date list helped me solve the problem.

Glad to hear that!

Another little reminder is that DataCollection.SENTINEL1_IW_ASC which is specified in your request is asking the api to look for Sentinel-1 IW data with ascending orbit, which is only available on 2022-01-10, 2022-01-22, 2022-02-03, and 2022-02-15 during the time period. None of them is in your allowedDates list, which leads to the same issue: the api is trying to access the empty object.

Best Regards

1 Like

Thank you.

I am happy to call this one ‘Resolved’
Many thanks :slight_smile: