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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Connect to API with token that changes

Hello, I am trying to connect to an API that requires re creation of a token every 8 hours. I can get it to create a token and pull the json into postman, but not into Power Bi. When I use that postman token. I also don't know how to code it in bi to make a new token, as this one expires every 8 hours. 

 

I am entering information into Power Bi and getting the 400 error, and referring to swagger endpoints for the API

20220429_095032.jpg

20220429_095038.jpg

20220429_095054.jpg

20220429_095103.jpg

20220429_095109.jpg

20220429_100912.jpg

20220429_100946.jpg

4 REPLIES 4
Anonymous
Not applicable

I'm now finding the issue is it is a POST request instead of GET, is there any way to connect to data of they have it set up as a POST?

HI @Anonymous,

In fact, you can also use post requests in the power query web connector. You need to add the request contents to the header or body(this is based on your API settings) and attached them to the data connector.

 

let
    rootURL = "app.xxx.com",
    secretId = xxxxx,
    GetJson =
        Web.Contents(
            rootURL,
            [
                Headers = [
                    #"Authorization" = "Basic " & secretId,
                    #"Content-Type" = "application/json"
                ],
                Content = Text.ToBinary("grant_type=client_credentials")
            ]
        ),
    body = "xxxxx",
    Result =
        Web.Contents(
            rootURL,
            [
                Headers = [
                    Authorization = "Bearer " + token,
                    apikey = "xxxxxxx",
                    RelativePath = "/api/departments/list/",
                    Content = Text.ToBinary(body),
                    ContentType = "application/json"
                ],
                Query = [
                    page = "1",
                    sortDirection = "asc"
                ]
            ]
        )
in
    Result

 

Chris Webb's BI Blog: Using The RelativePath And Query Options With Web.Contents() In Power Query And Power BI M Code Chris Webb's BI Blog (crossjoin.co.uk)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Providing a Content payload to Web.Contents() converts the API call from GET to POST.

 

Web.Contents - PowerQuery M | Microsoft Docs

lbendlin
Super User
Super User

There are many examples for handling refresh tokens. Here is one : Solved: Refresh token api call - Microsoft Power BI Community

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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