Method Not Allowed Querying API

Hi, I was adjusting a community script that pushes to Slack so I could add machine names in the deployment. I borrowed part of a script from this help article. I was able to use that script from the article, replacing the Octopus.Deployment.Machines variable with a simple array Machines-192 on the actual Octopus server and the script ran fine. But when I run it from Octopus and specify that it should be run on the server I get a 405, Method Not Allowed error. Here’s my adjusted script (apikey and uri are not the same as my script)–

$deployMachines = "#{Octopus.Deployment.Machines}" 
Add-Type -Path 'C:\Program Files\Octopus Deploy\Octopus\Octopus.Client.dll' 

$apikey = 'API-Key' 
$octopusURI = ''

$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 
$repository = New-Object Octopus.Client.OctopusRepository $endpoint

$machineIds = $deployMachines.Split(',')
$tempArray = @()

foreach ($machineId in $machineIds) {
    Write-Host "Checking for $machineId"
    $machine = $repository.Machines.Get($machineId)
    $tempArray += $machine.Name

$machines = $tempArray -join ","

$message = $OctopusParameters['ssn_Message'] -replace "Link:", "Machines: $machines\nLink:"

$payload = @{
    channel = $OctopusParameters['ssn_Channel'];
    username = $OctopusParameters['ssn_Username'];
    icon_url = $OctopusParameters['ssn_IconUrl'];
    attachments = @(
            mrkdwn_in = $('pretext', 'text');
            pretext = $OctopusParameters['ssn_Title'];
            text = $message;
            color = $OctopusParameters['ssn_Color'];

try {
    [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
    Invoke-Restmethod -Method POST -Body ($payload | ConvertTo-Json -Depth 4) -Uri $OctopusParameters['ssn_HookUrl']
} catch {
    Write-Host "An error occurred while attempting to send Slack notification"
    Write-Host $_.Exception
    Write-Host $_
    exit 0

Stacktrace is–

An error occurred while attempting to send Slack notification 
April 19th 2018 21:42:34Info
System.Net.WebException: The remote server returned an error: (405) Method Not Allowed. 
April 19th 2018 21:42:34Info
   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) 
April 19th 2018 21:42:34Info
   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() 
April 19th 2018 21:42:34Info
The remote server returned an error: (405) Method Not Allowed. 

Can you anyone advise what I might be doing wrong?

This can be closed. It’s not an Octopus issue. I sat on it overnight and realized there’s an issue with my slack message. Will handle this on my own.

Hi Tony,

Thanks for getting in touch! That’s great to hear you’ve narrowed down the issue. Please don’t hesitate to reach out if you have any further questions or concerns going forward. :slight_smile:

Best regards,


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.