Forum Discussion
M Code functions not recognised by other query
So I am using 1 function to gather my access token, 1 which builds the framework of the API and the final one which puts the 2 together with query parameters and returns the data. on the 3rd function, I am getting this "Expression.Error: The name 'X/Y' wasn't recognized. Make sure it's spelled correctly." I get the error for both steps (referencing both functions) on query 3. They have the fx symbol suggesting they are set up as functions also. I am sure they are spelt correctly, can anyone help?
Queries below, (Client details and URLS redacted)
Query1
let
GetAccessToken = () =>
let
url = "https://login.serverdata.net/user/connect/token",
body = [
grant_type = "client_credentials",
client_id = "XYZ",
client_secret = "ZYX",
scope = "api.some.scope.ting"
],
headers = [#"Content-Type" = "application/x-www-form-urlencoded"],
source = Json.Document(Web.Contents(url, [Headers=headers, Content=Text.ToBinary(Uri.BuildQueryString(body))]))
in
source[access_token]
in
GetAccessToken
Query2
let
GetCallDetails = (accessToken, dateFrom, dateTo) =>
let
url = "https://api.call.data/analytics/calls/call/detail",
body = [dateFrom = dateFrom, dateTo = dateTo],
headers = [#"Content-Type" = "application/json", #"Authorization" = "Bearer " & accessToken],
source = Json.Document(Web.Contents(url, [Headers=headers, Content=Text.ToBinary(Json.FromValue(body))]))
in
source
in
GetCallDetails
Query3
let
accessToken = GetAccessToken(),
callDetails = GetCallDetails(accessToken, "2023-06-01T00:00:00.000Z", DateTime.ToText(DateTime.LocalNow()))
in
callDetails
In your case, "Query 1" returns the access token, so you'll need to reference the query name and not the function within it.
Pat
1 Reply
- ppm1Solution Sage
In your case, "Query 1" returns the access token, so you'll need to reference the query name and not the function within it.
Pat