Forum Discussion
Michiel
Resolver III
8 years agoEncode a Text field
I'm using an API requiring a token in Base64 encoding, coming from a text string. Playing around with the query editor and M, I've been able to succesfully convert the encoded string back to the ori...
- 8 years ago
v-jiascu-msft
Microsoft Employee
8 years ago- Michiel8 years ago
Resolver III
Is it so simple... Thanks!
- Jonas17 years ago
Helper I
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.