Last active
November 9, 2022 19:22
-
-
Save ctigeek/b641168a39a6a4c4629d to your computer and use it in GitHub Desktop.
Creates an X-Api-Signature for making a REST API Call.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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