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
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.
Here's the query I have built -- also in the picture
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
@Anonymous
I doubt you can add the parameter within the " " string.
Try add the entire authkey to the parameter, then you can just call out the parameter in the code e.g.
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 - 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
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
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"],
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 10 | |
| 8 | |
| 7 | |
| 7 | |
| 5 |