Scot Sunnergren
02/08/2021, 4:21 PMMarc Reicher
02/08/2021, 5:29 PMScot Sunnergren
02/08/2021, 7:11 PMScot Sunnergren
02/08/2021, 7:17 PMMarc Reicher
02/08/2021, 9:50 PMScot Sunnergren
02/08/2021, 10:23 PMMarc Reicher
02/08/2021, 10:46 PMScot Sunnergren
02/09/2021, 1:44 PMdynamicl
02/09/2021, 4:27 PMScot Sunnergren
02/09/2021, 4:36 PMScot Sunnergren
02/09/2021, 4:40 PMScot Sunnergren
02/09/2021, 4:43 PMScot Sunnergren
02/09/2021, 4:46 PMMarc Reicher
02/09/2021, 5:15 PMScot Sunnergren
02/09/2021, 5:16 PMScot Sunnergren
02/09/2021, 5:16 PMScot Sunnergren
02/09/2021, 5:22 PMdynamicl
02/09/2021, 8:02 PMScot Sunnergren
02/10/2021, 11:33 AMdynamicl
02/10/2021, 12:20 PMdynamicl
02/10/2021, 12:21 PMcls
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
## USER SETTINGS START ##############################################################################################
$restMethod = "GET"
$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 = 'https://'+$nsUrlInstanceName+'.<http://restlets.api.netsuite.com/app/site/hosting/restlet.nl?script='+$nsScriptId+'&deploy='+$nsDeployId|restlets.api.netsuite.com/app/site/hosting/restlet.nl?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
if($restMethod -eq "GET"){
$message = 'GET&'+$baseUrlEncoded+'&'+$paramsEncoded
}
elseif($restMethod -eq "POST"){
$message = 'POST&'+$urlEncoded+'&'+$paramsEncoded
}
else{
"ERROR - Please check REST method parameter"
exit
}
$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+'"')
if($restMethod -eq "GET"){
$response = Invoke-RestMethod $fullUrl -Method 'GET' -Headers $headers
$response | ConvertTo-Json
}
elseif($restMethod -eq "POST"){
$body = "{}"
$response = Invoke-RestMethod $url -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
}
Scot Sunnergren
02/10/2021, 1:42 PMScot Sunnergren
02/10/2021, 2:12 PMdynamicl
02/10/2021, 2:13 PMScot Sunnergren
02/10/2021, 2:38 PMScot Sunnergren
02/10/2021, 2:39 PMScot Sunnergren
02/10/2021, 2:44 PMdynamicl
02/10/2021, 3:20 PMdynamicl
02/10/2021, 3:36 PMdynamicl
02/10/2021, 3:37 PMdynamicl
02/10/2021, 3:41 PMScot Sunnergren
02/10/2021, 4:09 PMScot Sunnergren
02/10/2021, 4:52 PMdynamicl
02/10/2021, 4:53 PMScot Sunnergren
02/10/2021, 4:53 PMdynamicl
02/10/2021, 4:53 PMdynamicl
02/10/2021, 4:54 PMdynamicl
02/10/2021, 5:09 PMdynamicl
02/10/2021, 5:09 PMScot Sunnergren
02/10/2021, 5:33 PMdynamicl
02/10/2021, 5:34 PM