Hi @rachel.dong
Thanks for your reply.
You are correct the Username + Password in Postman will likely be Base64 encoded, it may well do that part for you, but here when you are scripting yourself, you need to do it manually.
The answer to the Execution Location will depend on where the Groovy service REST API is hosted. If it’s as you mentioned at the start, and a SaaS product that is available in the cloud, and over the public internet, you can run the script on any deployment target or worker you like so long as the server where the script runs can connect to the API in question (including opening any firewall rules).
Let’s assume that the REST API can be connected to over the internet:
In your deployment process, you would add a PowerShell script step.
In the Execution Location, if you have no workers configured in your Octopus instance, you’d see something like this:
This allows you to run the script on the Octopus Server itself.
If you have a worker configured, choose the worker pool to run the script on:
As I shared before, run the script, substituting the username, password, and the URL to the REST API:
I’ve copied the script contents here, and taken the example Groovy REST API URL, you should replace that value with wherever the REST API you want to connect to is hosted:
# Step 1. Create a username:password pair
$credPair = "$($username):$($password)"
# Step 2. Encode the pair to Base64 string
$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair))
# Step 3. Form the header and add the Authorization attribute to it
$headers = @{ Authorization = "Basic $encodedCredentials" }
# Step 4. Make the request
$response = Invoke-RestMethod -Uri "https://transact.maguire.com/manager/secure/rest/groovy-service-invoke/v2/" -Headers $header -Method Get
From there, the $response
variable would contain details of the services. You are able to use that data however you wish.
I hope that helps.
Best regards,