USA JOBS
JobsExploring the USAJOBS API with JavaScript
If you're a developer looking for job openings or managing digital talent acquisition for an organization, the USAJOBS API is a great resource. With the public API, you can access job listings in real-time and embed them on your own website or application.
In this blog post, we'll explore how you can use JavaScript to consume the USAJOBS API. We'll begin with an overview of the API and then move on to a list of examples you can try out on your own.
A brief introduction to the USAJOBS API
The USAJOBS API is a RESTful web service that provides programmatic access to USAJOBS data. It's a publicly available resource that anyone can use to build applications that consume job data. The API user can access Job Listings, Application Data, Saved Search Data, Profile Data, etc.
Getting started with the USAJOBS API
Before you start consuming the API, you'll need to get an API key. You can sign up for an account here, and then apply for an API key. Once you have the key, you can start making requests to the API.
One of the easiest ways to get started with the API is to use the fetch()
method in JavaScript. This method allows you to send HTTP requests and handle the response. Here's an example:
const apiKey = 'YOUR_API_KEY_HERE';
const apiUrl = `https://data.usajobs.gov/api/Search?Keyword=developer&LocationName=Washington,DC&ApiKey=${apiKey}`;
fetch(apiUrl)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
In this example, we're sending a GET request to the API endpoint with two query parameters - Keyword
and LocationName
. We're also including our API key in the request. Once we get the response from the API, we're parsing it as JSON and logging it to the console.
USAJOBS API examples in JavaScript
Now that you know how to make a request to the API, let's look at some examples of what you can do with it.
Example 1 - Search for job openings
const apiKey = 'YOUR_API_KEY_HERE';
const apiUrl = `https://data.usajobs.gov/api/Search?Keyword=developer&LocationName=Washington,DC&ApiKey=${apiKey}`;
fetch(apiUrl)
.then(response => response.json())
.then(data => {
const jobOpenings = data.SearchResult.SearchResultItems;
console.log(jobOpenings);
})
.catch(error => console.error(error));
In this example, we're searching for job openings with the keyword "developer" in Washington, DC. We're logging the search result to the console.
Example 2 - Get details of a specific job opening
const apiKey = 'YOUR_API_KEY_HERE';
const jobId = '123456789'; // Replace with a valid job ID
const apiUrl = `https://data.usajobs.gov/api/JobSearch/Job/${jobId}?ApiKey=${apiKey}`;
fetch(apiUrl)
.then(response => response.json())
.then(data => {
const jobDetails = data.JobData;
console.log(jobDetails);
})
.catch(error => console.error(error));
In this example, we're retrieving the details of a specific job opening with the ID "123456789". We're logging the job details to the console.
Example 3 - Search for job openings with salary above a certain amount
const apiKey = 'YOUR_API_KEY_HERE';
const minSalary = 70000; // Replace with desired salary
const apiUrl = `https://data.usajobs.gov/api/Search?Keyword=developer&LocationName=Washington,DC&MinimumSalary=${minSalary}&ApiKey=${apiKey}`;
fetch(apiUrl)
.then(response => response.json())
.then(data => {
const jobOpenings = data.SearchResult.SearchResultItems;
console.log(jobOpenings);
})
.catch(error => console.error(error));
In this example, we're searching for job openings with the keyword "developer" in Washington, DC with a minimum salary of $70,000. We're logging the search result to the console.
Wrapping up
In this post, we've explored how you can use JavaScript to consume the USAJOBS API. We've covered the basics of the API, how to get started, and provided some examples of what you can do with it. With this knowledge, you can now build your own job search application, or integrate job listings into an existing project or website.