Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.
If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!
Working Rafts_CreateOrUpdateRaftItem example for Otter
-
Hi,
When I try your example, I get the error 'Invalid value for "Content_Bytes": Invalid cast from 'System.String' to 'Inedo.Data.VarBinaryInput''.Also, when I add a text file under Scripts, in my case .yml, it gets added as binary. I can't see a way to change this.
Thanks,
Scott -
Hi @scusson_9923 ,
Is this the latest version of Otter? "It worked on my machine" without an issue, so I wonder if there is a change somehow.
Are you able to upload the .yaml file in the way you want in the UI? What type shows up when you do that? I would expect you select like this?

The RaftItemType_Code for Text is 7.
Alana
-
Hi,
I'm on 2024.1. In this instance, I use Add Script->Upload Scripts & Assets because I already have the file on disk. I will use the "Create a Blank Script" method as a workaround.Also, can you provide an example of uploading a file from disk?
Thanks!
Scott -
Hi @scusson_9923 ,
This code should work for a file on disk; it's same as before, but uses GetBytes...
Invoke-WebRequest -Method Post -Uri "http://otter.localhost/api/json/Rafts_CreateOrUpdateRaftItem" -Body @{ API_Key = "abc123" Raft_Id = 1 RaftItemType_Code = 4 RaftItem_Name = "mypath/myscript.ps1" ModifiedOn_Date = Get-Date ModifiedBy_User_Name = "API" Content_Bytes = [System.Convert]::ToBase64String([IO.File]::ReadAllBytes("c:\myfile.txt")) } -
Hi,
Thanks for the example. However, I still get the error 'Invalid value for "Content_Bytes": Invalid cast from 'System.String' to 'Inedo.Data.VarBinaryInput'' with this body:
API_Key = "xxxxx" Raft_Id = 1 RaftItemType_Code = 4 RaftItem_Name = "JobConfigs/test.yml" ModifiedOn_Date = Get-Date ModifiedBy_User_Name = "scusson" Content_Bytes = [System.Convert]::ToBase64String([IO.File]::ReadAllBytes("D:\foo\bar\test.yml"))It appears that the .yml is being detected as binary?
Scott
-
Hi @scusson_9923 ,
The
Invalid cast from 'System.String' to 'Inedo.Data.VarBinaryInput''isn't related to the content of the file, it's just a problem with wiring up the API to database. Basically a bug.I don't know why it works on my machine, but not in your instance. It's one of those "deep in the code" things that we'd have to investigate.
Maybe try upgrading to latest version of Otter? I suspect there was a library upgrade/fix that might make this work.
Thanks,
Alana -
Hi Alana,
I updated my instance to 2024.2 and still get the same error.
Thanks,
Scott -
Hi @scusson_9923 ,
This seems to be an issue related to release vs debug builds (works fine locally, but not when deplyoed to server), and we'll investigate and fix via OT-517 in an upcoming maintenance release (2024.4) - not sure on the exact schedule, but we're targeting the next couple weeks
-- Dean
-
@dean-houston Thanks!
-
Hi Scott,
This fix will be included in tomorrow's release (2024.4).
Thanks!
-
Hi,
This functionality is fixed in 2024.4. However, the script gets created as type "Unknown". How can this be set and what types are valid?
Thanks,
Scott -
Hi @scusson_9923 ,
What is the file you are uploading? What happens when you upload through the UI?
Can you share the PowerShell snippet you're using?
What are you specifying for
RaftItemType_Code?-- Dean
-
Hi Dean,
Here is what I'm running:
Invoke-WebRequest -Method Post -Uri "https://<otter_server>/api/json/Rafts_CreateOrUpdateRaftItem" -Body @{
API_Key = "<apikey>"
Raft_Id = 1
RaftItemType_Code = 4
RaftItem_Name = "JobConfigs/test.yml"
ModifiedOn_Date = Get-Date
ModifiedBy_User_Name = "scusson"
Content_Bytes = [System.Convert]::ToBase64String([IO.File]::ReadAllBytes("D:\test.yml"))
}If I add the text file (test.yml) thru the UI, it gets added as binary.
Thanks,
Scott -
Hi @scusson_9923,
In this case, you'll likely want to select
5as the type.For reference, here are the valid types:
// // Summary: // Specifies the type of a raft item. // // Remarks: // All types except BinaryFile and TextFile are "regulated" and only allow well-known // files; for example, public enum RaftItemType { // // Summary: // A role configuration plan. RoleConfigurationScript = 1, // // Summary: // [Uninclused] A Script with .otter syntax is prefered OrchestrationPlan = 2, // // Summary: // [Uninclused] A Script with .otter syntax is prefered Module = 3, // // Summary: // A script. Script = 4, // // Summary: // An unclassified binary file. // // Remarks: // BinaryFiles cannot be edited in a text editor, compared, etc; they are always // treated as raw content BinaryFile = 5, // // Summary: // A deployment plan. DeploymentScript = 6, // // Summary: // An unclassified text file. // // Remarks: // TextFiles can be edited in UI , may have lines replaced on deploy, and can be // used as templates TextFile = 7, // // Summary: // A pipeline. Pipeline = 8, // // Summary: // [Uninclused] Feature is deprecated ReleaseTemplate = 9, // // Summary: // A job template. JobTemplate = 10, // // Summary: // Files used with build tools like Dockerfile. BuildFile = 11 }I'm not sure if TextFile (7) will work; in Otter it was intended to be used as a text template, which means lines in it are replacement. You may need to play around and see what works.
-- Dean
-
Hi Dean,
Setting RaftItemType_Code = 7 in this instance worked for me. Appreciate the list of valid types. Thanks for all of your help!
Scott
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login