Use REST API in a webpage form

external
usability
(Lucio Falco) #1

Hi,
sorry but this is something I have never done before:

  • I have an Octopus project;
  • An API-KEY (with the right permission to deploy the project’s release - right space);
  • 3 required variables for the above release (var1, var2, test - all strings type).

I have created a webpage with 3 simple textboxes and a submit button.
I don’t know the code I should put under the submit action event. :pensive:

PS: the release is deployed fine when I use Octo.exe or the Octopus.Client.dll. I think I am not familiar with html requests (?) and the json files.

Could you please show me an example?
I haven’t been able to find anything useful in the REST API examples/documentation.

Thank you for your time,
Kind Regards.
Lucio

(Justin Walsh) #2

Hi @Lucio_Falco1.

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.