Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowJuly 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more
Dear PowerBI wizzards,
Im pretty new to M and its coding. Currently im working to make a presentation with its input comes from an API. The API itselfs needs to be provided with a ClientIdentifier and ClientSecret. When this is done it, it returns me an API acces key wich i then can use to get the data that i want.
The problem that im running into is that i need to get data from multiple clouddirectorys. These different directorys all have differnt credentials.
This is my M code to call the API to give me the API Acces Key that i need:
//(UserName as text, OfficeCode as text, Password as text)=>
let
url = "https://xxxxxxxxxxxxxxx",
body =
"{""clientIdentifier"":""XXXXXXXX"",
""clientSecret"":""XXXXXXXX"",
""username"": ""XXXXX"",
""password"": ""XXXX"",
""officeCode"": ""XXXXXX"",
}",
Source = Json.Document(Web.Contents(url,[
Headers = [#"Content-Type"="application/json"],
Content = Text.ToBinary(body)] ))
in
Source
In the JSON body i hardcoded the credentials need to provide me the acces key. Now i want to re-use the code above to give me an acces key for every directory but im failing to combine the variables into the JSON body. Im looking for someting like this:
body = "{""username"": UserName}".
So my question is how can i implement the given paratamers in the top of the code commented out into my JSON body?
Much thanks in advance already!!!
Solved! Go to Solution.
I came up with this and it works:
body = "{""clientIdentifier"":""xxxxxxxx"",
""clientSecret"":""xxxxxxxx"",
""username"":" & Text.FromBinary(Json.FromValue(UserName)) & "," & "
""password"":" & Text.FromBinary(Json.FromValue(Password)) & "," & "
""officeCode"":" & Text.FromBinary(Json.FromValue(OfficeCode)) & "}",
If there are smarter or better solutions i gladly hear them:)
I came up with this and it works:
body = "{""clientIdentifier"":""xxxxxxxx"",
""clientSecret"":""xxxxxxxx"",
""username"":" & Text.FromBinary(Json.FromValue(UserName)) & "," & "
""password"":" & Text.FromBinary(Json.FromValue(Password)) & "," & "
""officeCode"":" & Text.FromBinary(Json.FromValue(OfficeCode)) & "}",
If there are smarter or better solutions i gladly hear them:)
Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.
Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.