Quickstart - Autocomplete API

A fast hands-on introduction to the Autocomplete API

Simple Example

Let's say that you are interested in getting all schools that begin with "harv." The Autocomplete API is the perfect tool for doing this, as it allows you to find multiple schools using a small set of input characteristics.

The list of supported inputs includes the field that you're seeking and the text that you want to complete. In this example, we'll use the following parameters:

Input Parameters

Parameter NameParameter Value
fieldschool
textharv
size10
titlecaseTrue
prettyTrue

Using this information, you can now query the Autocomplete API to find schools beginning with "harv":

import json

# See https://github.com/peopledatalabs/peopledatalabs-python
from peopledatalabs import PDLPY

# Create a client, specifying your API key
CLIENT = PDLPY(
    api_key="YOUR API KEY",
)

# Create a parameters JSON object
PARAMS = {
    "field": "school",
    "text": "harv",
    "size": 10,
    "titlecase": 10,
    "pretty": True
}

# Pass the parameters object to the Autocomplete API
json_response = CLIENT.autocomplete(**PARAMS).json()

# Print the API response in JSON format
print(json_response)
curl -X GET -G \
  'https://api.peopledatalabs.com/v5/autocomplete'\
  -H 'X-Api-Key: xxxx' \
  --data-urlencode 'field=school'\
  --data-urlencode 'text=harv'\
  --data-urlencode 'titlecase=true'\
  --data-urlencode 'size=10'
// See https://github.com/peopledatalabs/peopledatalabs-js
import PDLJS from 'peopledatalabs';

// Create a client, specifying your API key
const PDLJSClient = new PDLJS({ apiKey: "YOUR API KEY" });

// Create a parameters JSON object
const params = {
    "field": "school",
    "text": "harv",
    "size": 10,
    "titlecase"; true,
    "pretty": true
}

// Pass the parameters object to the Autocomplete API
PDLJSClient.autocomplete(params).then((data) => {
    // Print the API response in JSON format
    console.log(data);
}).catch((error) => {
    console.log(error);
});
# See https://github.com/peopledatalabs/peopledatalabs-ruby
require 'peopledatalabs'

# Set your API key
Peopledatalabs.api_key = 'YOUR API KEY'

# Pass parameters to the Autocomplete API
json_response = Peopledatalabs::Autocomplete.retrieve(field: "school", text: "harv", size: 10, titlecase: true, pretty: true)

# Print the API response in JSON format
puts JSON.dump(json_response)
package main

import (
    "fmt"
    "encoding/json"
    "context"
)

// See https://github.com/peopledatalabs/peopledatalabs-go
import (
    pdl "github.com/peopledatalabs/peopledatalabs-go"
    pdlmodel "github.com/peopledatalabs/peopledatalabs-go/model"
)

func main() {
    // Set your API key
    apiKey := "YOUR API KEY"
    // Set API key as environmental variable
    // apiKey := os.Getenv("API_KEY")

    // Create a client, specifying your API key
    client := pdl.New(apiKey)
    
    // Create a parameters JSON object
    params := pdlmodel.AutocompleteParams {
        BaseParams: pdlmodel.BaseParams {
            Size: 10,
            Titlecase: true
            Pretty: true,
        },
        AutocompleteBaseParams: pdlmodel.AutocompleteBaseParams {
            Field: "school",
            Text: "harv",
        },
      
        AdditionalParams: pdlmodel.AdditionalParams {
            TitleCase: true,
        },
    }
    
    // Pass the parameters object to the Autocomplete API
    response, err := client.Autocomplete(context.Background(), params)
    // Check for successful response
    if err == nil {
        // Convert the API response to JSON
        jsonResponse, jsonErr := json.Marshal(response)
        // Print the API response
        if (jsonErr == nil) {
            fmt.Println(string(jsonResponse))
        }
    }
}
import requests, json

# Set your API key
API_KEY = "YOUR API KEY"

# Set the Autocomplete API URL
PDL_URL = "https://api.peopledatalabs.com/v5/autocomplete"

# Create a parameters JSON object
PARAMS = {
    "api_key": API_KEY,
    "field": "school",
    "text": "harv",
    "size": 10,
  	"titlecase": True,
    "pretty": True
}

# Pass the parameters object to the Autocomplete API
json_response = requests.get(PDL_URL, params=PARAMS).json()

# Print the API response in JSON format
print(json_response)

The response that the API returns is as follows:

{
  "data": [
    {
      "name": "Harvard University",
      "count": 1927529,
      "meta": {
        "id": "3533/1_nmK6OO9uG-7wiyTDSIrDiA_0",
        "website": "harvard.edu",
        "location_name": "Cambridge, Massachusetts, United States"
      }
    },
    ...
  ],
    "fields": [
    "education.school.name"
  ],
  "status": 200
}

You can see the full response here:

Full Response (click to toggle):
{
  "data": [
    {
      "name": "Harvard University",
      "count": 1927529,
      "meta": {
        "id": "3533/1_nmK6OO9uG-7wiyTDSIrDiA_0",
        "website": "harvard.edu",
        "location_name": "Cambridge, Massachusetts, United States"
      }
    },
    {
      "name": "Harvard Business School",
      "count": 220817,
      "meta": {
        "id": "3533/1_qBjTBJNpBK2gzteZ59vd8A_0",
        "website": "hbs.edu",
        "location_name": "Boston, Massachusetts, United States"
      }
    },
    {
      "name": "Harvard - Westlake School",
      "count": 124263,
      "meta": {
        "id": "3533/1_NH1qPhIlKjFKZ1nf2Qgt3g_0",
        "website": "hw.com",
        "location_name": "Studio City, California, United States"
      }
    },
    {
      "name": "Harvard Law School",
      "count": 96958,
      "meta": {
        "id": "3533/1_teCnNBZuJ7ec9lfQzEOvyg_0",
        "website": "hls.harvard.edu",
        "location_name": "Cambridge, Massachusetts, United States"
      }
    },
    {
      "name": "Harvard Business School Online",
      "count": 70877,
      "meta": {
        "id": "3533/1_UB212jNfQFFVng4KfGkYlQ_0",
        "website": "online.hbs.edu",
        "location_name": "Boston, Massachusetts, United States"
      }
    },
    {
      "name": "Harvard Medical School",
      "count": 61403,
      "meta": {
        "id": "3533/1_YNnwi4r2jhgVlAvd7O400Q_0",
        "website": "hms.harvard.edu",
        "location_name": "Boston, Massachusetts, United States"
      }
    },
    {
      "name": "Harvard Extension School",
      "count": 38259,
      "meta": {
        "id": "3861/1_hJfk3w2iEDrBWBdwlSOyzg_0"
      }
    },
    {
      "name": "Harvard Graduate School of Education",
      "count": 31485,
      "meta": {
        "id": "3533/1_R-t9DblDP5zWHDnIlJjY9g_0",
        "website": "gse.harvard.edu",
        "location_name": "Cambridge, Massachusetts, United States"
      }
    },
    {
      "name": "Harvard Kennedy School",
      "count": 30697,
      "meta": {
        "id": "3533/1_nTJjAd36aI1cfDBojvtlHA_0",
        "website": "hks.harvard.edu",
        "location_name": "Cambridge, Massachusetts, United States"
      }
    },
    {
      "name": "Harvard Business School Executive Education",
      "count": 27768,
      "meta": {
        "id": "3533/1_HTv2bAJvLvwEEeG0ai63BQ_0",
        "website": "hbs.me",
        "location_name": "Boston, Massachusetts, United States"
      }
    }
  ],
  "fields": [
    "education.school.name"
  ],
  "status": 200
}