Download Collection Image in a Zip Format Issue

Hi, I am aimed to download all existing image in a collection with zip archive for planet scope images but the code returns invalid collection type.

error message: Failed to download data: 400
{“error”:{“status”:400,“reason”:“Bad Request”,“message”:“Invalid collection type. If using your own data collection, make sure to use the appropriate prefix.”,“code”:“COMMON_BAD_PAYLOAD”,“errors”:{“parameter”:“input->data[0]”,“invalidValue”:“35ab730f-0665-4dd4-b7ea-61c5fc401d19”}}}

CLIENT_ID = '***'
CLIENT_SECRET = '****'

token_url = 'https://services.sentinel-hub.com/oauth/token'

token_headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
}

token_payload = {
    'grant_type': 'client_credentials',
    'client_id': CLIENT_ID,
    'client_secret': CLIENT_SECRET
}

token_response = requests.post(token_url, headers=token_headers, data=token_payload)

if token_response.status_code == 200:
    access_token = token_response.json().get('access_token')
else:
    print(f"Failed to obtain access token: {token_response.status_code}")
    print(token_response.text)
    exit()

endpoint = 'https://services.sentinel-hub.com/api/v1/process'

headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {access_token}'
}

request_payload = {
    "input": {
        "bounds": {
            "bbox": [25.589692580730407, 60.42069787553206, 25.59204076791153, 60.42221714395521]
        },
        "data": [
            {
                "type": "35ab730f-0665-4dd4-b7ea-61c5fc401d19",  # Replace with the correct collection ID for PlanetScope data
                "dataFilter": {
                    "timeRange": {
                        "from": "2023-07-01T00:00:00Z",
                        "to": "2023-06-01T23:59:59Z"
                    }
                }
            }
        ]
    },
    "output": {
        "responses": [
            {
                "identifier": "default",
                "format": {
                    "type": "application/zip"
                }
            }
        ]
    }
}

response = requests.post(endpoint, headers=headers, data=json.dumps(request_payload))

if response.status_code == 200:
    with zipfile.ZipFile(io.BytesIO(response.content)) as z:
        z.extractall()
        print("Files downloaded and extracted successfully.")
else:
    print(f"Failed to download data: {response.status_code}")
    print(response.text)

When specifying your collection ID for PlanetScope data, make sure you declare it as a BYOC collection (see documentation here):

 "data": [
            {
                "type": "byoc-8c3ff934-5cf2-253b-f54c-5bgb044f7dbe",  # Replace with the correct collection ID for PlanetScope data
                "dataFilter": {...

I did but still the same error returns:

Failed to download data: 400
{“error”:{“status”:400,“reason”:“Bad Request”,“message”:“Invalid type”,“code”:“COMMON_BAD_PAYLOAD”,“errors”:{“parameter”:“output->responses[0]->format”,“invalidValue”:“application/zip”,“description”:“Format object.”,“possibleValues”:[“image/jpeg”,“image/png”,“image/tiff”,“application/json”,“zarr/array”,“sentinel/full”]}}}

request_payload = {
    "input": {
        "bounds": {
            "bbox": [25.589692580730407, 60.42069787553206, 25.59204076791153, 60.42221714395521]
        },
        "data": [
            {
                "type": "byoc-e40b4a3f-c192-43e7-85af-466e265dd6ed",  # Replace with the correct collection ID for PlanetScope data
                "dataFilter": {
                    "timeRange": {
                        "from": "2023-05-01T00:00:00Z",
                        "to": "2023-06-01T23:59:59Z"
                    }
                }
            }
        ]
    },
    "output": {
        "responses": [
            {
                "identifier": "default",
                "format": {
                    "type": "application/zip"
                }
            }
        ]
    }
}

The error you are getting is different:

The system is telling you, that you cannot directly return zip format: we only support jpeg, png, tiff, json, or zarr.

Either you can return the data in one of the above formats and zip them in a second step, or use the direct download functions as specified in the documentation here: Third Party Data Import API .

Thanks for the follow up. However, still returning error:

Failed to download data: 400
{“error”:{“status”:400,“reason”:“Bad Request”,“message”:“Failed to evaluate script!”,“code”:“RENDERER_EXCEPTION”}}

CLIENT_ID = '*****'
CLIENT_SECRET = '****'

token_url = 'https://services.sentinel-hub.com/oauth/token'

token_headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
}

token_payload = {
    'grant_type': 'client_credentials',
    'client_id': CLIENT_ID,
    'client_secret': CLIENT_SECRET
}

token_response = requests.post(token_url, headers=token_headers, data=token_payload)

if token_response.status_code == 200:
    access_token = token_response.json().get('access_token')
else:
    print(f"Failed to obtain access token: {token_response.status_code}")
    print(token_response.text)
    exit()

endpoint = 'https://services.sentinel-hub.com/api/v1/process'

headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {access_token}'
}

request_payload = {
    "input": {
        "bounds": {
            "bbox": [25.56305967671497, 60.409526419013076, 25.60894293008795, 60.425499185581174] # bbox = [min_x, min_y, max_x, max_y]
        },
        "data": [
            {
                "type": "byoc-2133a622-943b-432c-95b4-71770c04198d",  # Replace with the correct collection ID for PlanetScope data, alternative 97e518d3-1ee0-441e-9e6d-bf251c72c91d
                "dataFilter": {
                    "timeRange": {
                        "from": "2024-05-01T00:00:00Z",
                        "to": "2024-06-01T23:59:59Z"
                    }
                }
            }
        ]
    },
    "output": {
        "responses": [
            {
                "identifier": "default",
                "format": {
                    "type": "image/tiff"
                }
            }
        ]
    }
}

response = requests.post(endpoint, headers=headers, data=json.dumps(request_payload))


if response.status_code == 200:
        print("Files downloaded and extracted successfully.")
else:
    print(f"Failed to download data: {response.status_code}")
    print(response.text)

Hi,

as the error message states, it cannot evaluate the evalscript. I can’t see it in your code block so can you please share that here so we can help debug it.

Here is my code:


CLIENT_ID = '*****'
CLIENT_SECRET = '****'

token_url = 'https://services.sentinel-hub.com/oauth/token'

token_headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
}

token_payload = {
    'grant_type': 'client_credentials',
    'client_id': CLIENT_ID,
    'client_secret': CLIENT_SECRET
}

token_response = requests.post(token_url, headers=token_headers, data=token_payload)

if token_response.status_code == 200:
    access_token = token_response.json().get('access_token')
else:
    print(f"Failed to obtain access token: {token_response.status_code}")
    print(token_response.text)
    exit()

endpoint = 'https://services.sentinel-hub.com/api/v1/process'

headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {access_token}'
}

request_payload = {
    "input": {
        "bounds": {
            "bbox": [25.56305967671497, 60.409526419013076, 25.60894293008795, 60.425499185581174] # bbox = [min_x, min_y, max_x, max_y]
        },
        "data": [
            {
                "type": "byoc-2133a622-943b-432c-95b4-71770c04198d",  # Replace with the correct collection ID for PlanetScope data, alternative 97e518d3-1ee0-441e-9e6d-bf251c72c91d
                "dataFilter": {
                    "timeRange": {
                        "from": "2024-05-01T00:00:00Z",
                        "to": "2024-06-01T23:59:59Z"
                    }
                }
            }
        ]
    },
    "output": {
        "responses": [
            {
                "identifier": "default",
                "format": {
                    "type": "image/tiff"
                }
            }
        ]
    }
}

response = requests.post(endpoint, headers=headers, data=json.dumps(request_payload))


if response.status_code == 200:
        print("Files downloaded and extracted successfully.")
else:
    print(f"Failed to download data: {response.status_code}")
    print(response.text)

There is no Evalscript in your request so it will not work. In this script you need to define your inputs, processing and outputs.

You can find some examples for this with Planetscope data here.

1 Like

Thanks for your helpful tips.