PowerShell: Checking the status of domain registration with Openprovder

Building on top of what I did yesterday we can now move onto some of the more interesting parts of the Openprovider API

Now we can get in we want to check if a domain is registered or not.



function Get-BearereCreds
{
$EndPoint = "https://api.openprovider.eu/v1beta/auth/login"

##Configure Payload
$Body = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$Body.Add("ip","0.0.0.0") 
$Body.Add("username","UsernameHere") 
$Body.Add("password","PasswordHerePlease") 
$Body = $Body | ConvertTo-Json

$Bearer = (Invoke-RestMethod -Method Post -Uri $EndPoint -body $Body -ContentType 'application/json' ).data
return $Bearer
}

function check-domain
{
 Param(
    [parameter(Mandatory=$true)]
    [String]$Domains 
    )

$uri = "https://api.openprovider.eu/v1beta/domains/check"
$DomlistArray = @()
$bearcreds = Get-BearereCreds

$IdnScript = [pscustomobject]@{
idn_scrypt = "cyrl"}

Foreach ($Domain in $Domains)
{
$TLD = $Domain.Substring($Domain.IndexOf(".") + 1)
$DomName = ($domain.Split("."))[0]

$Domlist = [pscustomobject]@{
extension = $TLD
name = $DomName}
$DomListArray = $DomListArray + $DomList

}

$DomBody = [pscustomobject]@{
additional_data = $IdnScript
application_mode = "preregistration"
domains = $DomListArray
with_price = $true }
$DomBodyJson = $DomBody | ConvertTo-Json

$Bearer = Get-BearereCreds

$Domheader = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$Domheader.Add("Authorization","Bearer " +  $bearcreds.token) 

$Result = Invoke-RestMethod -Method Post -Uri $uri -Headers $Domheader -body $DomBodyJson -ContentType 'application/json'

return $Result.data.results
}

This function will do that for you. You use it like this

PS C:\Users\Mat_Grump> check-domain -Domains test0987.com

domain       status price                 
------       ------ -----                 
test0987.com free   @{product=; reseller=}

Or if you want to see how much it would cost to register the domain

PS C:\Users\Mat_Grump> (check-domain -Domains test0987.com).price

product                     reseller                   
-------                     --------                   
@{price=8.03; currency=USD} @{price=6.08; currency=GBP}