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,

    Since Otter does not have a native api to upload a script, can we get a working example for Rafts_CreateOrUpdateRaftItem to perform this action to a subfolder? Our goal is to have an automated job push a script upon success.

    Thanks,
    Scott


  • inedo-engineer

    Hi @scusson_9923 ,

    Here's a one-liner that should hopefully get you started.

    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([System.Text.Encoding]::UTF8.GetBytes("'hello world'"))
    }
    

    The RaftItemType_Code=4 is not documented, but it's a fixed value and means a script. I recommend creating the item manually first, then looking in the RaftItems table for the Raft_Id and RaftItemType_Code values.

    Cheers,
    Alana



  • @atripp Hi Alana. Thanks! I'll try it out.



  • 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


  • inedo-engineer

    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?

    8565717e-dba8-4603-af4d-a18261eaa7a6-image.png

    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


  • inedo-engineer

    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


  • inedo-engineer

    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


Log in to reply
 

Inedo Website HomeSupport HomeCode of ConductForums GuideDocumentation