You’ll likely want to use JavaScript here to do your API call, using XMLHttpRequest, or the Fetch API, there’s some hints and samples on using this over on StackOverflow to get you started.
As for the Octopus-specific call, the easiest way to get the exact call you want is to open up the Network pane in your browser’s developer tools, and do what you would like to in the web UI, and watch what calls are being made to the API (The web UI uses the same API as you are attempting to use). You can also use the Swagger UI built into Octopus to see a list of endpoints available (https://YOUR_SERVER/swaggerui) and run calls against them.
Additionally, although they’re in PowerShell, you can make use of the samples in the OctopusDeploy-Api github repo to see what calls are being made in the various scripts, like this one.