Forum Discussion
Anonymous
7 years agoNot 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
- v-frfei-msftCommunity Support
Hi Anonymous ,
Hope this case can help you.