Fabric Data Days Monthly is back. Join us on March 26th for two expert-led sessions on 1) Getting Started with Fabric IQ and 2) Mapping & Spacial Analytics in Fabric. Register now
Salesforce provides several OAuth 2.0 authentication flows to securely access data. One of the most suitable flows for server-to-server integrations and automation tools like Power BI is the Client Credentials Flow.
In this blog, we will cover:
✅ When to Use Client Credentials Flow
Use Client Credentials Flow when:
This is ideal for:
🔧 Step 1: Salesforce Configuration (Connected App)
1️⃣ Create a Connected App
2️⃣ Basic Information
Fill in:
3️⃣ Enable OAuth Settings
✔ Check Enable OAuth Settings
Set:
4️⃣ OAuth Scopes
Add required scopes:
5️⃣ Enable Client Credentials Flow
In OAuth Settings:
6️⃣ Save and Capture Credentials
After saving, copy:
From the App settings page.
🌐 Step 2: Salesforce Domain
Your Salesforce base URL looks like:
https://<your-org>.my.salesforce.com
We will reuse one base URL for:
⚙️ Step 3: Power BI M Code (Client Credentials Flow)
Below is the complete Power Query (M) script.
🧠 What This Code Does
🧩 Full Power BI M Code
let
// --------------------------------------------------
// 1. Base Salesforce Domain (SINGLE data source)
// --------------------------------------------------
BaseUrl =
"https://xxxxxxxxxxxxxdevelop.my.salesforce.com",
// --------------------------------------------------
// 2. Generate Access Token
// --------------------------------------------------
TokenResponse =
Json.Document(
Web.Contents(
BaseUrl,
[
RelativePath = "services/oauth2/token",
Content =
Text.ToBinary(
Uri.BuildQueryString(
[
grant_type = "client_credentials",
client_id =
"xxxxxxxxxxxxxxxx",
client_secret =
"xxxxxxxxxxxxxxxx"
]
)
),
Headers = [
#"Content-Type" = "application/x-www-form-urlencoded"
]
]
)
),
AccessToken = TokenResponse[access_token],
// --------------------------------------------------
// 3. SOQL Query
// --------------------------------------------------
SoqlQuery =
"SELECT Id, Subject, StartDateTime, EndDateTime, Location FROM Event LIMIT 10",
// --------------------------------------------------
// 4. Call Salesforce REST API (same BaseUrl)
// --------------------------------------------------
ApiResponse =
Json.Document(
Web.Contents(
BaseUrl,
[
RelativePath = "services/data/v65.0/query/",
Query = [
q = SoqlQuery
],
Headers = [
Authorization = "Bearer " & AccessToken,
#"Content-Type" = "application/json"
]
]
)
),
// --------------------------------------------------
// 5. Transform Response
// --------------------------------------------------
Records = ApiResponse[records],
TableFromRecords =
Table.FromList(
Records,
Splitter.SplitByNothing(),
null,
null,
ExtraValues.Error
),
ExpandedTable =
Table.ExpandRecordColumn(
TableFromRecords,
"Column1",
{
"Id",
"Subject",
"StartDateTime",
"EndDateTime",
"Location"
}
)
in
ExpandedTable
📊 Output in Power BI
Authentication method - Anonymous
Privacy level setting for this data source - Organizational
This produces a clean table with:
|
Id |
Subject |
StartDateTime |
EndDateTime |
Location |
You can now:
🚀 Why This Pattern Works Well in Power BI
🧾 Final Thoughts
Using Salesforce Client Credentials Flow with Power BI is a clean, secure, and production-ready approach for enterprise reporting. With a properly configured External App and a single base URL strategy, you can reliably extract Salesforce data without user intervention.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.