Challenge:
I’m a big fan of SearchStax as it removes all challenges to install, configure and manage Solr and let experts do experts job!
To set up Solr Collections: I always prefer to use Search Stax Plugin: https://github.com/searchstax/searchstax-sitecore-plugin
I made a mistake once where I had a typo in my config.yml and It uploaded config with the wrong name. (Garbage IN, Garbage OUT) Which I wanted to delete. But there was no way to do this via the plugin. So, I had to write a power shell using Search Stax API to do it and thought to share it with you!
Solution:
Disclaimer: I’m not yet proficient in Powershell. So, feel free to modify this script if you are Powershell NINJA!
You need to provide few values in the script and you should be good!
# "Please provide authentication information."
$uname = Read-Host – Prompt ' Username – '
$password = Read-Host – AsSecureString – Prompt ' Password – '
$password = [Runtime.InteropServices.Marshal ]::PtrToStringAuto([Runtime.InteropServices.Marshal ]::SecureStringToBSTR($password ))
Write-Host " Asking for an authorization token for $uname …"
Write-Host
$body = @ {
username = $uname
password = $password
}
Remove-Variable PASSWORD
$body = $body | ConvertTo-Json
try {
$token = Invoke-RestMethod – uri " https://app.searchstax.com/api/rest/v2/obtain-auth-token/ " – Method Post – Body $body – ContentType ' application/json'
$token = $token.token
Remove-Variable body
Write-Host " Obtained token" $token
Write-Host
$searchstaxUrl = ' https://app.searchstax.com '
$ACCOUNT = ' TODO' # <- CHANGE YOUR VALUE HERE
$uid = ' TODO' # <- CHANGE YOUR VALUE HERE
$NAME = ' sitecore_sitecore' # <- CHANGE YOUR VALUE HERE
$headers = New-Object " System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add (" Authorization" , " Token $token " )
# Delete Config
$RESULTS = Invoke-RestMethod – Method Delete – Headers $headers `
– uri " https://app.searchstax.com/api/rest/v2/account/ $ACCOUNT /deployment/$uid /zookeeper-config/$NAME /"
$RESULTS = $RESULTS | ConvertTo-Json
# return $token
} catch {
Write-Error – Message " Unable to get Auth Token. Error was: $_ " – ErrorAction Stop
}
You can find API Documentation from here : https://www.searchstax.com/docs/staxapi2ZK/#zkdelete
Like this: Like Loading...
Related
Leave a Reply