Hi, I made a custom connector for QuickBooks Online(Because Power BI default connector was not returning values from "Invoice" and Invoice related tables). I am able to get the data and publish in Power BI Desktop. I have included it in the enterprise gateway and able to see my report in Power BI Service, but on refresh from service I am recieving this error.
Underlying Error Message: "Value cannot be null: Parameter name: access Token Table: Invoice"
DM_ErrorDetailNameCode_UnderlyingHResult: -2147467261
I am pasting my OAuth Codes for reference.
// Data Source Kind description
PBIServiceRefresh = [
TestConnection = (dataSourcePath) => { "PBIServiceRefresh.Contents" },
Authentication = [
OAuth = [
StartLogin = StartLogin,
FinishLogin = FinishLogin,
Refresh = Refresh,
Logout = Logout
]
],
Label = "QBO Invoice Connector"
];
// StartLogin function definition
StartLogin = (resourceUrl, state, display) =>
let
authorizeUrl = authorize_uri & Uri.BuildQueryString([
client_id = client_id,
redirect_uri = redirect_uri,
state = state,
scope = "com.intuit.quickbooks.accounting",
response_type = "code",
response_mode = "query",
login = "login"
])
in
[
LoginUri = authorizeUrl,
CallbackUri = redirect_uri,
WindowHeight = 720,
WindowWidth = 1024,
Context = null
];
// FinishLogin function definition
FinishLogin = (context, callbackUri, state) =>
let
parts = Uri.Parts(callbackUri)[Query],
result = if (Record.HasFields(parts, {"error", "error_description"})) then
error Error.Record(parts[error], parts[error_description], parts)
else
TokenMethod("authorization_code", "code", parts[code])
in
result;
// Refresh and Logout functions
Refresh = (resourceUrl, refresh_token) => TokenMethod("refresh_token", "refresh_token", refresh_token);
Logout = (token) => logout_uri;
// TokenMethod definition
TokenMethod = (grantType, tokenField, code) =>
let
queryString = [
grant_type = "authorization_code",
redirect_uri = redirect_uri,
client_id = client_id,
client_secret = client_secret
],
queryWithCode = Record.AddField(queryString, tokenField, code),
tokenResponse = Web.Contents(token_uri, [
Content = Text.ToBinary(Uri.BuildQueryString(queryWithCode)),
Headers = [
#"Content-type" = "application/x-www-form-urlencoded",
#"Accept" = "application/json"
],
ManualStatusHandling = {400}
]),
body = Json.Document(tokenResponse),
result = if (Record.HasFields(body, {"error", "error_description"})) then
error Error.Record(body[error], body[error_description], body)
else
body
in
result;
Using this connector I am able to refresh in PowerBI Desktop.
Can anyone tell me what could be the problem?
Thanks in advance.