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

# YouTube Playlists

> Get the YouTube playlists for the connected YouTube channel

export const HeaderAPI = ({noProfileKey, profileKeyRequired}) => <>
    <ParamField header="Authorization" type="string" required>
      <a href="/apis/overview#authorization">API Key</a> of the Primary Profile.
      <br />
      <br />
      Format: <code>Authorization: Bearer API_KEY</code>
    </ParamField>
    {!noProfileKey && (profileKeyRequired ? <ParamField header="Profile-Key" type="string" required>
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField> : <ParamField header="Profile-Key" type="string">
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField>)}
  </>;

export const PlansAvailable = ({plans = [], maxPackRequired}) => {
  let displayPlans = plans;
  if (plans && plans.length === 1) {
    const lowerCasePlan = plans[0].toLowerCase();
    if (lowerCasePlan === "business") {
      displayPlans = ["Launch", "Business", "Enterprise"];
    } else if (lowerCasePlan === "premium") {
      displayPlans = ["Premium", "Launch", "Business", "Enterprise"];
    }
  }
  return <Note>
Available on {displayPlans.length === 1 ? "the " : ""}
{displayPlans.join(", ").replace(/\b\w/g, l => l.toUpperCase())}{" "}
{displayPlans.length > 1 ? "plans" : "plan"}.

{maxPackRequired && <span onClick={() => window.open('https://www.ayrshare.com/docs/additional/maxpack', '_self')} className="flex items-center mt-2 cursor-pointer">
 <span className="px-1.5 py-0.5 rounded text-sm" style={{
    backgroundColor: '#C264B6',
    color: 'white',
    fontSize: '12px'
  }}>
   Max Pack required
 </span>
</span>}
</Note>;
};

<PlansAvailable plans={["premium"]} maxPackRequired={false} />

## Header Parameters

<HeaderAPI noProfileKey={false} />

<RequestExample>
  ```bash cURL theme={"system"}
  curl \
  -H "Authorization: Bearer API_KEY" \
  -X GET https://api.ayrshare.com/api/analytics/youTubePlaylists
  ```

  ```javascript JavaScript theme={"system"}
  const API_KEY = "API_KEY";

  fetch("https://api.ayrshare.com/api/analytics/youTubePlaylists", {
    method: "GET",
    headers: {
      Authorization: `Bearer ${API_KEY}`,
    },
  })
    .then((res) => res.json())
    .then((json) => console.log(json))
    .catch(console.error);
  ```

  ```python Python theme={"system"}
  import requests

  headers = {'Authorization': 'Bearer API_KEY'}

  r = requests.get('https://api.ayrshare.com/api/analytics/youTubePlaylists', headers=headers)

  print(r.json())
  ```

  ```php PHP theme={"system"}
  <?php

  $apiUrl = 'https://api.ayrshare.com/api/analytics/youTubePlaylists';
  $apiKey = 'API_KEY';  // Replace 'API_KEY' with your actual API key

  $headers = [
      'Content-Type: application/json',
      'Authorization: Bearer ' . $apiKey,
  ];

  $curl = curl_init($apiUrl);
  curl_setopt_array($curl, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_HTTPHEADER => $headers
  ]);

  $response = curl_exec($curl);

  if ($response === false) {
      echo 'Curl error: ' . curl_error($curl);
  } else {
      echo json_encode(json_decode($response), JSON_PRETTY_PRINT);
  }

  curl_close($curl);
  ```

  ```csharp C# theme={"system"}
  using System;
  using System.Net.Http;
  using System.Threading.Tasks;

  namespace YouTubePlaylistsGETRequest_csharp
  {
     class YouTubePlaylists
     {
         private static readonly HttpClient client = new HttpClient();

         static async Task Main(string[] args)
         {
             string API_KEY = "API_KEY";
             string url = "https://api.ayrshare.com/api/analytics/youTubePlaylists";

             client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);

             try 
             {
                 HttpResponseMessage response = await client.GetAsync(url);
                 response.EnsureSuccessStatusCode();
                 string responseBody = await response.Content.ReadAsStringAsync();
                 Console.WriteLine(responseBody);
             }
             catch (HttpRequestException e)
             {
                 Console.WriteLine($"Error: {e.Message}");
             }
         }
     }
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200: Success theme={"system"}
  {
    "status": "success",
    "channelId": "UCsp6CnxiNbUU0AJtuYKZw",
    "playLists": [
      {
        "averageTimeInPlaylist": 2.2,
        "averageViewDuration": 3.1,
        "description": "A great list",
        "estimatedMinutesWatched": 21,
        "estimatedRedMinutesWatched": 23,
        "id": "PLcLpmVOb3fDaf7Mps",
        "playlistStarts": 23,
        "thumbNail": {
          "url": "https://i.ytimg.com/vi/default.jpg",
          "width": 120,
          "height": 90
        },
        "title": "Super Playlist",
        "views": 55,
        "viewsPerPlaylistStart": 32
      },
      {
        "averageTimeInPlaylist": 2,
        "averageViewDuration": 4.5,
        "description": "A great list 2",
        "estimatedMinutesWatched": 2,
        "estimatedRedMinutesWatched": 3,
        "id": "FLsp6CnxiNbUU0AJtu",
        "playlistStarts": 23,
        "thumbNail": {
          "url": "https://i.ytimg.com/vi/default.jpg",
          "width": 120,
          "height": 90
        },
        "title": "Favorites",
        "views": 20,
        "viewsPerPlaylistStart": 23
      }
    ],
    "lastUpdated": "2023-01-18T03:09:59.757Z",
    "nextUpdate": "2023-01-18T03:42:29.757Z"
  }
  ```

  ```json 400: Error getting analytics theme={"system"}
  {
    "action": "analytics",
    "status": "error",
    "code": 294,
    "message": "Error getting analytics."
  }
  ```
</ResponseExample>
