def create_payload_for_request(template_data, user_input_dict, existing_data=None):
    """
    This function creates the payload using the user provided input based on the respective template data
    and the existing data

    template_data
        dict which contains the data required for the resource(security rule, Nat rule, Network etc..)

    user_input_dict
        user provided data required for the resource(security rule, Nat rule, Network etc..)

    existing_data
        existing data for the resource(security rule, Nat rule, Network etc..)

    """
    template_data = template_data.copy()
    if existing_data:
        template_data.update(
            (k, existing_data[k]) for k in template_data.keys() & existing_data.keys()
        )

    template_data.update(user_input_dict)
    return template_data