Skip to main content
Image for post: Indeed API for your job search and ads

Indeed API for your job search and ads

Enpoints and PHP class

Using the Indeed API for your job search and ads is easy and you can obtain informations from all countries. The localization is a little bit difficult step because Indeed has a different domain for their websites in every nation. I have built a simple API caller to make a simple query simply by keyword, place \ region (optional) and Country.
Here is my PHP class:


/**
* Indeed API process request
*/
class Indeed
{
   const DEFAULT_FORMAT = 'json';
   const API_SEARCH_ENDPOINT = 'http://api.indeed.com/ads/apisearch';
   const API_JOBS_ENDPOINT = 'http://api.indeed.com/ads/apigetjobs';

   /**
    * @var array
    */
   private static $API_SEARCH_REQUIRED = ['userip', 'useragent', ['q', 'l']];

   /**
    * @var array
    */
   private static $API_JOBS_REQUIRED = ['jobkeys'];

   /**
    * Initialize publisher and version
    *
    * @param string $publisher
    * @param string $version
    */
   public function __construct($publisher, $version = "2")
   {
       $this->publisher = $publisher;
       $this->version = $version;
   }

   /**
    * Search jobs by argument
    *
    * @param mixed $args
    * @return mixed
    */
   public function search($args)
   {
       return $this->_processRequest(
           self::API_SEARCH_ENDPOINT,
           $this->_validateArgs(self::$API_SEARCH_REQUIRED, $args)
       );
   }

   /**
    * Validate args, process request
    *
    * @param mixed $args
    * @return mixed
    */
   public function jobs($args)
   {
       $valid_args = $this->_validateArgs(self::$API_JOBS_REQUIRED, $args);
       $valid_args['jobkeys'] = implode(",", $valid_args['jobkeys']);

       return $this->_processRequest(self::API_JOBS_ENDPOINT, $valid_args);
   }

   /**
    * Process request and CURL call
    *
    * @param $endpoint
    * @param $args
    * @return mixed
    */
   private function _processRequest($endpoint, $args)
   {
       $format = (array_key_exists('format', $args) ? $args['format'] : self::DEFAULT_FORMAT);
       $raw = ($format == 'xml' ? true : (array_key_exists('raw', $args) ? $args['raw'] : false));

       $args['publisher'] = $this->publisher;
       $args['v'] = $this->version;
       $args['format'] = $format;

       $c = curl_init(sprintf("%s?%s", $endpoint, http_build_query($args)));

       curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE);

       $result = curl_exec($c);

       curl_close($c);

       return  (!$raw) ? json_decode($result, $assoc = true) : $result;
   }

   /**
    * Validate args
    *
    * @param $required_fields
    * @param $args
    * @return mixed
    * @throws \Exception
    */
   private function _validateArgs($required_fields, $args)
   {
       foreach($required_fields as $field) {

           if(is_array($field)) {
               $has_one_required = false;
               foreach($field as $f){
                   if(array_key_exists($f, $args)){
                       $has_one_required = True;
                       break;
                   }
               }

               if(!$has_one_required){
                   throw new \Exception(sprintf("You must provide one of the following %s", implode(",", $field)));
               }

           } elseif(!array_key_exists($field, $args)) {
               throw new\ Exception("The field $field is required");
           }
       }

       return $args;
   }
}

You can see the two endpoints: http://api.indeed.com/ads/apisearch and http://api.indeed.com/ads/apigetjobs.
Here is how you can use the class:


$client = new Indeed($indeed_api_key);
$result = $client->search([
   'q'         => 'PHP', // job skill \ keywords search
   'l'         => 'London', // City \ place (optional)
   'co'        => 'gb', // Country abbreviation
   'start'     => 0, // starting pagination record
   'userip'    => '1.2.3.4',
   'useragent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2)'
]);
echo '<pre>'.print_r($result, 1).'</pre>';

Here is the Countries abbreviations array list in a PHP array:


$countries = [
   'Europe' => [
       'at' => 'Austria',
       'be' => 'Belgium',
       'cz' => 'Czech Republic',
       'dk' => 'Denmark',
       'fi' => 'Finland',
       'fr' => 'France',
       'de' => 'Germany',
       'gr' => 'Greece',
       'hu' => 'Hungary',
       'ie' => 'Ireland',
       'il' => 'Israel',
       'it' => 'Italy',
       'lu' => 'Luxembourg',
       'nl' => 'Netherlands',
       'no' => 'Norway',
       'pl' => 'Poland',
       'pt' => 'Portugal',
       'ro' => 'Romania',
       'ru' => 'Russia',
       'es' => 'Spain',
       'se' => 'Sweden',
       'ch' => 'Switzerland',
       'tr' => 'Turkey',
       'ua' => 'Ukraine',
       'gb' => 'United Kingdom',
    ],
   'North America' => [
       'ca' => 'Canada',
       'us' => 'United States',
       'mx' => 'Mexico',
   ],
   'Central America' => [
       'cr' => 'Costa Rica',
       'ec' => 'Ecuador',
   ],
   'South America' => [
       'ar' => 'Argentina',
       'br' => 'Brazil',
       'cl' => 'Chile',
       'co' => 'Colombia',
       'pa' => 'Panama',
       'pe' => 'Peru',
       'uy' => 'Uruguay',
       've' => 'Venezuela',
   ],
   'Asia' => [
       'bh' => 'Bahrain',
       'cn' => 'China',
       'ph' => 'Philippines',
       'hk' => 'Hong Kong',
       'in' => 'India',
       'id' => 'Indonesia',
       'jp' => 'Japan',
       'kw' => 'Kuwait',
       'my' => 'Malaysia',
       'om' => 'Oman',
       'pk' => 'Pakistan',
       'qa' => 'Qatar',
       'sa' => 'Saudi Arabia',
       'sg' => 'Singapore',
       'kr' => 'South Korea',
       'tw' => 'Taiwan',
       'th' => 'Thailand',
       'ae' => 'United Arab Emirates',
       'vn' => 'Vietnam',
   ],
   'Africa' => [
       'eg' => 'Egypt',
       'ma' => 'Morocco',
       'ng' => 'Nigeria',
       'za' => 'South Africa',
   ],
   'Oceania' => [
       'au' => 'Australia',
       'nz' => 'New Zealand',
   ],
   // 'aq' => 'Antarctica', ?
];

Share this post

This website and/or any sub domains use cookies to understand how you to improve your experience.