HTTP Request Shortcuts for Android on pyload API

I've been messing around with HTTP Request Shortcuts on Android over the past few days and after a lot of R&D I've created a process that gets links from the Share.. dialog or the phone clipboard and sends them to my pyload-ng server on Docker for further processing. After the files have been sent it opens the pyload server URL on a custom Firefox tab inside the app so that you can check out the progress. It also shows you a dialog during the submission process where you choose the name of the package ( in my case the category of the files ) and saves them accordingly (it's a pyload specific thing).

One thing that tripped me up was the pyload API login needed before being able to send any further requests. Once you copy the code below, save it as .json on your phone and Import.. it on "Shortcuts" you'll get a "pyload login" button on the app. You edit that shortcut by going to the "Request Body / Parameters" and changing the username and password while also going to "Basic Request Settings" and setting up your pyload server URL, and port if needed. Also change "Host" on "Request Headers". After you hit the login button you can then edit the other 2 shortcuts where you change your pyload IP again and you also change it on "Scripting" where I make the request to open the server URL on a custom Firefox tab inside "Shortcuts" after a successful URL submission.

I would recommend to first edit the .json file on your favorite text editor and replace anything you see capitalized. So, here's the code:

{
  "categories": [
    {
      "id": "f3b64df5-fd7b-4083-b264-53a86b099cb5",
      "name": "Shortcuts",
      "shortcuts": [
        {
          "categoryId": "f3b64df5-fd7b-4083-b264-53a86b099cb5",
          "codeOnSuccess": "const myCookieValue \u003d response.cookies[\u0027pyload_session\u0027][0];\nshowDialog(myCookieValue);\nsetVariable(/*[variable]*/\"3b338082-c2be-48c8-9f5a-e975005b1208\"/*[/variable]*/, myCookieValue)",
          "description": "Stores cookie so that following requests work",
          "headers": [
            {
              "id": "d27d527c-a871-46cd-9356-a992a4ec9153",
              "key": "Content-Type",
              "value": "application/x-www-form-urlencoded"
            },
            {
              "id": "8b9b42bd-b787-4821-8730-22e4db37e743",
              "key": "Host",
              "value": "YOUR_PYLOAD_IP_AND_PORT"
            }
          ],
          "iconName": "black_floppy_F8902B",
          "id": "46156158-1c50-4d5d-8ae0-74630a87e93e",
          "method": "POST",
          "name": "pyload login",
          "parameters": [
            {
              "fileUploadOptions": {
                "fileUploadType": "file_picker"
              },
              "id": "43f5a028-f5e4-438d-916a-86c69910b7e2",
              "key": "username",
              "value": "YOUR_PYLOAD_USERNAME"
            },
            {
              "fileUploadOptions": {
                "fileUploadType": "file_picker"
              },
              "id": "da3bd854-9380-44d2-bd64-14d75625de41",
              "key": "password",
              "value": "YOUR_PYLOAD_PASSWORD"
            }
          ],
          "requestBodyType": "x_www_form_urlencode",
          "responseHandling": {},
          "url": "http://YOUR_PYLOAD_IP_AND_PORT/api/login"
        },
        {
          "categoryId": "f3b64df5-fd7b-4083-b264-53a86b099cb5",
          "codeOnSuccess": "openUrl(\u0027http://YOUR_PYLOAD_IP_AND_PORT/\u0027, \u0027custom-tabs(org.mozilla.firefox)\u0027);",
          "description": "via Share... dialog",
          "headers": [
            {
              "id": "4d67a1f2-ffd6-4f11-9b34-eb399e6cfecf",
              "key": "Host",
              "value": "YOUR_PYLOAD_IP_AND_PORT"
            },
            {
              "id": "e912d984-64ae-4678-9ebd-e604d6bd9825",
              "key": "Content-Type",
              "value": "application/x-www-form-urlencoded"
            }
          ],
          "iconName": "black_floppy_F8902B",
          "id": "dd8500be-158d-405b-b333-bbe36c8ba9f5",
          "name": "pyload addPackage",
          "responseHandling": {},
          "url": "http://YOUR_PYLOAD_IP_AND_PORT/api/addPackage?name\u003d\"{{bd1e41f7-78a6-4e73-97a3-b4a6093c028d}}\"\u0026links\u003d[\"{{c90d3c1c-822e-48e7-8b4d-4cf9407a8b66}}\"]"
        },
        {
          "categoryId": "f3b64df5-fd7b-4083-b264-53a86b099cb5",
          "codeOnPrepare": "function joinAndQuote(input) {\n    // Split the input string into an array of values by splitting on newlines\n    let values \u003d input.split(\u0027\\n\u0027).filter(val \u003d\u003e val.trim() !\u003d\u003d \u0027\u0027);\n\n    // Map each value to a quoted version\n    let quotedValues \u003d values.map(val \u003d\u003e `\"${val.trim()}\"`);\n\n    // Join the quoted values with a comma separator\n    return quotedValues.join(\u0027,\u0027);\n}\n\nconst input \u003d getVariable(/*[variable]*/\"130a61db-76fa-43a3-a4d6-c15995ab8278\"/*[/variable]*/);\nlet outputUrls \u003d joinAndQuote(input);\nsetVariable(/*[variable]*/\"831b1a33-1f70-476e-a4bf-2330a41b96d3\"/*[/variable]*/, outputUrls)",
          "codeOnSuccess": "openUrl(\u0027http://YOUR_PYLOAD_IP_AND_PORT/\u0027, \u0027custom-tabs(org.mozilla.firefox)\u0027);",
          "description": "copy multiple URLs one under the other with newline between them",
          "headers": [
            {
              "id": "36ecf6d9-9b1d-416e-9529-5e7271d89db9",
              "key": "Host",
              "value": "YOUR_PYLOAD_IP_AND_PORT"
            },
            {
              "id": "1b540887-a26b-49ff-8a86-2405c9cd755a",
              "key": "Content-Type",
              "value": "application/x-www-form-urlencoded"
            }
          ],
          "iconName": "bitsies_folder",
          "id": "7cf27dff-0fb1-4e20-9b5c-9c78338022ca",
          "name": "pyload addPackage multiple copied",
          "responseHandling": {},
          "url": "http://YOUR_PYLOAD_IP_AND_PORT/api/addPackage?name\u003d\"{{bd1e41f7-78a6-4e73-97a3-b4a6093c028d}}\"\u0026links\u003d[{{831b1a33-1f70-476e-a4bf-2330a41b96d3}}]"
        }
      ]
    }
  ],
  "compatibilityVersion": 78,
  "variables": [
    {
      "flags": 1,
      "id": "c90d3c1c-822e-48e7-8b4d-4cf9407a8b66",
      "key": "shared_url"
    },
    {
      "id": "3b338082-c2be-48c8-9f5a-e975005b1208",
      "key": "pyloadsession",
      "value": "XUOutQp75K9jAgWy0bwWRbIJlOljyU9xs1wNXytS3OA"
    },
    {
      "id": "831b1a33-1f70-476e-a4bf-2330a41b96d3",
      "key": "finalUrls",
      "value": "\"https://somesite.com\""
    },
    {
      "id": "130a61db-76fa-43a3-a4d6-c15995ab8278",
      "key": "pastedUrls",
      "type": "clipboard"
    },
    {
      "data": "{\"select\":{\"multi_select\":\"false\",\"separator\":\",\"}}",
      "id": "bd1e41f7-78a6-4e73-97a3-b4a6093c028d",
      "key": "pyloadCategory",
      "options": [
        {
          "id": "9529e681-8036-4257-8413-1f27c4896a46",
          "value": "Movies"
        },
        {
          "id": "e3de0360-a063-40a5-ac83-2b62130abce1",
          "value": "Series"
        },
        {
          "id": "bcf22cec-2ac3-4423-8e42-8de73776ae4e",
          "value": "Tutorials"
        },
        {
          "id": "28db6935-6ab2-4989-912e-268d6e1f49c6",
          "value": "Music"
        },
        {
          "id": "230f057d-8bd5-46d3-add5-656b36940bb4",
          "value": "Ebooks"
        },
        {
          "id": "7d1a3619-3bd0-467d-ba9e-f5924ab82de8",
          "value": "Audiobooks"
        }
      ],
      "title": "Pick a category ",
      "type": "select"
    }
  ],
  "version": 81
}

This article makes a few assumptions. If you only have one URL to paste into pyload you use the "pyload addPackage" shortcut by long pressing the url on your browser and hitting "Share". If you have multiple URLs you have to copy them to your clipboard, one under the other with a newline (/n) between them. There is a short javascript that parses those links and adds them on a json list and then sends them to pyload.

For this whole process to work you have to have either a VPN connection to your pyload server or you expose it to the wider internet, which considering a CVE I saw the other day doesn't seem such a good idea. Being a self-hoster I'm guessing you already know what you're doing.