đŸ‘€ Validate Profile Data with HrFlow.ai SDK

Learn how to validate and manage profile data before sending it to the HrFlow.ai API, reducing errors and ensuring data integrity.

This guide will walk you through how to use these schemas for profile indexing, retrieval, and editing.

A. Why Use Profile Schemas?

Instead of managing profile data by handling JSON objects directly and meticulously following the profile object documentation, you can validate profile objects locally using profile schemas before making API calls. This approach catches errors early, streamlines the process, and reduces delays in identifying mistakes.

Benefits of Using Profile Schemas

  • Early Error Detection: Validate profile data locally to catch errors before making API calls.
  • Enhanced Data Integrity: Ensure that profile objects conform to the expected structure and types.
  • Streamlined Workflow: Simplify the process of managing profile data with robust validation.

B. Step-by-Step Guide

B.1. Initialize the HrFlow Client

📘

Prerequisites

First, initialize the HrFlow client with your API credentials.

from hrflow import Hrflow
from hrflow.schemas import HrFlowProfile, Location

client = Hrflow(api_secret="your_api_secret", api_user="your_api_user")

B.2. Define a Profile Using Profile Schemas

Create a profile object using the provided schemas. This ensures that the profile data adheres to the expected structure and types.

from hrflow.schemas import HrFlowProfile, Location

# Minimal profile with only required fields
profile = HrFlowProfile(
    name="John Doe",
    source_key="YOUR_SOURCE_KEY",
    location=Location(
        text="New York, USA"
    ),
)

B.3. Index a Profile

Use the client.profile.indexing.add_json method to index the profile. The profile schema ensures that the profile data is valid before it is sent to the API.

response = client.profile.indexing.add_json(source_key="YOUR_SOURCE_KEY", profile_json=profile.dict())

print(response)
# Output : {'code': 200, 'message': 'Profile parsing', 'data': {... profile data ...}}

For more details, refer to the Index a Profile documentation.

C. Additional Use Cases

C.1. Retrieve a Profile

To retrieve a profile, use the client.profile.indexing.get method. The profile data returned can be validated against the schema.

response = client.profile.indexing.get(source_key="YOUR_SOURCE_KEY", key="YOUR_PROFILE_KEY")
profile = HrFlowProfile.parse_obj(response["data"])

print(profile)
# Output: HrFlowProfile object with the profile data

For more details, refer to the Get a Profile documentation.

C.2. Edit a Profile

To edit a profile, modify the profile object and use the client.profile.indexing.edit method to update it.

profile.name = "Jane Doe"
response = client.profile.indexing.edit(source_key="YOUR_SOURCE_KEY", key="YOUR_PROFILE_KEY", profile_json=profile.dict())

print(response)
# Output : {'code': 200, 'message': 'Profile edited', 'data': {... profile data ...}}

For more details, refer to the Edit a Profile documentation.

D. Additional Resources