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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Help converting url rest authentication to powerquery with post.

I am trying to authenticate to a rest service.  I usually built a query in python with url encoder and have no troubles. 

 

The website documentation looke like this. 

 

$.post("/Services/General/Authentication/Authenticate",
    { data: JSON.stringify({ LoginName: "jdoe",Password: "jdoe" }) },
    function (data) {
        var token = JSON.parse(data);
    }
);

or it will take a url directly like so. 

 

http://localhost/Services/General/Authentication/Authenticate?data={"LoginName":"jdoe","Password":"jdoe"}

 In Python my code looks like this: 

 

def login():
    """ Login to site and return the token"""

    log.info("Connect to site and Get Security Settings")

    payload = {"LoginName":"login","Password":"pwd"}
                
    response = requests.get('https://localhost/services/General/Authentication/Authenticate?data=' + json.dumps(payload))
    jrespon = response.json()
    token = "&token=" + jrespon[u'Value'][u'Token']

    return token

 

Currently my query looks like this. 

 

let
    data = [    LoginName = "login",
                Password = "pwd"        
    ],

    header = [    #"Content-Type"= "application/json"],

    response = Web.Contents("https://localhost/Services/General/Authentication/Authenticate", [Content=Json.FromValue(data), Headers=header]),
    out = Json.Document(response)
    
in
    out

 

Any advice would be greatly appreciated.  I have tried multiple different ways, but I am always getting an invalid login name or invalid login name field error.  Fiddler seams to show that they are coming in as data and not being appended to the url.  I need to post not  get so if I just build the url as a string I can't get what I need either.  

 

Thanks in advance. 

1 REPLY 1
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

Hope this case can help you.

https://community.powerbi.com/t5/Desktop/Using-a-REST-API-as-a-data-source-POST-Method-Only/td-p/244166

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors