Simon
11/30/2021, 2:43 PMAlan Fitch
11/30/2021, 2:52 PMAlan Fitch
11/30/2021, 2:53 PMAlan Fitch
11/30/2021, 2:53 PMAlan Fitch
11/30/2021, 2:54 PMSimon
11/30/2021, 2:55 PMdynamicl
11/30/2021, 3:08 PMSimon
11/30/2021, 3:13 PMscottvonduhn
11/30/2021, 3:24 PMSimon
11/30/2021, 3:28 PMbattk
11/30/2021, 3:28 PMbattk
11/30/2021, 3:29 PMSimon
11/30/2021, 3:29 PMbattk
11/30/2021, 3:29 PMdynamicl
11/30/2021, 4:00 PMdynamicl
11/30/2021, 4:00 PMcls
Add-Type -AssemblyName System.Web
## USER SETTINGS START ##############################################################################################
$nsUrlInstanceName = "" #example: 12345-SB1
$nsRealm = "" #example: 12345_SB1
$nsDeployId = "" #example: 1
$nsScriptId = "" #example: 123
$oauth_consumer_key = ""
$oauth_consumer_secret = ""
$oauth_token = ""
$oauth_token_secret = ""
## USER SETTINGS END ##############################################################################################
function EncodeToUpper
{
param($value)
return $value.Replace("%2a","%2A").Replace("%2b","%2B").Replace("%2c","%2C").Replace("%2d","%2D").Replace("%2e","%2E").Replace("%2f","%2F").Replace("%3a","%3A").Replace("%3b","%3B").Replace("%3c","%3C").Replace("%3d","%3D").Replace("%3e","%3E").Replace("%3f","%3F")
}
$oauth_nonce = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes([System.DateTime]::Now.Ticks.ToString()))
$oauth_timestamp = [long](([datetime]::UtcNow)-(Get-Date "1970-01-01")).TotalSeconds
$baseUrl = 'https://'+$nsUrlInstanceName+'.<http://restlets.api.netsuite.com/app/site/hosting/restlet.nl|restlets.api.netsuite.com/app/site/hosting/restlet.nl>'
$fullUrl = $baseUrl + '?script='+$nsScriptId+'&deploy='+$nsDeployId
$baseUrlEncoded = [System.Web.HttpUtility]::UrlEncode($baseUrl)
$baseUrlEncoded = EncodeToUpper $baseUrlEncoded
#sort param names lexicographically
$params = "deploy=$nsDeployId&oauth_consumer_key=$oauth_consumer_key&oauth_nonce=$oauth_nonce&oauth_signature_method=HMAC-SHA256&oauth_timestamp=$oauth_timestamp&oauth_token=$oauth_token&oauth_version=1.0&script=$nsScriptId"
$paramsEncoded = [System.Web.HttpUtility]::UrlEncode($params)
$paramsEncoded = EncodeToUpper $paramsEncoded
$message = 'GET&'+$baseUrlEncoded+'&'+$paramsEncoded
$key = $oauth_consumer_secret + "&" + $oauth_token_secret
$hmac = New-Object System.Security.Cryptography.HMACSHA256
$hmac.Key = [System.Text.Encoding]::ASCII.GetBytes($key)
$signature = [System.Convert]::ToBase64String($hmac.ComputeHash([System.Text.Encoding]::ASCII.GetBytes($message)))
$signature = [System.Web.HttpUtility]::UrlEncode($signature)
$signature = EncodeToUpper $signature
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("Authorization", 'OAuth realm="'+$nsRealm+'", oauth_consumer_key="'+$oauth_consumer_key+'", oauth_token="'+$oauth_token+'", oauth_signature_method="HMAC-SHA256", oauth_timestamp="'+$oauth_timestamp+'", oauth_nonce="'+$oauth_nonce+'", oauth_version="1.0", oauth_signature="'+$signature+'"')
$response = Invoke-RestMethod $fullUrl -Method 'GET' -Headers $headers
$response | ConvertTo-Json
Simon
11/30/2021, 4:03 PMscottvonduhn
11/30/2021, 4:09 PMscottvonduhn
11/30/2021, 4:11 PMSimon
11/30/2021, 4:12 PMscottvonduhn
11/30/2021, 4:15 PMscottvonduhn
11/30/2021, 4:15 PMSimon
11/30/2021, 4:16 PMscottvonduhn
11/30/2021, 4:18 PMscottvonduhn
11/30/2021, 4:20 PMSimon
11/30/2021, 4:23 PMscottvonduhn
11/30/2021, 4:27 PM