def build_filter_query(form):
    """ Creates the odata query string used in the API request. """
    filtered_query = ""
    if ('Category' in form and form['Category'] != "All"):
        filtered_query += 'category eq ' if (len(filtered_query) == 0) else ' and category eq '
        filtered_query += "'{}'".format(form['Category'])
    if ('Provider' in form and form['Provider'] != "All"):
        filtered_query += 'vendorInformation/provider eq ' if (len(filtered_query) == 0) else ' and vendorInformation/provider eq '
        filtered_query += "'{}'".format(form['Provider'])
    if ('Status' in form and form['Status'] != "All"):
        filtered_query += 'Status eq ' if (len(filtered_query) == 0) else ' and Status eq '
        filtered_query += "'{}'".format(form['Status'])
    if ('Severity' in form and form['Severity'] != "All"):
        filtered_query += 'Severity eq ' if (len(filtered_query) == 0) else ' and Severity eq '
        filtered_query += "'{}'".format(form['Severity'])
    if ('HostFqdn' in form and form['HostFqdn'] != ""):
        filtered_query += "hostStates/any(a:a/fqdn eq " if (len(filtered_query) == 0) else ' and hostStates/any(a:a/fqdn eq '
        filtered_query += "'{}')".format(form['HostFqdn'])
    if ('Upn' in form and form['Upn'] != ""):
        filtered_query += 'userStates/any(a:a/userPrincipalName eq ' if (len(filtered_query) == 0) else ' and userStates/any(a:a/userPrincipalName eq '
        filtered_query += "'{}')".format(form['Upn'])
    return filtered_query