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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Help with integrating parameters into String creation

My first post here. I've tried searching quite a bit and took a Udemy course to try to learn a bit more about M language but still a little stuck.

 

I am trying to create an API call to get customer-related data into a table. It requires a bearer token.

 

  • I created a parameter that successfully retrieves the token value/string called "ChoiceBearerTokenGet". 
  • My problem is two-fold.
    1. When I hard code the bearer into the new query (CitrixServiceLic - pasted below in red), it works great (although a slight timing issue once time enough time has expired, detailed in #2 below). I am asking for assistance on how to replace the hard-coded value (bold red below) with the parameter I created called "ChoiceBearerTokenGet".
    2. The bearer token is only good for a particular length of time and then expires. I also need to figure out how to force the refresh of "ChoiceBearerTokenGet" before the query below runs (so that it gets a new bearer token value in the parameter)

Here's the query I have built -- also in the picture


picture.jpg

 

 

let

Date = Date.ToText(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),Date.Day(DateTime.LocalNow())),"yyyy-MM"),
Source = Json.Document(Web.Contents("https://licensing-eastus-release-b.citrixworkspacesapi.net/[companyName]/licenseusages/deployments/c..."&Date,
[Headers=[Authorization="CwsAuth Bearer=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMzQ4MTcwN", Accept="application/json", #"Content-Type"="application/json"]])),
singleTenantsUsage = Source[singleTenantsUsage],
#"Converted to Table" = Table.FromList(singleTenantsUsage, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"customerId", "orgId", "displayName", "editionName", "totalCommitCount", "totalUsageCount", "totalOverageCount", "totalUsagePercent"}, {"Column1.customerId", "Column1.orgId", "Column1.displayName", "Column1.editionName", "Column1.totalCommitCount", "Column1.totalUsageCount", "Column1.totalOverageCount", "Column1.totalUsagePercent"}),
#"Renamed Columns" = Table.RenameColumns(#"Expanded Column1",{{"Column1.displayName", "Company"}, {"Column1.editionName", "sku"}, {"Column1.totalCommitCount", "totalCommitCount"}, {"Column1.totalUsageCount", "totalUsageCount"}, {"Column1.totalOverageCount", "totalFlexCount"}, {"Column1.totalUsagePercent", "totalUsagePercent"}, {"Column1.orgId", "CitrixCompanyorgId"}, {"Column1.customerId", "CitrixCustomerId"}})
in
#"Renamed Columns"

 

Any help would be greatly appreciated!

 

Thank you!

Rob

4 REPLIES 4
Anonymous
Not applicable

@Anonymous 


I doubt you can add the parameter within the " " string.

 

Vpazhenmsft_0-1626138820484.png

Try add the entire authkey to the parameter, then you can just call out the parameter in the code e.g.

Vpazhenmsft_4-1626138907336.png

 

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

 

 

 

Anonymous
Not applicable

@Anonymous - so I actually used the code below and it seems to work although I'm getting a new error stating "Formula.Firewall: Query 'CitrixCVADServiceLic' (step 'Source') references other queries or steps, so it may not directly access a data source. Please rebuild this data combination." Now I did some research on this and found this but I don't believe that applies to my situation or, rather, I don't know how. 

 

The "ChoiceBearerTokenGet" is a parameter that grabs the token .

 

 

 

let
    myBearerVariable = ChoiceBearerTokenGet,
    Date = Date.ToText(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),Date.Day(DateTime.LocalNow())),"yyyy-MM"),
    myUrl = "https://licensing-eastus-release-b.citrixworkspacesapi.net/ChoiceSoluti/licenseusages/deployments/cloud/memberships/csp/products/cvad?date="&Date,
    myTokenHeader = "CwsAuth Bearer=" & myBearerVariable,
    myBody = "{
                ""authorization"": """& myTokenHeader & """,
                ""content-type"": ""application/json"",
                ""Accept"": ""application/json""
            }",
    Source = Json.Document(
            Web.Contents(
                myUrl,
                [
                    Headers = Json.Document(myBody)
                ]
            )
    ),
    singleTenantsUsage = Source[singleTenantsUsage],
    #"Converted to Table" = Table.FromList(singleTenantsUsage, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"customerId", "orgId", "displayName", "editionName", "totalCommitCount", "totalUsageCount", "totalOverageCount", "totalUsagePercent"}, {"Column1.customerId", "Column1.orgId", "Column1.displayName", "Column1.editionName", "Column1.totalCommitCount", "Column1.totalUsageCount", "Column1.totalOverageCount", "Column1.totalUsagePercent"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Column1",{{"Column1.displayName", "Company"}, {"Column1.editionName", "sku"}, {"Column1.totalCommitCount", "totalCommitCount"}, {"Column1.totalUsageCount", "totalUsageCount"}, {"Column1.totalOverageCount", "totalFlexCount"}, {"Column1.totalUsagePercent", "totalUsagePercent"}, {"Column1.orgId", "CitrixCompanyorgId"}, {"Column1.customerId", "CitrixCustomerId"}})
in
    #"Renamed Columns"

 

 

 

Anonymous
Not applicable

@Anonymous 
Check out the discussions in this post, also concerns and suggestions are mentioned.
Solved: Protection of API Keys Stored in Parameter - Microsoft Power BI Community

 

 

Paul Zheng _ Community Support Team

Anonymous
Not applicable

Paul - first, thank you for the reply. I had checked out that solution however the example in question is a key/value pair of Authorization/authkey

 

my problem is I need to append to the authkey (authkey = "CwsBearer = " then a very long key (that I'm storing in a parameter).

 

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

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.