Hi All,
I’m attempting to create a simple pack that queries a Power BI dataset and creates a sync table. I’ve successfully authorized the pack, but when I attempt to query Power BI I receive a 403 error.
I believe one of the potential causes is that the required token is missing from the api call, but I don’t know exactly. I’m using the ‘user owns data’ approach where the app prompts the user to approve its’ permissions.
Is anyone familiar with MSFT APIs? If so, have you come across similar issues?
Initial authorization succeeds
Query from the test formula fails
import * as coda from "@codahq/packs-sdk";
export const pack = coda.newPack();
// Per-user authentication to Microsoft APIs, using OAuth2.
// See https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow
// Allow the pack to make requests to Microsoft.
// pack.addNetworkDomain("microsoft.com");
pack.setUserAuthentication({
type: coda.AuthenticationType.OAuth2,
authorizationUrl:
"https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
tokenUrl: "https://login.microsoftonline.com/common/oauth2/v2.0/token",
scopes: [
"User.Read",
"offline_access",
"https://analysis.windows.net/powerbi/api/Dashboard.Read.All",
"https://analysis.windows.net/powerbi/api/Report.Read.All",
"https://analysis.windows.net/powerbi/api/Dataset.ReadWrite.All",
"https://analysis.windows.net/powerbi/api/Workspace.ReadWrite.All"
],
// Additional parameters to ensure a refresh_token is returned.
additionalParams: {
prompt: "consent",
},
// Enable PKCE (optional but recommended).
useProofKeyForCodeExchange: true,
// Determines the display name of the connected account.
// getConnectionName: async function (context) {
// let response = await context.fetcher.fetch({
// method: "GET",
// url: "https://graph.microsoft.com/v1.0/me",
// });
// let user = response.body;
// return user.displayName;
// },
});
pack.addNetworkDomain("powerbi.com");
// Add formulas here.
pack.addFormula({
name: "test",
description: "test connection",
parameters: [],
resultType: coda.ValueType.String,
// connectionRequirement: coda.ConnectionRequirement.Required,
execute: async function (_, context) {
let response = await context.fetcher.fetch({
method: "GET",
url: "https://api.powerbi.com/v1.0/myorg/groups/{workspace id redacted for this post}/datasets"
});
return response.body
},
});```