Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
dvdbroek
Frequent Visitor

Getting a specific value from a table that comes from a JSON file into a variable

Dear M query king and queens,

I made a custom function that retrieves an API Acces key so i can retrieve data from an API. The code is as following:

 

 

 

(UserName as text, OfficeCode as text, Password as text)=>

let
   url = "https://api.basecone.com/v1/Authentication/ApiAccessKeys",

   body = "{""clientIdentifier"":""xxxxxxxxxxx"",
        ""clientSecret"":"xxxxxxxxxxxxxxx"",
        ""username"":" & Text.FromBinary(Json.FromValue(UserName)) & "," & "
        ""password"":" & Text.FromBinary(Json.FromValue(Password)) & "," & "
        ""officeCode"":" & Text.FromBinary(Json.FromValue(OfficeCode)) & "}",

    #"Identifier" = "xxxxxxxxxxxxxxx"
 
    Source = Json.Document(Web.Contents(url,[

           Headers = [#"Content-Type"="application/json"],

           Content = Text.ToBinary(body)] )),


           
  #"Converted to Table" = Record.ToTable(Source),

   #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Value", type text}}),
  #"Base64Key" = Table.AddColumn(#"Converted to Table", "APIKeyBase64", each Binary.ToText(Text.ToBinary(Identifier & [Value]), 0)),
  FinalOutput = Table.First(#"Base64Key")

 
in
FinalOutput

 

 

 

This code gives me a table with 3 colums and 1 row because i only retrieved the first row of the table. The headers are:

"name"       "Value"    "Key"

 

Now i want to put the value of the colum "Key" into a variable, the rest of the table i dont need. But i cant seem to get it working within the advanced Editor. The file i get from the API is JSON , so maybe i can directly put the value into a variable from the JSON response?

 

Basicly im looking for something:

 

#"KeyFromApi" = Column "Key".value     (i know the syntax doenst make sense, but its the best way i can explain)

 

Much thnx in advance!

 

 

 

 

 

1 ACCEPTED SOLUTION
dvdbroek
Frequent Visitor

Anyone who can help me?

View solution in original post

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @ dvdbroek ,

 

This is related content, hope it can help you:

https://radacad.com/analyse-the-json-file-with-power-query

https://community.powerbi.com/t5/Desktop/Parsing-JSON-data-into-PowerBI-table/td-p/55946

https://eriksvensen.wordpress.com/2014/09/15/specifying-json-query-in-power-query-example-statistics...

 

Best Regards,

Liu Yang

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

dvdbroek
Frequent Visitor

Anyone who can help me?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors