Forum Discussion

arindamp's avatar
arindamp
New Member
2 years ago

Unable to fetch access_token from Extension.CurrentCredential()

Hi experts

I am building a PowerQuery Custom Connector (for Zoho APIs) in Visual Studio to be deployed to Power BI.
While debugging/launching from Visual Studio, I can see the data being fetched from the API; however, if I deploy the connector to the Power BI Custom Connectors folder, the same code doesn't work.
I get an error in Power BI while trying to use the Connector :
Details: "The field 'access_token' of the record wasn't found."

The snippet where I am accessing the token after the OAuth flow -

`...
token = GetToken(),
apiResponse = zoho.CallApi(apiEndpoint, token),
...

GetToken = () =>
let
access_token = Extension.CurrentCredential()[access_token]
in
access_token;

zoho.CallApi = (apiEndpoint as text, accessToken as text) =>
let
// Make API request using the access token
apiResponse = Json.Document(
Web.Contents(
apiEndpoint,
[Headers = [#"Authorization" = "Zoho-oauthtoken " & accessToken]]
)
)
in
apiResponse;
...
zoho = [
Authentication = [
OAuth = [
StartLogin=StartLogin,
FinishLogin=FinishLogin,
Refresh=Refresh,
Logout=Logout
]
]
];

//Implementations for StartLogin, FinishLogin, Refresh and Logout
`



Is there any restriction in invoking Extension.CurrentCredential() from Power BI (December 2023 version)?
The reason I need to fetch the access_token is because the Zoho APIs require the Authorization header to have the value : Zoho-oauthtoken <access_token>

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi arindamp 

    Please make sure that the access token is right,

    e.g 

     

    MyConnector.Raw = (_url as text) as binary =>
    let
        apiKey = Extension.CurrentCredential()[Key],
        headers = [
    
            #"x-APIKey" = apiKey,
            Accept = "application/vnd.api+json",
            #"Content-Type" = "application/json"
        ],
        request = Web.Contents(_url, [ Headers = headers, ManualCredentials = true ])
    in
        request

     

    and you can refer to the following link.

    Handling authentication for Power Query connectors - Power Query | Microsoft Learn

     

    Best Regards!

    Yolo Zhu

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

     

    • arindamp's avatar
      arindamp
      New Member

      Hi Anonymous 

      The access token name is right, as it all works fine from Visual Studio.
      The issue only happens when the Connector has been deployed to Power BI.