Jump to content

API add password with GenericField and Description error


hakan

Recommended Posts

Hi

 

I got this error when trying to add a password with additional fields:

Invoke-Restmethod : [{"errors":[{"message":"Invalid API Call"},{"phrase":"Error = Object reference not set to an instance of an object.}]}]
At line:60 char:15
+ ...   $result = Invoke-Restmethod -Method Post -Uri $PasswordstateUrl -Co ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

 

My code I try to execute is :

$ServerName = 'my ServerName'
$Title = 'My title'
$UserName = 'my UserName'
$Description = 'my description'
$AccountType = 'MS SQL Server'

$jsonData = '
    {
        "PasswordListID":"39",
        "Title": "'+$ServerName+' '+$Title+'",
        "GenericField1":'+$ServerName+'",
        "Description":'+$Description+'",
        "UserName":"'+$UserName+'",
        "password":"'+$passwordState+'",
        "APIKey":"my api key"

    $PasswordstateUrl = 'https://passwordstate/api/passwords'
    $result = Invoke-Restmethod -Method Post -Uri $PasswordstateUrl -ContentType "application/json" -Body $jsonData

    }
    '

 

If I remove "GenericField1":'+$ServerName+'", "Description":'+$Description+'",

 

the script is working

 

Thanks 

hakan

Link to comment
Share on other sites

Hi Hakan,

 

Sorry you're having some issues with this. Can you let us know what Build of Passwordstate you're using, and we'll do some testing to see if we can reproduce the issue?

I assume this Password List also had the Generic Field selected, and can you tell is what type of field it is i.e. text, password, date, etc?

Thanks

Click Studios

Link to comment
Share on other sites

Maybe it's what you've pasted here, but it also doesn't look like you've closed off the $jsonData variable properly. It should be:

 

$jsonData = '
    {
        "PasswordListID":"39",
        "Title": "'+$ServerName+' '+$Title+'",
        "GenericField1":'+$ServerName+'",
        "Description":'+$Description+'",
        "UserName":"'+$UserName+'",
        "password":"'+$passwordState+'",
        "APIKey":"my api key"
}
'
Link to comment
Share on other sites

Thanks, and I can see the issue now - I just tested this also:

  • You have your Invoke-RestMethod inside the json object - although you probably have moved this out by now
  • And the GenericField1 and Description fields do not have a double quote before the single quote for your PowerShell variables i.e. should be "GenericField1":"'+$ServerName+'", instead of "GenericField1":'+$ServerName+'",

I know it's hard to see in this forum, but cut and paste the text above and you will see what I mean.

Regards

Click Studios

Link to comment
Share on other sites

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...