Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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);
[String]::Format("{0}:{1}:{2}", $apikey, $dateTime, $signature);
$apiKey = "wxwgtpxWigsBwSIbofT1"
$apiSecret = "Rxqjp7k4NLi/1l0CopFLgpMf7rPJYkU9wmSOwKjs"
$userAgent = "Powershell"
$server = ""
$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
$ | ft
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.