Forum Discussion
JakobGsvendsen
8 years agoFrequent Visitor
REST API Injected data - special local letter do not show correctly.
Hello everyone I am making a solution for a customer that grabs some data from a couple of REST web services using PowerShell. then it injects to PowerBI using the PowerBI REST API. To do th...
- 8 years ago
seems to be a powerShell issue for invoke-restmehtod and invote-websrequest as they cannot send as UTF8.
I have rewritten my powershell to make a call.
https://docs.microsoft.com/en-us/power-bi/developer/walkthrough-push-data-add-rows
Will send pull request to update the moduel asap, and then i hope he accepts :)
Prototype code (not pretty but works :)):
Function Invoke-PBIWebRequestPost { param($Uri, $Headers,$Body) # Remove NewLine from json $Body = $Body -replace "$([Environment]::NewLine) *","" write-verbose "Posting data to URL: $Uri" $request = [System.Net.WebRequest]::Create($uri) -as [System.Net.HttpWebRequest]; $request.KeepAlive = $false; $request.Method = "POST"; $request.ContentLength = 0; $request.TimeOut = 100000; #5 minute timout #Add token to the request header foreach($key in $headers.Keys) { switch($key){ "Content-Type"{ $request.ContentType = $headers[$key]; } default { $request.Headers.Add($key, $headers[$key]); } } } $rowsJson = $Body $utf8Bytes = [System.Text.Encoding]::UTF8.GetBytes($Body) $request.ContentLength = $utf8Bytes.Length $postStream = $request.GetRequestStream() $postStream.Write($utf8Bytes, 0, $utf8Bytes.Length) #Write-String -stream $postStream -string $JSON $postStream.Dispose() try { #[System.Net.HttpWebResponse] $response = [System.Net.HttpWebResponse] $request.GetResponse() $response = $request.GetResponse() } catch { $response = $Error[0].Exception.InnerException.Response; Throw "Exception occurred in $($MyInvocation.MyCommand): `n$($_.Exception.Message)" } $reader = [IO.StreamReader] $response.GetResponseStream() $output = $reader.ReadToEnd() $reader.Close() $response.Close() return $output }
JakobGsvendsen
8 years agoFrequent Visitor
seems to be a powerShell issue for invoke-restmehtod and invote-websrequest as they cannot send as UTF8.
I have rewritten my powershell to make a call.
https://docs.microsoft.com/en-us/power-bi/developer/walkthrough-push-data-add-rows
Will send pull request to update the moduel asap, and then i hope he accepts :)
Prototype code (not pretty but works :)):
Function Invoke-PBIWebRequestPost {
param($Uri, $Headers,$Body)
# Remove NewLine from json
$Body = $Body -replace "$([Environment]::NewLine) *",""
write-verbose "Posting data to URL: $Uri"
$request = [System.Net.WebRequest]::Create($uri) -as [System.Net.HttpWebRequest];
$request.KeepAlive = $false;
$request.Method = "POST";
$request.ContentLength = 0;
$request.TimeOut = 100000; #5 minute timout
#Add token to the request header
foreach($key in $headers.Keys)
{
switch($key){
"Content-Type"{
$request.ContentType = $headers[$key];
}
default {
$request.Headers.Add($key, $headers[$key]);
}
}
}
$rowsJson = $Body
$utf8Bytes = [System.Text.Encoding]::UTF8.GetBytes($Body)
$request.ContentLength = $utf8Bytes.Length
$postStream = $request.GetRequestStream()
$postStream.Write($utf8Bytes, 0, $utf8Bytes.Length)
#Write-String -stream $postStream -string $JSON
$postStream.Dispose()
try
{
#[System.Net.HttpWebResponse] $response = [System.Net.HttpWebResponse] $request.GetResponse()
$response = $request.GetResponse()
}
catch
{
$response = $Error[0].Exception.InnerException.Response;
Throw "Exception occurred in $($MyInvocation.MyCommand): `n$($_.Exception.Message)"
}
$reader = [IO.StreamReader] $response.GetResponseStream()
$output = $reader.ReadToEnd()
$reader.Close()
$response.Close()
return $output
}