import requests


def getproducts(tileid):
    """ 
    Get a list of the products available for a tile.
    Accepts a 10k tile id or a 5k tile id.
    """

    # use a set so that duplicates are not included in the returned list
    productset = set()

    # in case a 5k tile id has been supplied 
    # get the first four characters for use in the url
    tileid = tileid[:4]

    # URL for JSON file
    jsonurl = f"http://www.geostore.com/environment-agency/rest/product/OS_GB_10KM/{tileid}?catalogName=Survey"

    # get the json catalog listing
    sdirectoryjson = requests.get(jsonurl)
    j = sdirectoryjson.json()

    # loop through json response
    for r in j:
        productset.add(r['pyramid'])

    productlist = list(productset)
    productlist.sort()

    return productlist