# Autocomplete

With the `youtube_autocomplete` source, users can get related keyword suggestions for any search term of their choice. These suggestions can be used with the `youtube_search` source to discover more relevant videos and expand your YouTube data workflows.

### Request samples

The following examples demonstrate how to retrieve search term suggestions for a given query.

{% tabs %}
{% tab title="cURL" %}

```shell
curl 'https://realtime.oxylabs.io/v1/queries' \
--user 'USERNAME:PASSWORD' \
-H 'Content-Type: application/json' \
-d '{
        "source": "youtube_autocomplete",
        "query": "what is",
        "language": "en",
        "location": "US"
    }'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
from pprint import pprint

# Structure payload.
payload = {
    "source": "youtube_autocomplete",
    "query": "what is",
    "language": "en",
    "location": "US"
}

# Get response.
response = requests.request(
    "POST",
    "https://realtime.oxylabs.io/v1/queries",
    auth=("USERNAME", "PASSWORD"),
    json=payload,
)

# Print the JSON response with the result.
pprint(response.json())
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const https = require("https");

const username = "USERNAME";
const password = "PASSWORD";
const body = {
    source: "youtube_autocomplete",
    query: "what is",
    language: "en",
    location: "US"
};

const options = {
    hostname: "realtime.oxylabs.io",
    path: "/v1/queries",
    method: "POST",
    headers: {
        "Content-Type": "application/json",
        Authorization:
            "Basic " + Buffer.from(`${username}:${password}`).toString("base64"),
    },
};

const request = https.request(options, (response) => {
    let data = "";

    response.on("data", (chunk) => {
        data += chunk;
    });

    response.on("end", () => {
        const responseData = JSON.parse(data);
        console.log(JSON.stringify(responseData, null, 2));
    });
});

request.on("error", (error) => {
    console.error("Error:", error);
});

request.write(JSON.stringify(body));
request.end();

```

{% endtab %}

{% tab title="HTTP" %}

```http
# The whole string you submit has to be URL-encoded.
https://realtime.oxylabs.io/v1/queries?source=youtube_autocomplete&query=what%20is&language=en&location=US&access_token=12345abcde

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$params = array(
    'source' => 'youtube_autocomplete',
    'query' => 'what is',
    'language' => 'en',
    'location' => 'US'
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://realtime.oxylabs.io/v1/queries");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "USERNAME" . ":" . "PASSWORD");

$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result;

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}

curl_close($ch);
```

{% endtab %}

{% tab title="Golang" %}

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

func main() {
	const Username = "USERNAME"
	const Password = "PASSWORD"

	// Define the payload
	payload := map[string]interface{}{
		"source":   "youtube_autocomplete",
		"query":    "what is",
		"language": "en",
		"location": "US",
	}

	jsonValue, err := json.Marshal(payload)
	if err != nil {
		fmt.Println("Error marshalling JSON:", err)
		return
	}

	client := &http.Client{}
	request, err := http.NewRequest("POST", "https://realtime.oxylabs.io/v1/queries", bytes.NewBuffer(jsonValue))
	if err != nil {
		fmt.Println("Error creating request:", err)
		return
	}

	request.SetBasicAuth(Username, Password)
	request.Header.Set("Content-Type", "application/json")

	response, err := client.Do(request)
	if err != nil {
		fmt.Println("Error making request:", err)
		return
	}
	defer response.Body.Close()

	responseText, err := ioutil.ReadAll(response.Body)
	if err != nil {
		fmt.Println("Error reading response:", err)
		return
	}

	fmt.Println(string(responseText))
}
```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;

namespace OxyApi
{
    class Program
    {
        static async Task Main()
        {
            const string Username = "USERNAME";
            const string Password = "PASSWORD";

            var parameters = new
            {
                source = "youtube_autocomplete",
                query = "what is",
                language = "en",
                location = "US"
            };

            var client = new HttpClient();

            Uri baseUri = new Uri("https://realtime.oxylabs.io");
            client.BaseAddress = baseUri;

            var requestMessage = new HttpRequestMessage(HttpMethod.Post, "/v1/queries");
            requestMessage.Content = JsonContent.Create(parameters);

            var authenticationString = $"{Username}:{Password}";
            var base64EncodedAuthenticationString = Convert.ToBase64String(Encoding.UTF8.GetBytes(authenticationString));
            requestMessage.Headers.Add("Authorization", "Basic " + base64EncodedAuthenticationString);

            try
            {
                var response = await client.SendAsync(requestMessage);
                response.EnsureSuccessStatusCode();

                var contents = await response.Content.ReadAsStringAsync();
                Console.WriteLine(contents);
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine($"Request error: {e.Message}");
            }
        }
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
package org.example;

import okhttp3.*;
import org.json.JSONObject;
import java.util.concurrent.TimeUnit;

public class Main implements Runnable {
    private static final String AUTHORIZATION_HEADER = "Authorization";
    public static final String USERNAME = "USERNAME";
    public static final String PASSWORD = "PASSWORD";

    public void run() {
        // Construct JSON payload
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("source", "youtube_autocomplete");
        jsonObject.put("query", "what is");
        jsonObject.put("language", "en");
        jsonObject.put("location", "US");

        Authenticator authenticator = (route, response) -> {
            String credential = Credentials.basic(USERNAME, PASSWORD);
            return response
                    .request()
                    .newBuilder()
                    .header(AUTHORIZATION_HEADER, credential)
                    .build();
        };

        var client = new OkHttpClient.Builder()
                .authenticator(authenticator)
                .readTimeout(180, TimeUnit.SECONDS)
                .build();

        var mediaType = MediaType.parse("application/json; charset=utf-8");
        var body = RequestBody.create(jsonObject.toString(), mediaType);
        var request = new Request.Builder()
                .url("https://realtime.oxylabs.io/v1/queries")
                .post(body)
                .build();

        try (var response = client.newCall(request).execute()) {
            if (response.body() != null) {
                try (var responseBody = response.body()) {
                    System.out.println(responseBody.string());
                }
            }
        } catch (Exception exception) {
            System.out.println("Error: " + exception.getMessage());
        }

        System.exit(0);
    }

    public static void main(String[] args) {
        new Thread(new Main()).start();
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
    "source": "youtube_autocomplete",
    "query": "what is",
    "language": "en",
    "location": "US"
}
```

{% endtab %}
{% endtabs %}

Our examples use synchronous [Realtime](https://developers.oxylabs.io/scraping-solutions/web-scraper-api/integration-methods/realtime) integration method. If you would like to use [Proxy Endpoint](https://developers.oxylabs.io/scraping-solutions/web-scraper-api/integration-methods/proxy-endpoint), or asynchronous [Push-Pull](https://developers.oxylabs.io/scraping-solutions/web-scraper-api/integration-methods/push-pull) integration, refer to the [Integration Methods](https://developers.oxylabs.io/scraping-solutions/web-scraper-api/integration-methods) section.

### Output sample

```json
{
    "results": [
        {
            "content": "window.google.ac.h([\"what is\",[[\"what is love\",0,[512,433]],[\"what is this feeling wicked\",0,[512,433,131]],[\"what is love baby dont hurt me no\",0,[512,433]],[\"what is 67\",0,[512,433,131]],[\"what is\",0,[512]],[\"what is you nba youngboy\",0,[512,433,131]],[\"what is love haddaway\",0,[512,433]],[\"what is this feeling wicked karaoke\",0,[512,433]],[\"what is love twice\",0,[512,433,131]],[\"what is you\",0,[512,433,131,650]],[\"what is sounds like\",0,[512,433]],[\"what is scientology\",0,[512]],[\"what is the big beautiful bill\",0,[512]],[\"what is a woman\",0,[512,433]]],{\"j\":\"5\",\"k\":1,\"q\":\"fxuDygqjaW7TVwu4-jEjTrWp6b8\"}])",
            "type": "raw",
            ...
}
```

### Request parameter values

<table><thead><tr><th width="227">Parameter</th><th width="289.3333333333333">Description</th><th>Default Value</th></tr></thead><tbody><tr><td><mark style="background-color:green;"><strong><code>source</code></strong></mark></td><td>Sets the scraper.</td><td><code>youtube_autocomplete</code></td></tr><tr><td><mark style="background-color:green;"><strong><code>query</code></strong></mark></td><td>The search term for which keyword suggestions should be returned.</td><td>–</td></tr><tr><td><code>location</code></td><td>Search location (2-letter country code).</td><td><code>US</code></td></tr><tr><td><code>language</code> </td><td>Search language code.</td><td><code>en</code></td></tr><tr><td><code>callback_url</code></td><td>URL to your callback endpoint. <a href="../../../integration-methods/push-pull#callback"><strong>More info</strong></a>.</td><td>–</td></tr></tbody></table>

&#x20;    – mandatory parameter

### Localization

For available `location` and `language` parameter values, consult the tables below.

<details>

<summary>Available locations for <code>youtube_autocomplete</code></summary>

| Parameter value | Country                                      |
| --------------- | -------------------------------------------- |
| af              | Afghanistan                                  |
| al              | Albania                                      |
| dz              | Algeria                                      |
| as              | American Samoa                               |
| ad              | Andorra                                      |
| ao              | Angola                                       |
| ai              | Anguilla                                     |
| aq              | Antarctica                                   |
| ag              | Antigua and Barbuda                          |
| ar              | Argentina                                    |
| am              | Armenia                                      |
| aw              | Aruba                                        |
| au              | Australia                                    |
| at              | Austria                                      |
| az              | Azerbaijan                                   |
| bs              | Bahamas                                      |
| bh              | Bahrain                                      |
| bd              | Bangladesh                                   |
| bb              | Barbados                                     |
| by              | Belarus                                      |
| be              | Belgium                                      |
| bz              | Belize                                       |
| bj              | Benin                                        |
| bm              | Bermuda                                      |
| bt              | Bhutan                                       |
| bo              | Bolivia                                      |
| ba              | Bosnia and Herzegovina                       |
| bw              | Botswana                                     |
| bv              | Bouvet Island                                |
| br              | Brazil                                       |
| io              | British Indian Ocean Territory               |
| bn              | Brunei Darussalam                            |
| bg              | Bulgaria                                     |
| bf              | Burkina Faso                                 |
| bi              | Burundi                                      |
| kh              | Cambodia                                     |
| cm              | Cameroon                                     |
| ca              | Canada                                       |
| cv              | Cape Verde                                   |
| ky              | Cayman Islands                               |
| cf              | Central African Republic                     |
| td              | Chad                                         |
| cl              | Chile                                        |
| cn              | China                                        |
| cx              | Christmas Island                             |
| cc              | Cocos (Keeling) Islands                      |
| co              | Colombia                                     |
| km              | Comoros                                      |
| cg              | Congo                                        |
| cd              | Congo, the Democratic Republic of the        |
| ck              | Cook Islands                                 |
| cr              | Costa Rica                                   |
| ci              | Cote D'ivoire                                |
| hr              | Croatia                                      |
| cu              | Cuba                                         |
| cy              | Cyprus                                       |
| cz              | Czech Republic                               |
| dk              | Denmark                                      |
| dj              | Djibouti                                     |
| dm              | Dominica                                     |
| do              | Dominican Republic                           |
| ec              | Ecuador                                      |
| eg              | Egypt                                        |
| sv              | El Salvador                                  |
| gq              | Equatorial Guinea                            |
| er              | Eritrea                                      |
| ee              | Estonia                                      |
| et              | Ethiopia                                     |
| fk              | Falkland Islands (Malvinas)                  |
| fo              | Faroe Islands                                |
| fj              | Fiji                                         |
| fi              | Finland                                      |
| fr              | France                                       |
| gf              | French Guiana                                |
| pf              | French Polynesia                             |
| tf              | French Southern Territories                  |
| ga              | Gabon                                        |
| gm              | Gambia                                       |
| ge              | Georgia                                      |
| de              | Germany                                      |
| gh              | Ghana                                        |
| gi              | Gibraltar                                    |
| gr              | Greece                                       |
| gl              | Greenland                                    |
| gd              | Grenada                                      |
| gp              | Guadeloupe                                   |
| gu              | Guam                                         |
| gt              | Guatemala                                    |
| gn              | Guinea                                       |
| gw              | Guinea-Bissau                                |
| gy              | Guyana                                       |
| ht              | Haiti                                        |
| hm              | Heard Island and Mcdonald Islands            |
| va              | Holy See (Vatican City State)                |
| hn              | Honduras                                     |
| hk              | Hong Kong                                    |
| hu              | Hungary                                      |
| is              | Iceland                                      |
| in              | India                                        |
| id              | Indonesia                                    |
| ir              | Iran, Islamic Republic of                    |
| iq              | Iraq                                         |
| ie              | Ireland                                      |
| il              | Israel                                       |
| it              | Italy                                        |
| jm              | Jamaica                                      |
| jp              | Japan                                        |
| jo              | Jordan                                       |
| kz              | Kazakhstan                                   |
| ke              | Kenya                                        |
| ki              | Kiribati                                     |
| kp              | North Korea                                  |
| kr              | South Korea                                  |
| kw              | Kuwait                                       |
| kg              | Kyrgyzstan                                   |
| la              | Lao People's Democratic Republic             |
| lv              | Latvia                                       |
| lb              | Lebanon                                      |
| ls              | Lesotho                                      |
| lr              | Liberia                                      |
| ly              | Libya                                        |
| li              | Liechtenstein                                |
| lt              | Lithuania                                    |
| lu              | Luxembourg                                   |
| mo              | Macao                                        |
| mk              | North Macedonia                              |
| mg              | Madagascar                                   |
| mw              | Malawi                                       |
| my              | Malaysia                                     |
| mv              | Maldives                                     |
| ml              | Mali                                         |
| mt              | Malta                                        |
| mh              | Marshall Islands                             |
| mq              | Martinique                                   |
| mr              | Mauritania                                   |
| mu              | Mauritius                                    |
| yt              | Mayotte                                      |
| mx              | Mexico                                       |
| fm              | Micronesia, Federated States of              |
| md              | Moldova, Republic of                         |
| mc              | Monaco                                       |
| mn              | Mongolia                                     |
| ms              | Montserrat                                   |
| ma              | Morocco                                      |
| mz              | Mozambique                                   |
| mm              | Myanmar                                      |
| na              | Namibia                                      |
| nr              | Nauru                                        |
| np              | Nepal                                        |
| nl              | Netherlands                                  |
| nc              | New Caledonia                                |
| nz              | New Zealand                                  |
| ni              | Nicaragua                                    |
| ne              | Niger                                        |
| ng              | Nigeria                                      |
| nu              | Niue                                         |
| nf              | Norfolk Island                               |
| mp              | Northern Mariana Islands                     |
| no              | Norway                                       |
| om              | Oman                                         |
| pk              | Pakistan                                     |
| pw              | Palau                                        |
| ps              | Palestinian Territory, Occupied              |
| pa              | Panama                                       |
| pg              | Papua New Guinea                             |
| py              | Paraguay                                     |
| pe              | Peru                                         |
| ph              | Philippines                                  |
| pn              | Pitcairn                                     |
| pl              | Poland                                       |
| pt              | Portugal                                     |
| pr              | Puerto Rico                                  |
| qa              | Qatar                                        |
| re              | Reunion                                      |
| ro              | Romania                                      |
| ru              | Russian Federation                           |
| rw              | Rwanda                                       |
| sh              | Saint Helena                                 |
| kn              | Saint Kitts and Nevis                        |
| lc              | Saint Lucia                                  |
| pm              | Saint Pierre and Miquelon                    |
| vc              | Saint Vincent and the Grenadines             |
| ws              | Samoa                                        |
| sm              | San Marino                                   |
| st              | Sao Tome and Principe                        |
| sa              | Saudi Arabia                                 |
| sn              | Senegal                                      |
| rs              | Serbia and Montenegro                        |
| sc              | Seychelles                                   |
| sl              | Sierra Leone                                 |
| sg              | Singapore                                    |
| sk              | Slovakia                                     |
| si              | Slovenia                                     |
| sb              | Solomon Islands                              |
| so              | Somalia                                      |
| za              | South Africa                                 |
| gs              | South Georgia and the South Sandwich Islands |
| es              | Spain                                        |
| lk              | Sri Lanka                                    |
| sd              | Sudan                                        |
| sr              | Suriname                                     |
| sj              | Svalbard and Jan Mayen                       |
| sz              | Swaziland                                    |
| se              | Sweden                                       |
| ch              | Switzerland                                  |
| sy              | Syrian Arab Republic                         |
| tw              | Taiwan                                       |
| tj              | Tajikistan                                   |
| tz              | Tanzania, United Republic of                 |
| th              | Thailand                                     |
| tl              | Timor-Leste                                  |
| tg              | Togo                                         |
| tk              | Tokelau                                      |
| to              | Tonga                                        |
| tt              | Trinidad and Tobago                          |
| tn              | Tunisia                                      |
| tr              | Turkey                                       |
| tm              | Turkmenistan                                 |
| tc              | Turks and Caicos Islands                     |
| tv              | Tuvalu                                       |
| ug              | Uganda                                       |
| ua              | Ukraine                                      |
| ae              | United Arab Emirates                         |
| uk              | United Kingdom                               |
| gb              | United Kingdom                               |
| us              | United States                                |
| um              | United States Minor Outlying Islands         |
| uy              | Uruguay                                      |
| uz              | Uzbekistan                                   |
| vu              | Vanuatu                                      |
| ve              | Venezuela                                    |
| vn              | Viet Nam                                     |
| vg              | Virgin Islands, British                      |
| vi              | Virgin Islands, U.S.                         |
| wf              | Wallis and Futuna                            |
| eh              | Western Sahara                               |
| ye              | Yemen                                        |
| zm              | Zambia                                       |
| zw              | Zimbabwe                                     |
| gg              | Guernsey                                     |
| je              | Jersey                                       |
| im              | Isle of Man                                  |
| me              | Montenegro                                   |

</details>

<details>

<summary>Available languages for <code>youtube_autocomplete</code></summary>

| Parameter value | Language                 |
| --------------- | ------------------------ |
| ach             | Luo                      |
| af              | Afrikaans                |
| ak              | Akan                     |
| am              | Amharic                  |
| ar              | Arabic                   |
| az              | Azerbaijani              |
| be              | Belarusian               |
| bem             | Bemba                    |
| bg              | Bulgarian                |
| bh              | Bihari                   |
| bn              | Bengali                  |
| br              | Breton                   |
| bs              | Bosnian                  |
| bt              | Bhutanese                |
| ca              | Catalan                  |
| chr             | Cherokee                 |
| ckb             | Kurdish (Soranî)         |
| co              | Corsican                 |
| crs             | Seychellois Creole       |
| cs              | Czech                    |
| cy              | Welsh                    |
| da              | Danish                   |
| de              | German                   |
| ee              | Ewe                      |
| el              | Greek                    |
| en              | English                  |
| eo              | Esperanto                |
| es              | Spanish                  |
| es-419          | Spanish (Latin American) |
| et              | Estonian                 |
| eu              | Basque                   |
| fa              | Persian                  |
| fi              | Finnish                  |
| fo              | Faroese                  |
| fr              | French                   |
| fy              | Frisian                  |
| ga              | Irish                    |
| gaa             | Ga                       |
| gd              | Scots Gaelic             |
| gl              | Galician                 |
| gn              | Guarani                  |
| gu              | Gujarati                 |
| ha              | Hausa                    |
| haw             | Hawaiian                 |
| he              | Hebrew                   |
| hi              | Hindi                    |
| hr              | Croatian                 |
| ht              | Haitian Creole           |
| hu              | Hungarian                |
| hy              | Armenian                 |
| ia              | Interlingua              |
| id              | Indonesian               |
| ig              | Igbo                     |
| is              | Icelandic                |
| it              | Italian                  |
| iw              | Hebrew                   |
| ja              | Japanese                 |
| jw              | Javanese                 |
| ka              | Georgian                 |
| kg              | Kongo                    |
| kk              | Kazakh                   |
| kl              | Greenlandic              |
| km              | Cambodian                |
| kn              | Kannada                  |
| ko              | Korean                   |
| kri             | Krio (Sierra Leone)      |
| ku              | Kurdish                  |
| ky              | Kyrgyz                   |
| la              | Latin                    |
| lg              | Luganda                  |
| ln              | Lingala                  |
| lo              | Laothian                 |
| loz             | Lozi                     |
| lt              | Lithuanian               |
| lua             | Tshiluba                 |
| lv              | Latvian                  |
| mfe             | Mauritian Creole         |
| mg              | Malagasy                 |
| mi              | Maori                    |
| mk              | Macedonian               |
| ml              | Malayalam                |
| mn              | Mongolian                |
| mo              | Moldavian                |
| mr              | Marathi                  |
| ms              | Malay                    |
| mt              | Maltese                  |
| mv              | Maldives                 |
| my              | Myanmar                  |
| ne              | Nepali                   |
| nl              | Dutch                    |
| nn              | Norwegian (Nynorsk)      |
| no              | Norwegian                |
| nso             | Northern Sotho           |
| ny              | Chichewa                 |
| nyn             | Runyakitara              |
| oc              | Occitan                  |
| om              | Oromo                    |
| or              | Oriya                    |
| pa              | Punjabi                  |
| pcm             | Nigerian Pidgin          |
| pl              | Polish                   |
| ps              | Pashto                   |
| pt              | Portuguese               |
| pt-br           | Portuguese (Brazil)      |
| pt-pt           | Portuguese (Portugal)    |
| qu              | Quechua                  |
| rm              | Romansh                  |
| rn              | Kirundi                  |
| ro              | Romanian                 |
| ru              | Russian                  |
| rw              | Kinyarwanda              |
| sd              | Sindhi                   |
| sh              | Serbo-Croatian           |
| si              | Sinhalese                |
| sk              | Slovak                   |
| sl              | Slovenian                |
| sn              | Shona                    |
| so              | Somali                   |
| sq              | Albanian                 |
| sr              | Serbian                  |
| sr-me           | Montenegrin              |
| st              | Sesotho                  |
| su              | Sundanese                |
| sv              | Swedish                  |
| sw              | Swahili                  |
| ta              | Tamil                    |
| te              | Telugu                   |
| tg              | Tajik                    |
| th              | Thai                     |
| ti              | Tigrinya                 |
| tk              | Turkmen                  |
| tl              | Filipino                 |
| tn              | Setswana                 |
| to              | Tonga                    |
| tr              | Turkish                  |
| tt              | Tatar                    |
| tum             | Tumbuka                  |
| tw              | Twi                      |
| ug              | Uighur                   |
| uk              | Ukrainian                |
| ur              | Urdu                     |
| uz              | Uzbek                    |
| vi              | Vietnamese               |
| vu              | Vanuatu                  |
| wo              | Wolof                    |
| ws              | Samoa                    |
| xh              | Xhosa                    |
| yi              | Yiddish                  |
| yo              | Yoruba                   |
| zh-cn           | Chinese (Simplified)     |
| zh-tw           | Chinese (Traditional)    |
| zu              | Zulu                     |

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.oxylabs.io/scraping-solutions/web-scraper-api/targets/youtube/autocomplete.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
