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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Doc-tan
Regular Visitor

Custom connector API - TOKEN (error binary)

I have create a custom connector but i can not see and use the token because of error

Details: "We cannot convert a value of type Binary to type Text."

at the postman i can post the same url with the same header and body and answer me with json 

{
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJiZX",
    "refresh": "Srbwtr7J"
}
 
my code:
 
let
                        creds = Extension.CurrentCredential(),
                       
                        Response =
                       
                            Web.Contents(
                                    
                                    server &"SignIn",
                                    [
                                        Headers = [
                                                    #"Content-Type" = "application/json",
                                                    #"api-version" = "1.0"
                                                    ],
                                        Content =
                                                    Text.ToBinary(
                                                                    Json.FromValue([
                                                                    username = creds[Username],
                                                                    password = creds[Password],
                                                                    afm = "",
                                                                    code = ""
                                                                    ])
                                                                )
                                    ]
                                        ),

                       
                       
                        JsonResponse = Json.Document(Response),
                        Token =  JsonResponse[token]
1 ACCEPTED SOLUTION
Doc-tan
Regular Visitor

I solved my problem with putting url, header and body in vars and used these in web.contents.

 

let
                        creds = Extension.CurrentCredential(),
                        urlToken = Server &"SignIn",
                       
                        HeadersToken = [#"Content-Type" = "application/json",#"api-version" = "1.0"],
                        BodyToken = Json.FromValue([
                                                username = creds[Username],
                                                password = creds[Password],
                                                afm = "",
                                                code = ""
                                                ]),


                        ResponseToken =
                         
                            Web.Contents(
                                    url,
                                    [
                                       Headers = HeadersToken ,
                                       Content = BodyToken
                                   
                                    ]
                                        ),
                        JsonResponseToken = Json.Document(ResponseToken),
                        Token =  JsonResponseToken[token]
                     
                   
                    in
                   
                    Token
 
 
Thank for all your answers!!

View solution in original post

6 REPLIES 6
Doc-tan
Regular Visitor

I solved my problem with putting url, header and body in vars and used these in web.contents.

 

let
                        creds = Extension.CurrentCredential(),
                        urlToken = Server &"SignIn",
                       
                        HeadersToken = [#"Content-Type" = "application/json",#"api-version" = "1.0"],
                        BodyToken = Json.FromValue([
                                                username = creds[Username],
                                                password = creds[Password],
                                                afm = "",
                                                code = ""
                                                ]),


                        ResponseToken =
                         
                            Web.Contents(
                                    url,
                                    [
                                       Headers = HeadersToken ,
                                       Content = BodyToken
                                   
                                    ]
                                        ),
                        JsonResponseToken = Json.Document(ResponseToken),
                        Token =  JsonResponseToken[token]
                     
                   
                    in
                   
                    Token
 
 
Thank for all your answers!!
Ray_Minds
Continued Contributor
Continued Contributor

Hello @Doc-tan  Please find the solution :
Before : 

Ray_Minds_1-1769104174373.png

The issue you’re experiencing with extracting thetoken from your custom connector is a common problem in Power Query when dealing with API responses.
Even though theAPI worksfinein Postman, Power Query requires careful handling of binary content and JSON parsing.
Here’s what’s happening:
1. Binary Response:Web.Contentsalwaysreturns a binary.You cannot directly treat it as text or JSON. If you try to reference a key beforeparsing, Power Query throwserrors like“Cannot convert a value of type Binary to type Text”.
2. JSONParsing: Onceyou parsethebinary with Json.Document, theoutput is a record, not text. To access thetoken field, you must ensure: oTheresponseis valid JSON. The key matches exactly (Power Query iscase-sensitive). In your API response, the key is"token", not "Token"

Ray_Minds_2-1769104289922.png

 

 

 

v-hjannapu
Community Support
Community Support

Hi @Doc-tan,
Thank you  for reaching out to the Microsoft fabric community forum.

The problem is happening inside the Power Query custom connector. In Power Query, the response coming from Web.Contents is treated as Binary by default. But later in the code, it’s being read like normal text/JSON. Because of this mismatch, Power Query throws the error saying it can’t convert Binary to Text, and the token is not getting read.

So this is not related to headers, body, or login details. It’s only a response handling issue in the connector. Once the response is properly handled as JSON, you should be able to access the token without any problem.

please go through with the below document hope it may resolve your Issue:
Json.Document - PowerQuery M | Microsoft Learn
Web.Contents - PowerQuery M | Microsoft Learn
Hope the above provided information help you resolve the issue, if you have any further concerns or queries, please feel free to reach out to us.
Regards,
Community Support Team.

Hi @Doc-tan,
I hope the information provided above assists you in resolving the issue. If you have any additional questions or concerns, please do not hesitate to contact us. We are here to support you and will be happy to help with any further assistance you may need.

Regards,
Community Support Team.


Hello, 
I think this Web.Contents - PowerQuery M | Microsoft Learn help me to change my code.

Hi @Doc-tan,
Thank you for sharing the update. If you encounter any problems or have questions after going through the document, feel free to reach out here.

Regards,
Community Support Team.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.