> ## Documentation Index
> Fetch the complete documentation index at: https://docs.peopledatalabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Examples - 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](https://curl.trillworks.com/) to convert code from cURL to the language of your choice.

<Callout icon="💡" theme="default">
  ### We want your feedback!

  Do you see a bug? Is there an example you'd like to see that's not listed here?

  Head over to the public roadmap and submit a [bug ticket](https://peopledatalabs.canny.io/bugs) or a [feature request](https://peopledatalabs.canny.io/feature-requests) and receive automatic notifications as your bug is resolved or your request is implemented
</Callout>

## Company Autocomplete Example

*"Give me 10 suggestions for companies starting with`"ama"`* ."

```python Python3 SDK
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)
```

```shell cURL
curl -X GET -G \
  'https://api.peopledatalabs.com/v5/autocomplete'\
  -H 'X-Api-Key: xxxx' \
  --data-urlencode 'field=company'\
  --data-urlencode 'text=ama'
```

```javascript JavaScript
// 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);
});
```

```ruby Ruby
# 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)
```

```go
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))
        }
    }
}
```

```python Python3
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"`."*

```python Python3 SDK
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)
```

```shell cURL
curl -X GET -G \
  'https://api.peopledatalabs.com/v5/autocomplete'\
  -H 'X-Api-Key: your-api-key' \
  --data-urlencode 'field=title'\
  --data-urlencode 'text=data'\
  --data-urlencode 'size=20'
```

```javascript JavaScript
// 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);
});
```

```ruby Ruby
# 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)
```

```go
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))
        }
    }
}
```

```python Python3
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)
```

## Skill Autocomplete Example Using POST

*"Give me 5 suggestions for skills starting with the prefix`"python"`* ."

> 📘 Difference Between GET and POST Requests
>
> See this article for a comparison of the [differences between GET and POST requests](https://www.w3schools.com/tags/ref_httpmethods.asp). The biggest difference is that POST requests don't have any limit on the amount of data that you can pass in a request.

```python Python3
import requests, json

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

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

HEADERS = {
  'Content-Type': "application/json",
  'X-api-key': API_KEY
}

# Create a parameters JSON object
PARAMS = {
    "api_key": API_KEY,
    "field": "skill",
    "text": "python",
    "pretty": True
}

# Pass the parameters object to the Autocomplete API using POST method
response = requests.post(
  PDL_URL,
  headers=HEADERS,
  json=PARAMS # Passing the data directly as a JSON object
).json()

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

```curl cURL
curl -X POST \
  'https://api.peopledatalabs.com/v5/autocomplete' \
  -H 'X-Api-Key: your-api-key' \
  -H 'Content-Type: application/json' \
  -d '{
    "field": "skill",
    "text": "python",
    "pretty": true
}'
```