hakan Posted June 7, 2018 Share Posted June 7, 2018 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 More sharing options...
support Posted June 7, 2018 Share Posted June 7, 2018 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 More sharing options...
support Posted June 7, 2018 Share Posted June 7, 2018 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 More sharing options...
hakan Posted June 7, 2018 Author Share Posted June 7, 2018 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 Link to comment Share on other sites More sharing options...
support Posted June 7, 2018 Share Posted June 7, 2018 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 GBS-IT and hakan 2 Link to comment Share on other sites More sharing options...
hakan Posted June 8, 2018 Author Share Posted June 8, 2018 It working thanks for great support Link to comment Share on other sites More sharing options...
support Posted June 8, 2018 Share Posted June 8, 2018 Thanks Hakan 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