Assuming you have the product identifier (22e2fbfe-0aa7-423d-b0b5-df46527f03f5
) you can construct the query you want with a little parsing of the scihub odata response.
The constructed img_url
can then be downloaded with the tool/library of your choice.
import requests
from six.moves.urllib.parse import urljoin
# connect to the api
api_session = requests.Session()
api_session.auth = ("username", "password")
api_url = "https://scihub.copernicus.eu/apihub/odata/v1/"
# product UUID you want to download a single band for
prod_id = "22e2fbfe-0aa7-423d-b0b5-df46527f03f5"
# parse the product name
nodes = api_session.get(urljoin(api_url, "Products('%s')/Nodes?$format=json" % prod_id)).json()
prod_name = nodes["d"]["results"][0]["Id"]
# parse the granule id
granules = api_session.get(urljoin(api_url, "Products('%s')/Nodes('%s')/Nodes('GRANULE')/Nodes?$format=json" % (prod_id, prod_name))).json()
granules["d"]["results"][0].keys()
gran_id = granules["d"]["results"][0]["Id"]
# parse the band names
bands = api_session.get(urljoin(api_url, "Products('%s')/Nodes('%s')/Nodes('GRANULE')/Nodes('%s')/Nodes('IMG_DATA')/Nodes?$format=json" % (prod_id, prod_name, gran_id))).json()
band_id = bands["d"]["results"][3]["Id"] # element 3 is band 4, element 0 band 1
# construct the final image url
img_url = urljoin(api_url, "Products('%s')/Nodes('%s')/Nodes('GRANULE')/Nodes('%s')/Nodes('IMG_DATA')/Nodes('%s')/$value" % (prod_id, prod_name, gran_id, band_id))
22e2fbfe-0aa7-423d-b0b5-df46527f03f5
orS2A_MSIL1C_20170316T112101_N0204_R037_T29SNC_20170316T112658.SAFE
? The first is the 'Unique Universal Identifier (UUID)', the second is referred to as 'Product Name' by ESA.