Create a gist now

Instantly share code, notes, and snippets.

Creates an X-Api-Signature for making a REST API Call.
function Get-XapiSignature($userAgent, $apiKey, $apiSecret) {
$dateTime = [DateTime]::UtcNow.ToString("yyyyMMddHHmmss");
$dataToSign = [String]::Format("{0}{1}{2}{3}", $apikey, $userAgent, $dateTime, $apiSecret);
$sha1 = [System.Security.Cryptography.SHA1]::Create();
$signedBytes = $sha1.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($dataToSign));
$signature = [System.Convert]::ToBase64String($signedBytes);
$sha1.Dispose()
[String]::Format("{0}:{1}:{2}", $apikey, $dateTime, $signature);
}
$apiKey = "wxwgtpxWigsBwSIbofT1"
$apiSecret = "Rxqjp7k4NLi/1l0CopFLgpMf7rPJYkU9wmSOwKjs"
$userAgent = "Powershell"
$server = "https://api.emailsrvr.com"
$url = "/v1/domains"
$address = $server+$url
$signature = Get-XapiSignature $userAgent $apiKey $apiSecret
$header = @{ "User-Agent"=$userAgent; "Accept"="application/json"; "X-Api-Signature"=$signature }
$domains = Invoke-RestMethod -Uri $address -Method Get -Headers $header
$domains.domains | ft
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment