Examples - Autocomplete API
Illustrative examples for the Autocomplete API
We've provided code samples in Python, cURL, Ruby, Go and JavaScript. If you aren't comfortable working in any of these languages, feel free to use this handy tool to convert code from cURL to the language of your choice.
See a Bug? Want To See a Specific Example?
Feel free to use the
Suggest Edits
button in the top right-hand corner of this page to point out any bugs or to request any specific code examples for this API that you'd like to see here.
Company Autocomplete Example
Give me 10 suggestions for companies starting with "ama"
.
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": "company",
"text": "ama",
"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=company'\
--data-urlencode 'text=ama'
// 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": "company",
"text": "ama",
"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: "company", text: "ama", 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 {
Pretty: true,
},
AutocompleteBaseParams: pdlmodel.AutocompleteBaseParams {
Field: "company",
Text: "ama",
},
}
// 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": "company",
"text": "ama",
"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)
Job Title Autocomplete Example
Give me 20 suggestions for job titles starting with the prefix "data"
.
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": "title",
"text": "data",
"size": 20,
"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=title'\
--data-urlencode 'text=data'\
--data-urlencode 'size=20'
// 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": "title",
"text": "data",
"size": 20,
"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: "title", text: "data", size: 20, 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: 20,
Pretty: true,
},
AutocompleteBaseParams: pdlmodel.AutocompleteBaseParams {
Field: "title",
Text: "data",
},
}
// 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": "title",
"text": "data",
"size": 20,
"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)
Updated about 1 year ago