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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
JBBaxter
Frequent Visitor

Call Google Search Console API with Power Query (M) - Web.Contents( POST Problem)

Hi Guys,

 

i managed to work with googles oath2 in including a refresh of the access_token in Power Query (M), (what a pain to get the first token and the refresh token) made also my first requests via GET. 

::is working

let
    AccessTokenList = List.Buffer(api_token),
    access_token = AccessTokenList{0},
    AccessTokenHeader = "bearer " & access_token,
    GetJsonQuery = Json.Document(Web.Contents("https://www.googleapis.com/webmasters/v3/sites?&access_token=" & access_token))

in 
    GetJsonQuery

 

 

 

so now i tried to call the /searchAnalytics/ query wich works with post :

 

let
    JsonRecords = Text.FromBinary(Json.FromValue(Source)),
    JsonRequest = "{
  ""startDate"": ""2019-01-01"",
  ""endDate"": ""2019-02-01"",
}", 
    JsonContent = Text.ToBinary(JsonRequest),
    AccessTokenList = List.Buffer(api_token),
    access_token = AccessTokenList{0},
    AuthKey = "Bearer " & access_token,

    Response = Web.Contents("https://www.googleapis.com/webmasters/v3/sites/https%3A%2F%2Fwww.xxxxxxx.xxx/searchAnalytics/query", [Headers=[Authorization=AuthKey, ContentType="application/json", Accept="application/json"], Content=JsonContent]),
    JsonResponse = Json.Document(Response)
in
    JsonResponse

getting a bad request (400) - [auth header is working fine] already tested it, so there must be something wrong with the Header request aka Content=(body) or formating. Request body needs to have "startDate": "YYYY-MM-DD" and "endDate": "YYYY-MM-DD", 

 

Google reference:

https://developers.google.com/webmaster-tools/search-console-api-original/v3/searchanalytics/query

 

Any Idea?

 

Thanks

 

 

3 REPLIES 3
Anonymous
Not applicable

@JBBaxter , Did you solve this problem? I have a question, when you've created the API Application in google API console, did you use OAuth authentication (with client ID) or API Token? Thans

v-yuta-msft
Community Support
Community Support

@JBBaxter ,

 

This issue should be caused by invalid format of the query in body. How about use format like YYYY/MM/DD?

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for your reply, @v-yuta-msft 

 

I tested it:

let
    body = "{ ""startDate"": ""2019/01/01"", ""endDate"": ""2019/02/01"" }", 
    AccessTokenList = List.Buffer(api_token),
    access_token = AccessTokenList{0},
    AuthKey = "Bearer " & access_token,
    url = "https://www.googleapis.com/webmasters/v3/sites/https%3A%2F%2Fwww.xxxxxxx.xxx/searchAnalytics/query",

    Response = Web.Contents(url, [Headers=[Authorization=AuthKey, ContentType="application/json", Accept="application/json"], Content=Text.ToBinary(body)]),
    JsonResponse = Json.Document(Response)
in
    JsonResponse

Still gives me a 400

 

any other ideas? maybe (WebMethod.Post or WebAction.Request)?

 

Thx 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.