none
Trying to use Azure Cognative Services Translator Text api... cannot get service to connect - Error 400: Bad Request RRS feed

  • Question

  • Below is my M Query Code snippet. What am I missing?

    This works in Postmas (api testing tool).

    I have seen a lot of people struggling to get apis calls to work in AAS/Power BI/Power Query - there are some threads that are over 2 years old without apparent resolution.

    ---

    let

     

    body =  "{""Text"":""Have a good day""}",

     

        Source = Json.Document(Web.Contents("https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=fr-FR",

     

    [

     

    Headers=[#"Ocp-Apim-Subscription-Key"="xxxxxx", #"Content-Type"="application/json"],

     

    Content= Text.ToBinary(body)

     

    ] ))

     

     

    in

        Source


    Friday, October 19, 2018 5:59 PM

Answers

  • this worked:

    let

     

    body =  "[{""Text"":""Have a good day""}]",

     

    jsonContent = Text.ToBinary(body, TextEncoding.Ascii),

     

    source= Web.Contents(

     

    "<API URL>",


    [

     

    Headers=

     

    [#"Ocp-Apim-Subscription-Key"="xxxxxxxxxxxxxx",

     #"Content-Type"="application/json", 

     #"Accept"="application/json"],

     

    Content=jsonContent

     

    ]

     

    ),

     

    json = Json.Document(source),

     

        json1 = json{0},

     

        translations = json1[translations],

     

        translations1 = translations{0}

     

     

    in

        translations1

    Friday, October 19, 2018 9:03 PM