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
dcoronno
Regular Visitor

POST Authentication to a REST API

Hi,

 

I am having issues doing a POST method in M to grab an authentication token.
Specifically I am trying to grab data out of the REST API to Power Query for Excel..

 

They have given a piece of curl code, but I am having trouble dissecting it into M.

curl -X POST --user {user}:'{password}' https://auth.anaplan.com/token/authenticate

 

Any help would be appreciated

3 REPLIES 3
Anonymous
Not applicable

Hi @dcoronno ,

 

You could try this

Get Access token in Power BI Desktop:


 

() =>

 

let

    body = "client_id=" & #"App ID"

    & "&scope=https://analysis.windows.net/powerbi/api/.default&client_secret=" & #"App Secret"

    & "&grant_type=client_credentials",

    Data= Json.Document(Web.Contents("https://login.microsoftonline.com/"& TenantID & "/oauth2/v2.0/token/",

    [Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(body)])),

    access_token = Data[access_token]

in

    access_token

 

This is the official document you can refer to.

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

kleighton
Helper II
Helper II

Hi,

 

I was fighting with retrieving authentication tokens for some time. Here's what worked in my situation. The following is a function to retrieve an Auth Token which i then call in several different data queries. You may need to change the content type. Hope you can make it work for you! 

 

let
Source = () =>
let
body = "{
""user"": ""UserHere"",
""pass"": ""PassHere""
}",
Data=Json.Document(Web.Contents("https://LinkHere", [Headers=[#"Content-Type"="application/json"], Content=Text.ToBinary(body)])),
access_token = Data[token]
in
access_token
in
Source

 

cheers,

Keith

lbendlin
Super User
Super User

You call Web.Contents with a Content payload to transform a GET call into a POST call.

 

Web.Contents - PowerQuery M | Microsoft Docs

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.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

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