njordur Posted November 20, 2017 Share Posted November 20, 2017 Hi, Can you fix so the whenever you use the API to create a password and the password has a $ sign in it truncates the rest of the password set in passwordstate. I proably can fix this with modifications in my script. But just wanted to have this so I wouldn't have to. Example of a powershell script, works fine if there are no $ signs in the password. Probably the same happens with other parameters. param($username, $password, $description) $jsonString = @" { "PasswordListID":92, "Title":"company\\$username", "Description":"$description", "AccountTypeID":64, "UserName":"$username", "password":"$password", "APIKey":"XXXXXXXXXXXXXXXXXXXXXXXX", "PasswordResetEnabled":true, "PrivilegedAccountID":2, "HeartbeatEnabled":true, "ValidationScriptID":7, "ADDomainNetBIOS":"company" } "@ Invoke-RestMethod -Uri https://passwordstate.company.com/api/passwords/ -Method Post -ContentType "application/json" -Body $jsonString Link to comment Share on other sites More sharing options...
support Posted November 20, 2017 Share Posted November 20, 2017 Hi Njordur, Unfortunately we don't think we can change the API to accomodate for this, but we do have a fix for you to update your scripts. I've given an exact example below which works, and an explanation below that of what you need to change: # Begin Script param( $username, $password, $description ) $jsonString = ' { "PasswordListID":9914, "Title":"company\\' + $username + '", "Description":"' + $description + '", "AccountTypeID":82, "UserName":"' + $username + '", "password":"' + $password + '", "APIKey":"63fca2537db89e4fb32954234532455", "PasswordResetEnabled":true, "PrivilegedAccountID":2044, "HeartbeatEnabled":true, "ValidationScriptID":9, "ADDomainNetBIOS":"halox" } " ' Invoke-RestMethod -Uri https://alien.halox.net/api/passwords/ -Method Post -ContentType "application/json" -Body $jsonString # End Script Things I changed: 1. The opening brackets of the JSON string $jsonString = @" to $jsonString = ' 2. the variables inside the jsons string are now enclosed with a single quote and + symbol. So we went from "UserName":"$username" to "UserName":"' + $username + '" 3. the closing brackets of the JSON went from }"@ to }' I hope this is not too much trouble to change your scripts, and we hope this helps! Regards, Support. njordur 1 Link to comment Share on other sites More sharing options...
Fabian Näf Posted November 22, 2017 Share Posted November 22, 2017 Hi All I'm not sure if this helps (I had no time to test it). I usually create the JSON as following: Create a Powershell Object, then convert it to JSON. If you do it like this, then you dont have to struggle with the string-creation. $Body = @{ PasswordList = $Name Description = $Description ApplyPermissionsForUserID = $global:UserToPermit CopySettingsFromTemplateID = $global:PasswordstateTemplateID LinkToTemplate = "False" Permission = "A" PrivatePasswordList = "false" NestUnderFolderID = $ParentFolderID APIKey = $global:PasswordStateSystemWideAPIKey } $jsonBody = $Body | ConvertTo-Json (just an example, it doesn't fit to your requirement) Best regards, Fabian njordur 1 Link to comment Share on other sites More sharing options...
support Posted November 22, 2017 Share Posted November 22, 2017 Thanks Fabian Link to comment Share on other sites More sharing options...
njordur Posted December 4, 2017 Author Share Posted December 4, 2017 Thanks for this, didn't solve the input problem though. I just excluded $ from the input so I don't have to handle it. Nice touch with the psobject, will use that. /Njörður Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now