# YouTube Search API

Here is the list of default parameters you can use with this API:

|                            Parameters                           |                                                                                                                       Description                                                                                                                       |
| :-------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| <p>api\_key<br><br><mark style="color:red;">required</mark></p> |                                                                                                                  This is your API key.                                                                                                                  |
|                                q                                |                                                                                               <p>Type: <code>String</code><br><br>Youtube Search Query</p>                                                                                              |
|                                gl                               |            <p>Type: <code>String</code></p><p></p><p>Default: <code>"us"</code><br> Name of the country. The name should be in </p><p><a href="https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes">ISO 3166 Alpha-2</a> format.</p>           |
|                                hl                               |                                                                <p>Type: <code>String</code></p><p><br>Default Value: <code>"en\_us"</code><br>The language of the requested results.</p>                                                                |
|                                sp                               | <p>Type: <code>String</code><br><br>This parameter is used to get the next page results. You can also filter the search results with this parameter. <br><br>You can visit the YouTube website to get the filter value for integrating in the API. </p> |
|                               html                              |                                                                       <p>Type: <code>Boolean</code><br><br>Default: <code>false</code><br>To render the response as raw HTML.</p>                                                                       |

**Note:** \
**1. Each YouTube Search API request will cost you 10 request per credit.**\
**2. Currently, JSON results are not available as the API is still in development mode. So, you will get only HTML results with this API until we are done with the development. Please use the "html=true" parameter to get the HTML results.**

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

```json
cURL "http://api.serpdog.io/youtube?q=javascript+tutorials&api_key=APIKEY&html=true"
```

{% endtab %}

{% tab title="Node JS" %}

```javascript
const axios = require('axios');

axios.get('https://api.serpdog.io/youtube?q=javascript+tutorials&api_key=APIKEY&html=true')
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.log(error);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
payload = {'api_key': 'APIKEY', 'q':'javascript+tutorials' , 'html': 'true'}
resp = requests.get('https://api.serpdog.io/youtube', params=payload)
print (resp.text)
```

{% endtab %}

{% tab title="Java" %}

```java
try {
 String url = "https://api.serpdog.io/youtube?q=javascript+tutorials&api_key=APIKEY&html=true";
 URL urlForGetRequest = new URL(url);
 String readLine = null;
 HttpURLConnection conection = (HttpURLConnection) urlForGetRequest.openConnection();
 conection.setRequestMethod("GET");
 int responseCode = conection.getResponseCode();
 if (responseCode == HttpURLConnection.HTTP_OK) {
 BufferedReader in = new BufferedReader(new InputStreamReader(conection.getInputStream()));
 StringBuffer response = new StringBuffer();
 while ((readLine = in.readLine()) != null) {
 response.append(readLine);
 }
 in.close();
 System.out.println(response.toString());
} else {
 throw new Exception("Error in API Call");
 }
} catch (Exception ex) {
 ex.printStackTrace();
}
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'net/http'
require 'json'
params = {
 :api_key => "APIKEY",
 :q=> "javascript+tutorials",
 :html=> "true"
}
uri = URI('https://api.serpdog.io/youtube')
uri.query = URI.encode_www_form(params)
website_content = Net::HTTP.get(uri)
print(website_content)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$url = "https://api.serpdog.io/youtube?q=javascript+tutorials&api_key=APIKEY&html=true";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
```

{% endtab %}
{% endtabs %}


---

# 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://docs.serpdog.io/youtube-search-api.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.
