Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
hgarciaf
New Member

Authentication issue with Google API connection

I am connecting with Google Translate API without any problem in PowerQuery, I use my access-token and I get the json response flawlessly.

 

But then, when i close the Query Editor and the data starts to refresh I am getting an error when trying to authenticate with www.translation.googleapis.com anonymously. 

 

I have also set "Ignore Privacy Levels" in case that was related to the issue but nothing changes.

 

Is there any way to resolve this?

3 REPLIES 3
hgarciaf
New Member

This is the function I'm using. It gets the data without any issue on the Query Editor, but the anonymous connection fails when refreshing the data on the PowerBI app. I've hidden the token a project name:

let
Source = (ToBeTranslated as text, TargetLang as text) => let
// Define the URL for the API endpoint
url = "https://translation.googleapis.com/language/translate/v2",

// Define the request headers
headers = [
#"Authorization" = "Bearer TokenHere",
#"x-goog-user-project" = "ProjectNameHere",
#"Content-Type" = "application/json; charset=utf-8"
],

// Define the request body
body = Json.FromValue([
q = { ToBeTranslated },
target = TargetLang
]),

// Make the POST request
response = Web.Contents(url, [
Headers = headers,
Content = body
]),

// Parse the JSON response
jsonResponse = Json.Document(response),
// Parse the JSON response
data = jsonResponse[data],
// Parse the JSON response
translations = data[translations],
// Parse the JSON response
translations1 = translations{0},
#"Converted to Table" = Record.ToTable(translations1),
#"Filtered Rows" = Table.SelectRows(#"Converted to Table", each ([Name] = "translatedText")),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Name"})
in
#"Removed Columns"
in
Source
Anonymous
Not applicable

Hi @hgarciaf,

Have you tried to use the optional parameter relative path to processing your url? AFAIK, some of api with anonymous authorization only allow to receive the credentials on the root level:

let
    Source = (ToBeTranslated as text, TargetLang as text) =>
        let
            // Define the URL for the API endpoint
            url = "https://translation.googleapis.com",
            // Define the request headers
            headers = [
                #"Authorization" = "Bearer TokenHere",
                #"x-goog-user-project" = "ProjectNameHere",
                #"Content-Type" = "application/json; charset=utf-8"
            ],
            path = "/language/translate/v2",
            // Define the request body
            body = Json.FromValue([
                q = {ToBeTranslated},
                target = TargetLang
            ]),
            // Make the POST request
            response = Web.Contents(url, [
                Headers = headers,
                RelativePath = path,
                Content = body
            ]),
            // Parse the JSON response
            jsonResponse = Json.Document(response),
            // Parse the JSON response
            data = jsonResponse[data],
            // Parse the JSON response
            translations = data[translations],
            // Parse the JSON response
            translations1 = translations{0},
            #"Converted to Table" = Record.ToTable(translations1),
            #"Filtered Rows" = Table.SelectRows(#"Converted to Table", each ([Name] = "translatedText")),
            #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows", {"Name"})
        in
            #"Removed Columns"
in
    Source

Using The RelativePath And Query Options With Web.Contents() In Power Query And Power BI M Code 

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Hi @hgarciaf ,

Can you please share some more detail information about this issue? They should help us clarify your scenario and test to troubleshoot.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.