cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
blizzardice Occasional Visitor
Occasional Visitor

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
Community Support Team
Community Support Team

Re: Help converting url rest authentication to powerquery with post.

Hi @blizzardice ,

 

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/244...

 

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
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

January 2020 Community Highlights

January 2020 Community Highlights

Make sure you didn't miss any of the things that happened in the community in January!

Top Solution Authors
Top Kudoed Authors