def get_file_id(service, file_name, mime_type=None, parent_id=None):
    """Return the ID of a Google Drive file

    :param service: A Google Drive API service object
    :param file_name: A string, the name of the file
    :param mime_type: A string, optional MIME type of file to search for
    :param parent_id: A string, optional id of a parent folder to search in

    :return file_id: A string, file ID of the first found result
    """

    file_id = None

    query = """name='{}'
               and trashed=False
               """.format(file_name)

    if parent_id:
        query += "and parents in '{}'".format(parent_id)

    if mime_type:
        query += "and mimeType in '{}'".format(mime_type)

    try:
        results = service.files().list(
            q=query,
            fields='files(name, id)').execute()

        if len(results['files']) > 1:
            print('Multiple files found, retrieving first from list')

        file_id = results['files'][0]['id']

    except Exception as e:
        print('An error occurred: {}'.format(e))

    return file_id