# PowerShell Integration with Openprovider API

If you are interested in accessing and using the Openprovider API via PowerShell, you can find useful information here.

## Authenticating to the Openprovider API via PowerShell

The Openprovider API uses Bearer authentication. You authenticate once with your username and password and are given a bearer code. You then use the bearer code for the rest of your API calls.

Here is an example of what this looks like in PowerShell:

```powershell
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","PasswordPlease") 
$Body = $Body | ConvertTo-Json

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

$Bearer = Get-BearereCreds
```

Keep in mind that the bearer code expires after a set time. When you want to perform scheduled tasks or tasks that take a long time, you will need to periodically request a new bearer code.

## Checking the status of domain registration via PowerShell

Here is an example of how to request the status of a domain registration:

```
function Get-BearereCreds<br></br>{<br></br>$EndPoint = "https://api.openprovider.eu/v1beta/auth/login"<br></br><br></br>##Configure Payload<br></br>$Body = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"<br></br>$Body.Add("ip","0.0.0.0") <br></br>$Body.Add("username","UsernameHere") <br></br>$Body.Add("password","PasswordHerePlease") <br></br>$Body = $Body | ConvertTo-Json<br></br><br></br>$Bearer = (Invoke-RestMethod -Method Post -Uri $EndPoint -body $Body -ContentType 'application/json' ).data<br></br>return $Bearer<br></br>}<br></br><br></br>function check-domain<br></br>{<br></br>Param(<br></br>[parameter(Mandatory=$true)]<br></br>[String]$Domains <br></br>)<br></br><br></br>$uri = "https://api.openprovider.eu/v1beta/domains/check"<br></br>$DomlistArray = @()<br></br>$bearcreds = Get-BearereCreds<br></br><br></br>$IdnScript = [pscustomobject]@{<br></br>idn_scrypt = "cyrl"}<br></br><br></br>Foreach ($Domain in $Domains)<br></br>{<br></br>$TLD = $Domain.Substring($Domain.IndexOf(".") + 1)<br></br>$DomName = ($domain.Split("."))[0]<br></br><br></br>$Domlist = [pscustomobject]@{<br></br>extension = $TLD<br></br>name = $DomName}<br></br>$DomListArray = $DomListArray + $DomList<br></br><br></br>}<br></br><br></br>$DomBody = [pscustomobject]@{<br></br>additional_data = $IdnScript<br></br>application_mode = "preregistration"<br></br>domains = $DomListArray<br></br>with_price = $true }<br></br>$DomBodyJson = $DomBody | ConvertTo-Json<br></br><br></br>$Bearer = Get-BearereCreds<br></br><br></br>$Domheader = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"<br></br>$Domheader.Add("Authorization","Bearer " + $bearcreds.token)<br></br><br></br>$Result = Invoke-RestMethod -Method Post -Uri $uri -Headers $Domheader -body $DomBodyJson -ContentType 'application/json'<br></br><br></br>return $Result.data.results<br></br>}
```

### Credits

We've drafted this article using the following sources:

- [PowerShell: Authenticating to the Openprovider API](https://grumpy.tech/powershell-authenticating-to-the-openprovider-api/)
- [PowerShell: Checking the status of domain registration with Openprovider](https://grumpy.tech/powershell-checking-the-status-of-domain-registration-with-openprovder/)

We thank the author of these sources for sharing their knowledge with us, to help the Openprovider community enjoy all the possibilities of the Openprovider API.