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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Power Query Get Token for OAUTH

Hello everyone,

I have the following code to generate an OAUTH token Does anyone have any idea how I write this in Power Query

 

// Values from your OAuth app. You create ONE for a page/plugin/service.
$clientid     = "#Place OAuth clientID here#";
$clientsecret = "#Place OAuth client secret here#";

// The official CleverReach URL, no need to change this.
$token_url = "https://rest.cleverreach.com/oauth/token.php";

// We use curl to make the request
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL, $token_url);
curl_setopt($curl,CURLOPT_USERPWD, $clientid . ":" . $clientsecret);
curl_setopt($curl,CURLOPT_POSTFIELDS, array("grant_type" => "client_credentials"));
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
curl_close ($curl);

// The final $result contains the access_token and some other information besides.
// For you to see it, we dump it out here.
var_dump($result);

 

 

The final result of the OAuth process is the access token.Here is the format of the reponse as an example.

 

{
  "access_token":  "7h4t1s50mek1nd0fab4t70ken",
  "expires_in":    31536000,
  "scope":         "batmobile batcycle batplane batcopter",
  "refresh_token": "m4keb4t70kenfr35h"
}

 

 

4 REPLIES 4
Stachu
Community Champion
Community Champion

Anonymous
Not applicable

@Stachu Thanks for the links, but unfortunately I can't get anywhere with them, because the cURL process for the request is not explained here. Do you have an idea how I write this with PowerQuery

Stachu
Community Champion
Community Champion

try to connect with the PowerBI UI (regular web connection) and show the M code that gets generated together with the respective errors, I will try to troubleshoot from there



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

I have inserted the Token URL alone into the Web Connection without settings and this message appears.Anmerkung 2020-02-18 120224.png

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.