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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ZaraSeif123
Frequent Visitor

Einstein Analytics REST API query

Hi
I'm using this code to connect to Einstein Analytics in Salesforce and fetch data using Rest APIs
let
    token_url = "https://login.salesforce.com/services/oauth2/token",   
    api_base_url = "https://***.my.salesforce.com/services/data/v48.0/wave/query",
    qry_str = "",
   body="grant_type=password&client_id=***&client_secret=***&username=***&password=***",
   Source  = Json.Document(Web.Contents(token_url,
   [
     Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
     Content=Text.ToBinary(body)
   ]
   )
   ),
    token = Source[access_token],
content = "{
    ""query"":""q = load \""DataSetName\"";  
     q = limit q 200;""
}",
    data= Json.Document(Web.Contents(api_base_url&qry_str,
   [
     Headers = [
                #"Authorization"="Bearer "&token,#"Content-Type"="application/json"],Content=Text.ToBinary(content)
    
   ]
   )
   )
in
    data
 
 
 
the Authentication works fine and I can get the access token and connect but when I post the second request I get this error: "We couldn't authenticate with the credentials provided"
Am I sending the post request correctly by using Content=Text.ToBinary(content)? or maybe my SAQL query is wrong? as I'm not familiar with SAQL.
the below code works:
  
    api_base_url = "https://***.my.salesforce.com/services/data/v42.0/wave",
  
    data= Json.Document(Web.Contents(api_base_url&qry_str,
   [
     Headers = [
                #"Authorization"="Bearer "&token,#"Content-Type"="application/json"]
    
   ]
   )
   )
  
but when I change the URL to   "https://***.my.salesforce.com/services/data/v48.0/wave/query" and post the query it breaks.
Any help with this will be greatly appreciated.
Thanks
Zara
 
1 ACCEPTED SOLUTION
ZaraSeif123
Frequent Visitor

Hi Guys 

 

In case anybody else faces this issue, I solved it by adding \n to my query:

 

content = "{
    ""query"":""q = load \""DataSetName\"";  \n q = limit q 200;""
}",

View solution in original post

1 REPLY 1
ZaraSeif123
Frequent Visitor

Hi Guys 

 

In case anybody else faces this issue, I solved it by adding \n to my query:

 

content = "{
    ""query"":""q = load \""DataSetName\"";  \n q = limit q 200;""
}",

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors