[GH-ISSUE #48] Docs don't specify how to use POST: /api/playlist/<playlist_id>/ #86

Closed
opened 2026-03-23 21:16:43 +00:00 by mirror · 3 comments
Owner

Originally created by @douglasg14b on GitHub (Oct 20, 2024).
Original GitHub issue: https://github.com/tubearchivist/docs/issues/48

It seems like this endpoint expects an object, but the docs do not appear to elaborate on what that is

image

The endpoint appears to be here:

github.com/tubearchivist/tubearchivist@cfe94c8dac/tubearchivist/api/views.py (L532C1-L557C75)


    def post(self, request, playlist_id):
        """post to custom playlist to add a video to list"""
        playlist = YoutubePlaylist(playlist_id)
        if not playlist.is_custom_playlist():
            message = f"playlist with ID {playlist_id} is not custom"
            return Response({"message": message}, status=400)

        action = request.data.get("action")
        if action not in self.valid_custom_actions:
            message = f"invalid action: {action}"
            return Response({"message": message}, status=400)

        video_id = request.data.get("video_id")
        if action == "create":
            playlist.add_video_to_playlist(video_id)
        else:
            hide = UserConfig(request.user.id).get_value("hide_watched")
            playlist.move_video(video_id, action, hide_watched=hide)

        return Response({"success": True}, status=status.HTTP_201_CREATED)
Originally created by @douglasg14b on GitHub (Oct 20, 2024). Original GitHub issue: https://github.com/tubearchivist/docs/issues/48 It seems like this endpoint expects an object, but the docs do not appear to elaborate on what that is ![image](https://github.com/user-attachments/assets/827d9ddc-cfd3-4a37-af95-b2b98cee700b) The endpoint appears to be here: https://github.com/tubearchivist/tubearchivist/blob/cfe94c8dacca3b4f1f8d874d6ddf66553d6dcbd7/tubearchivist/api/views.py#L532C1-L557C75 ```python def post(self, request, playlist_id): """post to custom playlist to add a video to list""" playlist = YoutubePlaylist(playlist_id) if not playlist.is_custom_playlist(): message = f"playlist with ID {playlist_id} is not custom" return Response({"message": message}, status=400) action = request.data.get("action") if action not in self.valid_custom_actions: message = f"invalid action: {action}" return Response({"message": message}, status=400) video_id = request.data.get("video_id") if action == "create": playlist.add_video_to_playlist(video_id) else: hide = UserConfig(request.user.id).get_value("hide_watched") playlist.move_video(video_id, action, hide_watched=hide) return Response({"success": True}, status=status.HTTP_201_CREATED) ```
Author
Owner

@douglasg14b commented on GitHub (Oct 20, 2024):

Been trying to get this endpoint working for a bit, but I can't seem to get videos added to custom playlists 🤔

The data structure is unknown to me, but it appears as though it's expecting something like:

interface Request {
    action: "create" | "remove" | "up" | "down" | "top" | "bottom";
    video_id: string;
}
        const response = await fetch(`${TA_BASE_URL}/api/playlist/${PLAYLIST_ID}`, {
            method: 'POST',
            headers: {
                'Authorization': `Token ${TA_API_KEY}`,
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({ action: 'create', video_id: videoId })
        });

This seems to trigger the GET endpoint, as the response returns metadata bout the playlist with a 200, but not the response I'd expect from here: github.com/tubearchivist/tubearchivist@cfe94c8dac/tubearchivist/api/views.py (L557)

Regardless of the body, even if I omit the body entirely, I still get the GET response. And not the expected POST response. No logs appear to be generated for this endpoint 🤔

How is this endpoint supposed to be used?

<!-- gh-comment-id:2424655669 --> @douglasg14b commented on GitHub (Oct 20, 2024): Been trying to get this endpoint working for a bit, but I can't seem to get videos added to custom playlists 🤔 The data structure is unknown to me, but it _appears_ as though it's expecting something like: ```ts interface Request { action: "create" | "remove" | "up" | "down" | "top" | "bottom"; video_id: string; } ``` ```js const response = await fetch(`${TA_BASE_URL}/api/playlist/${PLAYLIST_ID}`, { method: 'POST', headers: { 'Authorization': `Token ${TA_API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ action: 'create', video_id: videoId }) }); ``` This seems to trigger the `GET` endpoint, as the response returns metadata bout the playlist with a `200`, but not the response I'd expect from here: https://github.com/tubearchivist/tubearchivist/blob/cfe94c8dacca3b4f1f8d874d6ddf66553d6dcbd7/tubearchivist/api/views.py#L557 Regardless of the body, even if I omit the body entirely, I still get the `GET` response. And not the expected `POST` response. No logs appear to be generated for this endpoint 🤔 How is this endpoint supposed to be used?
Author
Owner

@douglasg14b commented on GitHub (Oct 20, 2024):

Looks like the trailing / is required for these endpoints for some reason. Wonky routing?

<!-- gh-comment-id:2424691597 --> @douglasg14b commented on GitHub (Oct 20, 2024): Looks like the trailing `/` is required for these endpoints for some reason. Wonky routing?
Author
Owner

@bbilly1 commented on GitHub (Nov 8, 2024):

added to the docs.

<!-- gh-comment-id:2463996216 --> @bbilly1 commented on GitHub (Nov 8, 2024): added to the docs.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
tubearchivist/docs#86
No description provided.