Updating a StepTemplate in Octpus using APi

Hi,
I have created a new StepTemplate in Octopus using the API which works fine. But when I go to add parameters to the new Step Template it fails for ‘The remote server returned an error: (500) Internal Server Error.’ I have removed the Id in the first parameter and still fails. Any idea why this is happening?

This is my API call:
Invoke-RestMethod “$OctopusUrl/api/$($SpaceId)/actiontemplates/$($StepTemplateId)”

  • I am getting a $SpaceId and the $StepTemplateId and passing it in

My json object looks like:
$updateStepTemplate = @’
{
“Id”: “2c5cb210-608f-45f0-bf5f-065deffc207a”
“Name”: “Send Package to Artifactory”,
“Description”: “Send a package to Artifactory.”,
“ActionType”: “Octopus.Script”,
“Version”: 2,
“CommunityActionTemplateId”: null,
“Packages”: [],
“Properties”: {
“Octopus.Action.Script.ScriptSource”: “Inline”,
“Octopus.Action.Script.Syntax”: “PowerShell”,
},
“Parameters”: [
{
“Id”: ““2c5cb210-608f-45f0-bf5f-0837hkjf””
“Name”: “_packageOriginalFullName”,
“Label”: “Package Original Full Name”,
“HelpText”: “The full name and path of the package”,
“DefaultValue”: " #{Octopus.Action[Transfer Package].Output.Package.FilePath}",
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
}
},

Hi @mikepower79,

Thanks for getting in touch! I have some thoughts here but first I’ll note that we try to avoid using the Invoke-RestMethod over the Octopus.Client where possible. The Octopus.Client has been constructed to make managing Octopus through the API a nicer experience. There are quite a few places you can get caught when using raw REST with Octopus.

A few things to note regarding your above REST content.

  • You should not specify a version for the template as Octopus will automatically update the version when the new resources is pushed to the server. Supplying a version can confuse Octopus.
  • The Id could potentially be left blank in the parameter for Octopus to generate its own. (I’ve not tested that specifically with RestMethod.)
    The Id in the main Template body should be the the same as your $stepTemplateID (e.g. ActionTemplates-101)

There are quite a few places you can get caught when using raw REST with Octopus. In general, I like to use the Octopus.Client as you can return the data in the format Octopus expects it and use that as a reference to add or modify future resources.

Let me know how you go here, and if you have any further questions at all here, or get stuck, please don’t hesitate to let me know.

Best regards,
Daniel

Hi Daniel,
Is there not a simple way to import a Json file to create the Step Template.
Like in the UI when you select the import option:
image
My json file is:

Send Package to Artifactory.json (9.7 KB)

Hi Daniel,
Actually if I reference the json file it works.
$steptemplateJson = Get-Content “C:\temp\Send Package to Artifactory.json”
and then pass $steptemplateJson into my Invoke-Restmethod call.

Micheal

Hi Micheal,

Thanks for the update here! I’m glad to hear that you have this working with the raw rest! There is a big handful of gotcha’s when using rest directly that often make it much easier to use the Octopus.Client.

Though if you have this working successfully without the client, then that’s excellent news. :slight_smile:

If you have any further thoughts or questions on this, please don’t hesitate to let me know.

Best regards,
Daniel

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