Jump to content

Can't Delete a password with WebApi


Recommended Posts

Hi, I'm attempting to setup a powershell script to delete a password that I have created within a list, but I'm am having trouble with the documentation for this particular item.

http://www.clickstudios.com.au/api/#DeletePassword

When I read this there is no reference to the passwordId that I am actually trying to delete.

 


Invoke-WebRequest : [{"errors":[{"message":"Invalid API Call"},{"phrase":"Error = Object reference not set to an instance of an object.}]}]

At H:\devl\paulfa\PasswordState.ps1:51 char:5

+     Invoke-WebRequest -Uri $passwordRequest -Method DELETE -Body $postParams

+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException

    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
 
when I attempt to call invoke the Api I get an error
 

Invoke-WebRequest : [{"errors":[{"message":"Invalid API Call"},{"phrase":"Error = Object reference not set to an instance of an object.}]}]

At H:\devl\paulfa\PasswordState.ps1:51 char:5

+     Invoke-WebRequest -Uri $passwordRequest -Method DELETE -Body $postParams

+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException

    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
 
Is there something simple that I am missing?
Link to post
Share on other sites

Hi Paul,

 

Can you try something like the PowerShell script below - I just tested this and it worked in our environment. Replace the URL, PasswordID and API Keys as appropriate.

 

$PasswordstateAPIURL = 'https://<yoururl>/api/passwords/59967?MoveToRecycleBin=True'
Invoke-Restmethod -Method Delete -Uri $PasswordstateAPIURL -Header @{ "APIKey" = "9e537a6cdf2b834daf8354236c79eb63" }
Let us know if this works for you or not.
 
Regards
Click Studios
Link to post
Share on other sites
  • 6 months later...

Hello, I'm having the same issue as Paul above, only the solution you gave him does not work for me. 

I'm using version 7086 at our office with Powershell. 

The code I'm using to delete a password is as follows:


Invoke-Restmothod : [{"errors":[{"Messsage":"Invalid API call"}, {"Phrase":"Error = Object reference not set to an instance of an object."}]}]

This follows the same logic I

I've been using to create new passwords, along side what is on the API. However, running this the result:
 


Invoke-Restmothod : [{"errors":[{"Messsage":"Invalid API call"}, {"Phrase":"Error = Object reference not set to an instance of an object."}]}]

Link to post
Share on other sites

Hi,

 

Sorry you've having this issue. I can see a couple of issues with your script, and hopefully the following will help:

  • You cannot specify details in the BODY of the HTTP request, then need to be in the QueryString - as per the example below
  • The PasswordListID value is not required here, only the PasswordID value

Can you try it in the format below and let me know if it errors at all?

$PasswordstateAPIURL = 'https://<yoururl>/api/passwords/59967?MoveToRecycleBin=True'
Invoke-Restmethod -Method Delete -Uri $PasswordstateAPIURL -Header @{ "APIKey" = "9e537a6cdf2b834daf8354236c79eb63" }

Regards

Click Studios

Link to post
Share on other sites

Hi,

 

Sorry you've having this issue. I can see a couple of issues with your script, and hopefully the following will help:

  • You cannot specify details in the BODY of the HTTP request, then need to be in the QueryString - as per the example below
  • The PasswordListID value is not required here, only the PasswordID value

Can you try it in the format below and let me know if it errors at all?


      $DEL_HEADER = @{

            "APIKey"=$APIKEY

        }



        $API_URL = "$PASSWORDSTATE_SERVER/api/passwords/$ID_No?MoveToRecyleBin=True"

        Invoke-Restmethod -Method DELETE -Uri $API_URL -Header $DEL_HEADER 

Regards

Click Studios

 

Hi, I have tried out the solution you have suggested as shown below, but I'm afraid it still invokes the same error.


      $DEL_HEADER = @{

            "APIKey"=$APIKEY

        }



        $API_URL = "$PASSWORDSTATE_SERVER/api/passwords/$ID_No?MoveToRecyleBin=True"

        Invoke-Restmethod -Method DELETE -Uri $API_URL -Header $DEL_HEADER 

Link to post
Share on other sites

Hi,

 

After a bit of testing with your script, we have a solution - one of the problems was that your had MoveToRecycleBin spelt incorrectly.

 

$PASSWORDSTATE_SERVER = "https://<Your_URL>"
$APIKEY = "<Your_APIKey>"
$ID_No = "<Your_PasswordID"

URL Example 1
$API_URL = "{0}/api/passwords/{1}?MoveToRecycleBin=True" -f $PASSWORDSTATE_SERVER, $ID_No

URL Example 2
$API_URL = "$PASSWORDSTATE_SERVER/api/passwords/" + $ID_No + "?MoveToRecycleBin=True"

Invoke-Restmethod -Method Delete -Uri $API_URL -Header @{ "APIKey" = $APIKEY } 

I've provided two examples of the URL formatting, and you can choose which ever one is easier for your to read.

Regards

Click Studios

Link to post
Share on other sites

 

Hi,

 

After a bit of testing with your script, we have a solution - one of the problems was that your had MoveToRecycleBin spelt incorrectly.

 


$PASSWORDSTATE_SERVER = "https://<Your_URL>"

$APIKEY = "<Your_APIKey>"

$ID_No = "<Your_PasswordID"



URL Example 1

$API_URL = "{0}/api/passwords/{1}?MoveToRecycleBin=True" -f $PASSWORDSTATE_SERVER, $ID_No



URL Example 2

$API_URL = "$PASSWORDSTATE_SERVER/api/passwords/" + $ID_No + "?MoveToRecycleBin=True"



Invoke-Restmethod -Method Delete -Uri $API_URL -Header @{ "APIKey" = $APIKEY } 

I've provided two examples of the URL formatting, and you can choose which ever one is easier for your to read.

Regards

Click Studios

 

Thank you, yes spelling "MoveToRecycleBin" properly would probably help me in my future code. Thank you for catching that, although it wasn't the problem. 

The first example you gave me does work, although I'm not entirely sure why it does over the previous method you suggested. 

Thank you for your help!

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