Tutorials - Export Archived Jobs

This tutorial will show you how to search USAJOBS for historical records on previously offered job opportunity announcments using the REST based API. A detailed reference on this API endpoint can be found at GET /api/Archive.

Before proceeding with this tutorial you will first need to obtain an API Key if you do not already have one. To request an API Key, please go the the API Request page and fill out an application.

Step 1: Set up a request

To instantiate the Search REST API, we first need to set up the request. Note that all interactions with USAJOBS are via HTTP. The request must include 3 parameters defined in the header which include: Host, User Agent and Authorization Key. The base URL for the Archived Search API is https://data.usajobs.gov/api/archive.

JavaScript
cURL

var request = require('request');  
        
var host = 'data.usajobs.gov';  
var userAgent = 'your@email.address';  
var authKey = 'YourAPIKey';     
request({      
    url: 'https://data.usajobs.gov/api/archive',      
    method: 'GET',      
    headers: {          
        "Host": host,          
        "User-Agent": userAgent,          
        "Authorization-Key": authKey      
    }    
}, function(error, response, body) {      
    var data = JSON.parse(body);  
});

$ curl -H "Host: data.usajobs.gov"    
  -H "User-Agent: $YOUR_EMAIL"    
  -H "Authorization-Key: $AUTH_KEY"    
  https://data.usajobs.gov/api/archive

Step 2: Define query parameters

Now we have the structure of our request built, we need to define query parameters that will be appended to the base URL to drive the specific results desired. The full list of acceptable query parameters for this API endpoint can be found at: GET /api/Archive. For purposes of this tutorial, we will perform a search for jobs posted between January 1st and 31st of 2016 by the Office of Personnel Management, which is defined by Agency Subelement "OM00". A complete list of Agency Subelement codes can be found at: API-Reference/GET-codelist-agencysubelements.

JavaScript
cURL
var request = require('request');          

var host = 'data.usajobs.gov';  
var userAgent = 'your@email.address';  
var authKey = 'YourAPIKey';     

request({      
    url: 'https://data.usajobs.gov/api/archive?PostingStartDate=01/01/2016&PostingEndDate=01/31/2016&Organization=OM00',      
    method: 'GET',     
    headers: {          
        "Host": host,          
        "User-Agent": userAgent,          
        "Authorization-Key": authKey      
    }    
}, function(error, response, body) {      
    var data = JSON.parse(body);  
});
$ curl -H "Host: data.usajobs.gov"    
  -H "User-Agent: $YOUR_EMAIL"    
  -H "Authorization-Key: $AUTH_KEY"    
  https://data.usajobs.gov/api/archive?PostingStartDate=01/01/2016&PostingEndDate=01/31/2016&Organization=OM00

Step 3: Execute Archived Job Search

We have set up the logic to make a request and defined what we are searching for (Search Criteria: Jobs that were posted by agency submelement "OM00", Office of Personnel Management during January of 2016). Now, let's execute the code and view the results.

Search Result (JSON):{
    "LanguageCode": "EN",
    "SearchParameters": { },
    "SearchResult": {
        "SearchResultCount": 24,
        "SearchResultItems": [...]
    }
}

The search REST API returns a JSON object with the following attributes. A more detailed explanation of the response object can be found at: API-Reference/GET-api-Archive.

Name Description Type
LanguageCode Response Langauge String
SearchParameters Query parameters used in search request. Object
SearchResult Object
 SearchResultCount Number of records returned in response object. Integer
 SearchResultItems Array of job opportunity announcement objects that matched search criteria. Array