Forum Discussion
Encode a Text field
- 8 years ago
Is it so simple... Thanks!
Hi Michiel ,
Currentely sitting with the same issue as you did, gonna have to do a encode-decode to retrieve what will finally be my APi-token. Would you mind showing me your code on this?
- Michiel7 years ago
Resolver III
Hi Jonas1 ,
The demo M code below will give you an idea how it works:
let BaseToken = "<token><version>1</version><data>7B4A8AEB674D862950EC85F3ACD631777A6E63CBAC5A0A4FDE85DBFE0BF92AD6</data></token>", Decoded = Binary.ToText(Text.ToBinary(BaseToken, BinaryEncoding.Base64)), BaseEncodedToken = "PHRva2VuPjx2ZXJzaW9uPjE8L3ZlcnNpb24+PGRhdGE+N0I0QThBRUI2NzREODYyOTUwRUM4NUYzQUNENjMxNzc3QTZFNjNDQkFDNUEwQTRGREU4NURCRkUwQkY5MkFENjwvZGF0YT48L3Rva2VuPg==", DecodedBinary = Binary.FromText(BaseEncodedToken, BinaryEncoding.Base64), DecodedText = Text.FromBinary(DecodedBinary,TextEncoding.Windows) in DecodedTextThe Decoded step shows the Base64 text version of the BaseToken string. The DecodedText step shows the decoded verson of the BaseEncodedToken string. The confusing thing here is that both are strings and you're basically encoding one into the other; but obviously you cannot include things like </version> in a HTML call directly.
- Jonas17 years ago
Helper I
Thanks Michiel. Think maybe I have to give up using PBI for this though as my API also required additional stuff for the authorization process (hashlib and hmac if you are familiar with Python). Because your API only required base64 right?
- Michiel7 years ago
Resolver III
I'm not familiar with that, but I must say that the web.contents function in M is pretty powerful. In my case, I ended up not using encoding at all but constructing the encoded string directly (long story to explain, but it allowed me to have separate Power Queries to list the fields I want to retrieve from a specific entity).
You do know that it's possible to call a Python script from M? There are some restrictions, though.