Jump to content
hakan

API add password with GenericField and Description error

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

Share this post


Link to post
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

Share this post


Link to post
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"
}
'

Share this post


Link to post
Share on other sites

Hi

 

it´s V8.2 (Build 8242) and our GenericField1 is used för computername.

 

Sorry I missed the ending brackets, I have thoose in my code

 

 }
    '

 

Regards

Hakan

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...