💼 Validate Job Data with HrFlow.ai SDK
Learn how to validate and manage job 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 job indexing, retrieval, and editing.
A. Why Use Job Schemas?
Instead of managing job data by handling JSON objects directly and meticulously following the job object documentation to avoid errors, you can validate job objects locally using job schemas before making API calls. This approach catches errors early, streamlines the process, and reduces delays in identifying mistakes.
Benefits of Using Job Schemas
- Early Error Detection: Validate job data locally to catch errors before making API calls.
- Enhanced Data Integrity: Ensure that job objects conform to the expected structure and types.
- Streamlined Workflow: Simplify the process of managing job data with robust validation.
B. Step-by-Step Guide
B.1. Initialize the HrFlow Client
Prerequisites
- ✨ Create a Workspace
- 🔑 Get your API Key
- HrFlow.ai Python SDK version 4.0.0 or above: Install it via pip with
pip install -U hrflow>=4.0.0
or conda withconda install hrflow>=4.0.0 -c conda-forge
.
First, initialize the HrFlow client with your API credentials.
from hrflow import Hrflow
from hrflow.schemas import HrFlowJob, Location
client = Hrflow(api_secret="your_api_secret", api_user="your_api_user")
B.2. Define a Job Using Job Schemas
Create a job object using the provided schemas. This ensures that the job data adheres to the expected structure and types.
from hrflow.schemas import HrFlowJob, Location
# Minimal job with only required fields
job = HrFlowJob(
name="Data Scientist",
board_key="YOUR_BOARD_KEY",
location=Location(
text="Paris, France"
),
)
B.3. Index a Job
Use the client.job.storing.add_json
method to index the job. The job schema ensures that the job data is valid before it is sent to the API.
response = client.job.storing.add_json(board_key="YOUR_BOARD_KEY", job_json=job.dict())
print(response)
# Output : {'code': 201, 'message': 'Job created', 'data': {... job data ...}}
For more details, refer to the Index a Job documentation.
C. Additional Use Cases
C.1. Retrieve a Job
To retrieve a job, use the client.job.indexing.get
method. The job data returned can be validated against the schema.
response = client.job.indexing.get(board_key="YOUR_BOARD_KEY", key="YOUR_JOB_KEY")
job = HrFlowJob.parse_obj(response["data"])
print(job)
# Output: HrFlowJob object with the job data
For more details, refer to the Get a Job documentation.
C.2. Edit a Job
To edit a job, modify the job object and use the client.job.indexing.edit
method to update it.
job.name = "Senior Data Scientist"
response = client.job.indexing.edit(board_key="YOUR_BOARD_KEY", key="YOUR_JOB_KEY", job_json=job.dict())
print(response)
# Output : {'code': 200, 'message': 'Job edited', 'data': {... job data ...}}
For more details, refer to the Edit a Job documentation.
D. Additional Resources
- HrFlow.ai Python SDK on PyPI
- HrFlow Cookbook: Repository containing helpful notebooks by the HrFlow.ai team
- Job Object Documentation
- API Authentication Documentation
- Index a Job documentation
- Get a Job documentation
- Edit a Job documentation
Updated 2 months ago