import requests
import json


def get_pvdaq_metadata(system_id, api_key):
    """Query PV system metadata from NREL's PVDAQ data service.

    Parameters
    ----------
    system_id: int
        The system ID corresponding to the site that data should be
        queried from.

    api_key: string
        Your NREL API key (https://developer.nrel.gov/docs/api-key/)

    Returns
    -------
    list of dict
    """

    params = {'system_id': system_id, 'api_key': api_key}
    sites_url = 'https://developer.nrel.gov/api/pvdaq/v3/sites.json'
    r = requests.get(sites_url, params=params)
    r.raise_for_status()
    outputs = json.loads(r.content)['outputs']
    return outputs