YouTubeYouTube API Guide

How to Add YouTube Videos to Playlists via API

Schedule YouTube videos and Shorts to specific playlists using the PostFast API. Retrieve your playlist IDs and organize content programmatically.

Last updated: January 2025
Organize your YouTube content automaticallyGet API Key

When scheduling YouTube videos or Shorts through the PostFast API, you can automatically add them to a playlist after publishing. This helps organize your content and improve discoverability through playlist-based recommendations.

To add a video to a playlist, you need the playlist ID. Use the GET /social-media/{socialMediaId}/youtube-playlists endpoint to retrieve all playlists for your connected YouTube channel. Then include the playlistId value in the youtubePlaylistId control when creating your post.

Important: The video publishes first, then gets added to the playlist as a secondary operation. If the playlist addition fails (wrong ID, playlist full, etc.), the video is still live on your channel.

API Parameters

ParameterTypeDescription
youtubePlaylistIdstringYouTube playlist ID to add the video to after publishing. Get available playlists from GET /social-media/{socialMediaId}/youtube-playlists and use the playlistId field.
youtubeIsShortbooleanWhether it's a YouTube Short
youtubeTitlestringVideo title. If not provided, the first 100 characters of content will be used
youtubePrivacystringVideo privacy setting
PUBLICUNLISTEDPRIVATE

Code Example

const response = await fetch('https://api.postfa.st/social-posts', {
  method: 'POST',
  headers: {
    'pf-api-key': 'YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
        "posts": [
            {
                "content": "Part 3 of my React hooks series! Today we cover useCallback and useMemo ⚛️\n\nTimestamps:\n0:00 - useCallback basics\n0:45 - When to use useCallback\n1:30 - useMemo explained\n2:15 - Performance tips\n\n#reactjs #webdev #programming",
                "mediaItems": [
                    {
                        "key": "video/b3c4d5e6-f7a8-9012-3456-789012bcdefg.mp4",
                        "type": "VIDEO",
                        "sortOrder": 0
                    }
                ],
                "scheduledAt": "2025-01-31T14:00:00.000Z",
                "socialMediaId": "880a1722-b5ce-64a7-d049-778988772004"
            }
        ],
        "controls": {
            "youtubePlaylistId": "PLrAXtmErZgOeiKm4sgNOknGvNjby9efdf",
            "youtubeIsShort": true,
            "youtubeTitle": "React Hooks: useCallback & useMemo Explained",
            "youtubePrivacy": "PUBLIC"
        }
    })
});

const data = await response.json();

Did You Know?

Playlist Ownership
Must be your playlist
The playlist must belong to the authenticated YouTube channel
Playlist ID Source
Use playlistId field
Get from GET /social-media/{socialMediaId}/youtube-playlists response
Single Playlist
One playlist per video
You can only add a video to one playlist via the API. For multiple playlists, use YouTube Studio after publishing.
Failure Handling
Video still publishes
If playlist addition fails, the video is still live on your channel

Tips

First call GET /social-media/{socialMediaId}/youtube-playlists to get your playlist IDs, then cache them - they rarely change

Organize Shorts into themed playlists (tips, tutorials, behind-the-scenes) for better channel structure

Playlist addition happens after video processing, so there may be a short delay before it appears in the playlist

Use playlists to create content series that viewers can binge-watch

If you create a new playlist on YouTube, sync it in the PostFast dashboard (Accounts → your YouTube account → Sync Playlists)

Schedule videos to YouTube with automatic playlist organization

7-day free trial
Try PostFast Free

Common Pitfalls

Using wrong playlist ID

Make sure you use the playlistId field from the API response (e.g., "PLrAXtmErZgOeiKm4sgNOknGvNjby9efdf"), not the internal id field.

Playlist from different channel

The playlist must belong to the same YouTube channel you're posting to. You cannot add videos to playlists from other channels.

Assuming playlist addition is instant

Playlist addition happens after the video is fully processed. For long videos, there may be a delay before it appears in the playlist.

Not checking for errors

The video publishes even if playlist addition fails. Check your YouTube Studio to confirm the video was added to the playlist.

Frequently Asked Questions

How do I get my YouTube playlist IDs?

Call GET /social-media/{socialMediaId}/youtube-playlists with your YouTube account's socialMediaId. This returns all your playlists with their playlistId values (like "PLrAXtmErZgOeiKm4sgNOknGvNjby9efdf"). Use the playlistId field when setting youtubePlaylistId.

Can I add a video to multiple playlists?

The API supports adding to one playlist via youtubePlaylistId. To add to multiple playlists, you'll need to use YouTube Studio manually or the YouTube Data API separately after publishing.

What happens if the playlist addition fails?

The video still publishes successfully to your channel. Playlist addition is a secondary operation - if it fails (wrong ID, playlist full, etc.), the video is still live. Check YouTube Studio to confirm.

Build your YouTube content library with programmatic posting

Start Free Trial
7-day free trialCancel anytime