PeerTube add-intro API call format

Hi,
I’m trying to make a test API call using CURL to add an intro to a video.
I managed to do a lot of other tasks but this one seems particularly complicated due to the Request Body schema: application/x-www-form-urlencoded
Am I right that the video I’m adding as intro shouldn’t be passed from my PC but should link to a video already present in PeerTube? Because if I try with a video in my PC I get an error regarding the size of the request even if the intro video is only 1MB.
Can someone provide me a succesful API call format for this task?
Thank you in advance!

1 « J'aime »

Hi,

The video must comes from your local disk. Can you paste the error your get?

1 « J'aime »

Think the problem was the Base64 encoding of the file.

At the moment I’m trying with this

curl -X POST https://<hostname>/api/v1/videos/<videoid>/studio/edit \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "tasks[0][name]=add-intro" \
--data-urlencode "tasks[0][options][file]=<local .mp4 file>"

but I get

{"type":"about:blank","title":"Bad Request","detail":"Incorrect request parameters: tasks","instance":"/api/v1/videos/<videoid>/studio/edit","status":400,"invalid-params":{"tasks":{"type":"field","msg":"Should have a valid array of tasks","path":"tasks","location":"body"}},"error":"Incorrect request parameters: tasks"}% 

Thanks for the reply!

1 « J'aime »

Can you enable debug logs on the peertube instance and insert them after running the curl command?

1 « J'aime »

Sure!
I got this with debug enabled

debug[27/01/2025, 16:55:11] Getting access token.

debug[27/01/2025, 16:55:11] Checking POST - /api/v1/videos/redacted/studio/edit parameters

{
  "body": {
    "name[0]": "add-intro",
    "options[0][file]": "/Users/User/Documents/intro.mp4"
  },
  "params": {
    "videoId": "redacted"
  },
  "query": {},
  "tags": []
}

warn[27/01/2025, 16:55:11] Incorrect request parameters

{
  "path": "/api/v1/videos/redacted/studio/edit",
  "err": {
    "tasks": {
      "type": "field",
      "msg": "Should have a valid array of tasks",
      "path": "tasks",
      "location": "body"
    }
  }
}

debug[27/01/2025, 16:55:11] Bad HTTP request.

{
  "json": {
    "type": "about:blank",
    "title": "Bad Request",
    "detail": "Incorrect request parameters: tasks",
    "instance": "/api/v1/videos/redacted/studio/edit",
    "status": 400,
    "invalid-params": {
      "tasks": {
        "type": "field",
        "msg": "Should have a valid array of tasks",
        "path": "tasks",
        "location": "body"
      }
    },
    "error": "Incorrect request parameters: tasks"
  }
}

info[27/01/2025, 16:55:11] <myIP> - - [27/Jan/2025:15:55:11 +0000] "POST /api/v1/videos/redacted/studio/edit HTTP/1.0" 400 313 "-" "curl/8.7.1"

{
  "tags": [
    "http"
  ]
}

Let me know if you need other infos!

1 « J'aime »

Thanks,

Try to send the file using -F curl option without specifying Content-Type because PeerTube requires multipart/form-data

1 « J'aime »

Hi, using

curl -X POST https://host/api/v1/videos/redacted/studio/edit \
-H "Authorization: Bearer token" \
-F "tasks[0][name]=add-intro" \
-F "tasks[0][options][file]=@/Users/User/Downloads/intro.mp4"

throws (from logs set to debug)

debug[28/01/2025, 09:18:53] Getting access token.

debug[28/01/2025, 09:18:53] Checking POST - /api/v1/videos/redacted/studio/edit parameters

{
  "body": {
    "tasks": [
      {
        "name": "add-intro"
      }
    ]
  },
  "params": {
    "videoId": "redacted"
  },
  "query": {},
  "files": [
    {
      "fieldname": "tasks[0][options][file]",
      "originalname": "intro.mp4",
      "encoding": "7bit",
      "mimetype": "application/octet-stream",
      "destination": "/var/www/peertube/storage/tmp/",
      "filename": "redacted.mp4",
      "path": "/var/www/peertube/storage/tmp/redacted.mp4",
      "size": 1628117
    }
  ],
  "tags": []
}

debug[28/01/2025, 09:18:53] Bad HTTP request.

{
  "json": {
    "type": "about:blank",
    "title": "Bad Request",
    "detail": "Task add-intro is invalid",
    "status": 400,
    "error": "Task add-intro is invalid"
  }
}

info[28/01/2025, 09:18:53] yip - - [28/Jan/2025:08:18:53 +0000] "POST /api/v1/videos/redacted/studio/edit HTTP/1.0" 400 130 "-" "curl/8.7.1"

{
  "tags": [
    "http"
  ]
}

Thaks for the help!

1 « J'aime »

Try

-F "tasks[0][options][file]=@/Users/User/Downloads/intro.mp4;type=video/mp4"
1 « J'aime »

I can confirm this call format seems to be working

curl -X POST https://openmedia01.edunext.eu/api/v1/videos/<videoID>/studio/edit \
-H "Authorization: Bearer <yourToken>" \
-F "tasks[0][name]=add-intro" \
-F "tasks[0][options][file]=@<path/to/file/in/your/pc.mp4>;type=video/mp4"

Will confirm later because the server I’m testing with is running PeerTube 6.3.2 that seems to have a bug related to transcoding that is preventing ffmpeg to run correctly when adding an intro. But now the curl is not throwing errors and the add-intro task is started correctly.
From what I’ve see in changelog the problem was fixed in 6.3.3 so will update to the latest release asap.
Also if anyone will read this I encourage you to make the action you want to perform via the web interface with network monitor open so you can see how the call is performed. Would have saved a lot of headache in my case.
In the API documentation is stated « Request Body schema: application/x-www-form-urlencoded » as « required » so I think it’s a bit misleading if I’m reading the documentation correctly.

Anyway thanks a lot for your help and all the work that you put in the project!

1 « J'aime »

Thanks, I’ll fix the documentation :slight_smile:

1 « J'aime »