Merging Job Listings from Multiple Company Entries
Efficiently retrieve job listings associated with specific companies.
Table of contents
In this tutorial, we will explore how to effectively merge job listings from a company that may appear multiple times in the Jobdata API due to different divisions, regional entities, or separate Applicant Tracking Systems (ATS). This is a common scenario for large organizations, such as universities or multinational corporations, where each division may have its own job postings but share the same overarching company identity.
Understanding the Problem
When querying the Jobdata API, you may encounter multiple entries for the same company. For example, Johns Hopkins University may have separate ATS accounts for faculty/teaching positions and administrative jobs. Each of these accounts will return job listings under the same company name but may have different job types and locations.
Key Points to Consider:
- Company Name: Usually consistent across different entries.
- Website and Social Accounts: Often the same, making it easier to match entries.
- No Duplicate Job Listings: Different ATS systems typically do not duplicate job listings, as they cater to different job types.
Steps to Merge Job Listings
- Fetch Company Data: Use the
/api/companies/
endpoint to retrieve all company entries. - Identify Unique Companies: Use the company name, website, or social media links to identify unique companies.
- Fetch Job Listings: For each unique company, fetch job listings using the
/api/jobs/
endpoint. - Merge Listings: Combine job listings from different entries into a single list for each unique company.
Example: Merging Job Listings for Johns Hopkins University
Step 1: Fetch Company Data
You can search for companies by name or domain name using the following queries:
Search by Company Name:
import requests
url = "https://jobdataapi.com/api/companies/"
params = {
"name": "Johns Hopkins University"
}
headers = {
"Authorization": "Api-Key YOUR_API_KEY"
}
response = requests.get(url, headers=headers, params=params)
companies_data = response.json()
print(companies_data)
Search by Domain Name:
url = "https://jobdataapi.com/api/companies/"
params = {
"website": "jhu.edu"
}
response = requests.get(url, headers=headers, params=params)
companies_data = response.json()
print(companies_data)
Step 2: Identify Unique Companies
After fetching the company data, you can loop through the results to identify unique companies based on their name or website.
unique_companies = {}
for company in companies_data['results']:
company_id = company['id'] # Use company ID as the unique identifier
unique_companies[company_id] = company # Store the company using its ID
Step 3: Fetch Job Listings
Now that you have a list of unique companies, you can fetch job listings for each one.
all_jobs = []
for company in unique_companies.values():
company_id = company['id']
jobs_url = f"https://jobdataapi.com/api/jobs/?company_id={company_id}"
response = requests.get(jobs_url, headers=headers)
jobs_data = response.json()
# Append jobs to the all_jobs list
all_jobs.extend(jobs_data['results'])
Step 4: Merge Listings
Since the job listings are already unique (as per the API's design), you can simply return or process the all_jobs
list.
# Print all unique job listings
for job in all_jobs:
print(f"Title: {job['title']}, Location: {job['location']}, Company: {job['company']['name']} (ID: {job['company']['id']})")
Complete Example Code
Here’s the complete code that combines all the steps:
import requests
# Set your API key
API_KEY = "YOUR_API_KEY"
headers = {
"Authorization": f"Api-Key {API_KEY}"
}
# Step 1: Fetch Company Data
def fetch_companies_by_name(name):
url = "https://jobdataapi.com/api/companies/"
params = {"name": name}
response = requests.get(url, headers=headers, params=params)
return response.json()
# Step 2: Identify Unique Companies
def identify_unique_companies(companies_data):
unique_companies = {}
for company in companies_data['results']:
company_id = company['id'] # Use company ID as the unique identifier
unique_companies[company_id] = company # Store the company using its ID
return unique_companies
# Step 3: Fetch Job Listings
def fetch_jobs_for_companies(unique_companies):
all_jobs = []
for company in unique_companies.values():
company_id = company['id']
jobs_url = f"https://jobdataapi.com/api/jobs/?company_id={company_id}"
response = requests.get(jobs_url, headers=headers)
jobs_data = response.json()
all_jobs.extend(jobs_data['results'])
return all_jobs
# Main Execution
if __name__ == "__main__":
company_name = "Johns Hopkins University"
companies_data = fetch_companies_by_name(company_name)
unique_companies = identify_unique_companies(companies_data)
all_jobs = fetch_jobs_for_companies(unique_companies)
# Print all unique job listings
for job in all_jobs:
print(f"Title: {job['title']}, Location: {job['location']}, Company: {job['company']['name']} (ID: {job['company']['id']})")
Searching for Job Listings by Company Name or Website (Domain)
In the following example, we will demonstrate how to search for job listings directly using the /api/jobs/
endpoint by filtering based on either the company_name
or company_website
parameters. This allows you to retrieve job listings that match a specific company name or website, leveraging the internal "like" search functionality of the database.
Step 1: Search by Company Name
You can search for job listings by specifying the company_name
parameter in your request. This will return all job listings associated with companies that have names similar to the one you provide.
Python Code Example: Search by Company Name
import requests
# Set your API key
API_KEY = "YOUR_API_KEY"
headers = {
"Authorization": f"Api-Key {API_KEY}"
}
# Function to search jobs by company name
def search_jobs_by_company_name(company_name):
url = "https://jobdataapi.com/api/jobs/"
params = {
"company_name": company_name # Using company_name parameter
}
response = requests.get(url, headers=headers, params=params)
return response.json()
# Example usage
if __name__ == "__main__":
company_name = "Johns Hopkins University"
jobs_data = search_jobs_by_company_name(company_name)
# Print job listings
for job in jobs_data['results']:
print(f"Title: {job['title']}, Location: {job['location']}, Company: {job['company']['name']}")
Step 2: Search by Company Website
Similarly, you can search for job listings by specifying the company_website
parameter. This will return job listings for companies that have websites matching the provided URL.
Python Code Example: Search by Company Website
# Function to search jobs by company website
def search_jobs_by_company_website(company_website):
url = "https://jobdataapi.com/api/jobs/"
params = {
"company_website": company_website # Using company_website parameter
}
response = requests.get(url, headers=headers, params=params)
return response.json()
# Example usage
if __name__ == "__main__":
company_website = "jhu.edu"
jobs_data = search_jobs_by_company_website(company_website)
# Print job listings
for job in jobs_data['results']:
print(f"Title: {job['title']}, Location: {job['location']}, Company: {job['company']['name']}")
Complete Example Code
Here’s the complete code that combines both search functionalities:
import requests
# Set your API key
API_KEY = "YOUR_API_KEY"
headers = {
"Authorization": f"Api-Key {API_KEY}"
}
# Function to search jobs by company name
def search_jobs_by_company_name(company_name):
url = "https://jobdataapi.com/api/jobs/"
params = {
"company_name": company_name # Using company_name parameter
}
response = requests.get(url, headers=headers, params=params)
return response.json()
# Function to search jobs by company website
def search_jobs_by_company_website(company_website):
url = "https://jobdataapi.com/api/jobs/"
params = {
"company_website": company_website # Using company_website parameter
}
response = requests.get(url, headers=headers, params=params)
return response.json()
# Main Execution
if __name__ == "__main__":
# Search by company name
company_name = "Johns Hopkins University"
jobs_data_name = search_jobs_by_company_name(company_name)
print(f"Job listings for {company_name}:")
for job in jobs_data_name['results']:
print(f"Title: {job['title']}, Location: {job['location']}, Company: {job['company']['name']}")
# Search by company website
company_website = "jhu.edu"
jobs_data_website = search_jobs_by_company_website(company_website)
print(f"\nJob listings for website {company_website}:")
for job in jobs_data_website['results']:
print(f"Title: {job['title']}, Location: {job['location']}, Company: {job['company']['name']}")
This functionality allows you to efficiently retrieve job listings associated with specific companies, making it easier to aggregate and display relevant job opportunities for users.
Conclusion
By following the steps outlined in this tutorial, you can effectively merge job listings from multiple entries of the same company in the Jobdata API. The shown approaches ensure that you maintain a clean and organized dataset, allowing for better job search experiences and insights into hiring trends.