Forum Discussion
Calling an SAP BTP CAP service via OData with API key without saving the key as plain text
- 10 months ago
Hi Jonas_Trompeter,
If you need to call an SAP BTP CAP OData service using an API key but want to avoid storing the key as plain text in your M code, there are several secure methods you can use. One straightforward approach is to store the API key as a Power Query parameter rather than hard-coding it in the query. This way, the key is entered through the parameter interface, and the M code only references the parameter, so the key does not appear as a literal string. When you publish the report to Power BI Service, you can securely re-enter the key in the dataset settings.
For greater security at the enterprise level, you can keep the API key in a secret vault like Azure Key Vault or SAP BTP Destination/Connectivity Service. Power BI can then use a custom connector or a proxy/API Management layer to retrieve the key at runtime and add it to the request header, ensuring the key is never stored in the PBIX file or M script.
Ideally, consider moving away from static API-key authentication and publishing the CAP service with OAuth2/XSUAA. OAuth2 allows Power BI to authenticate with token-based access, removing the need to store a long-lived secret and offering improved security, easier key rotation, and better governance.
Thank you.
Hi Jonas_Trompeter,
Thank you for the update, and I’m glad the guidance was helpful. Azure Key Vault is indeed a strong choice for API-key authentication, as it keeps secrets outside of PBIX/Dataflow and enables key rotation without needing to republish.
You’re also right that Power BI currently doesn’t support secure API-key storage natively. If you’d like, you can suggest this as a feature in the Power BI Ideas forum for consideration by the product team and community. There’s growing interest in native secret management, so your suggestion would be valuable.
Fabric Ideas - Microsoft Fabric Community
Thank you.