Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error 400000 on Getting Text from PowerShell Variable #9

Open
dborchers-gc opened this issue Jun 24, 2023 · 0 comments
Open

Error 400000 on Getting Text from PowerShell Variable #9

dborchers-gc opened this issue Jun 24, 2023 · 0 comments

Comments

@dborchers-gc
Copy link

I totally have no idea what's happening here. Hope someone here can help me. That makes no sense and its frustrating...

I tried to reach the text translation API in PowerShell. This are my Global Variables:

$TranslatorKey = "e54902*******" # You need a valid key for Microsoft Translator
  
$global:BaseUri = "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0"
$global:Headers = @{
    'Ocp-Apim-Subscription-Key' = $translatorKey
    'Ocp-Apim-Subscription-Region' = 'germanywestcentral' # added (change if needed)
    'Content-type' = 'application/json; charset=UTF-8'
}

When i use the Text directly inside my Code it works:

$LanguageCode = "de"
$textJson = @{
    "Text" = "Users may see some meetings scheduled in Mexico time zones are displaying with the incorrect time."
} | ConvertTo-Json
$Body = "[$textJson]"
$Uri = "$($global:BaseUri)&to=$($LanguageCode)"
$Status = Invoke-RestMethod -Method Post -Uri $uri -Headers $global: headers -Body $Body

But if i want to use a Variable with the Text inside, it throws the Error in the Title:

$temp = "Users may see some meetings scheduled in Mexico time zones are displaying with the incorrect time."
$LanguageCode = "de"
$textJson = @{
    "Text" = $temp
} | ConvertTo-Json
$Body = "[$textJson]"

Ive checked absolutely everything and have no idea what's the difference. I really Hope someone can help me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant