Jump to content

API Create Password with $ in it


njordur

Recommended Posts

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

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...