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 "stanf." 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
Using this information, you can now query the Autocomplete API to find schools beginning with "stanf":
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": "stanf",
"size": 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=stanf'\
--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": "stanf",
"size": 10,
"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: "stanf", size: 10, 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,
Pretty: true,
},
AutocompleteBaseParams: pdlmodel.AutocompleteBaseParams {
Field: "school",
Text: "stanf",
},
}
// 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": "stanf",
"size": 10,
"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": "stanford university",
"count": 434677,
"meta": {
"website": "stanford.edu",
"location_name": "stanford, california, united states",
"id": "1W561qgHMjuYX4YWF1sIrQ_0"
}
},
...
],
"fields": [
"education.school.name"
],
"status": 200
}
You can see the full response here:
Full Response (click to toggle):
{
"data": [
{
"name": "stanford university",
"count": 434677,
"meta": {
"website": "stanford.edu",
"location_name": "stanford, california, united states",
"id": "1W561qgHMjuYX4YWF1sIrQ_0"
}
},
{
"name": "stanford university graduate school of business",
"count": 44080,
"meta": {
"website": "gsb.stanford.edu",
"location_name": "stanford, california, united states",
"id": "HSBJxyTEjoUZ0HB0QMYNhg_0"
}
},
{
"name": "stanford law school",
"count": 10425,
"meta": {
"website": "law.stanford.edu",
"location_name": "stanford, california, united states",
"id": "7oB8xssxBNsgj55NVNgX8w_0"
}
},
{
"name": "stanford university school of medicine",
"count": 9788,
"meta": {
"website": "med.stanford.edu",
"location_name": "palo alto, california, united states",
"id": "Bx27PJ2pdlcuFt305W0--g_0"
}
},
{
"name": "stanford continuing studies",
"count": 5248,
"meta": {
"website": "continuingstudies.stanford.edu",
"location_name": "stanford, california, united states",
"id": "Ij6aIDqpy2vcAEvsy84d7A_0"
}
},
{
"name": "stanford university graduate school of education",
"count": 1943,
"meta": {
"website": "ed.stanford.edu",
"location_name": "stanford, california, united states",
"id": "7memxNXEkFjKfVFzugGARw_0"
}
},
{
"name": "stanford university school of engineering",
"count": 1557,
"meta": {
"website": "engineering.stanford.edu",
"location_name": "stanford, california, united states",
"id": "EmDZlGWe-NO97qziNWDZlQ_0"
}
},
{
"name": "stanford graduate school of business executive education",
"count": 1197,
"meta": {
"website": null,
"location_name": "united states",
"id": "gAhTlHvSnTzbG9v8GIBzHg_0"
}
},
{
"name": "stanfield secondary school",
"count": 326,
"meta": {
"website": "stanfield.k12.or.us",
"location_name": "stanfield, oregon, united states",
"id": "eeSTd4RdDZx8blKM9CsHdw_0"
}
},
{
"name": "stanford online high school",
"count": 325,
"meta": {
"website": "ohs.stanford.edu",
"location_name": "stanford, california, united states",
"id": "dZ7tnAE3--3kiSjm6xauSQ_0"
}
}
],
"fields": [
"education.school.name"
],
"status": 200
}
Updated about 1 year ago