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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
gilmore_staci
Helper II
Helper II

Query for Salesforce API connection

I have gone through salesforce help and they believe the issue is on the power bi side so checking here.

 

I have an external client app set up to api connect salesforce to power bi.  this is the code i'm using

 its giving me a DataSource.Error: Web.Contents failed to get contents from 'https://caterpillar.my.salesforce.com/services/oauth2/token' Bad Request  error. 

 

Am I missing something?

let
    // 1. Define Salesforce API credentials
    SalesforceUrl = "https://*Client*.my.salesforce.com",
    ClientId = "ClientKey",
    ClientSecret = "clientsecret",
    
    // 2. Request the OAuth2 Access Token
        TokenResponse = Json.Document(Web.Contents(SalesforceUrl & "/services/oauth2/token", [
        Content = Text.ToBinary("grant_type=client_credentials&client_id=" & ClientId & "&client_secret=" & ClientSecret),
        Headers = [#"Content-Type"="application/x-www-form-urlencoded"]
    ])),
    AccessToken = TokenResponse[access_token],

    // 3. Query the data using REST API (SOQL)
    DataResponse = Json.Document(Web.Contents(SalesforceUrl & "/services/data/v60.0/query", [
    Query =  [q="SELECT Id, Name, Email FROM User WHERE Profile.Name = 'System Administrator'"],
    Headers = [#"Authorization" = "Bearer " & AccessToken]
    ])),
    
    // 4. Parse the results into a table
    Records = DataResponse[records],
    Table = Table.FromList(Records, Record.FieldValues, {"Id", "Name", "Email"})
in
    Table
0 REPLIES 0

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors