Forum Discussion
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
I solved my problem with putting url, header and body in vars and used these in web.contents.
letcreds = 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]inTokenThank for all your answers!!
6 Replies
- v-hjannapuCommunity 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.- v-hjannapuCommunity Support
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.- Doc-tanRegular Visitor
Hello,
I think this Web.Contents - PowerQuery M | Microsoft Learn help me to change my code.
- Ray_MindsSolution Supplier
Hello Doc-tan Please find the solution :
Before :
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" - Doc-tanRegular Visitor
I solved my problem with putting url, header and body in vars and used these in web.contents.
letcreds = 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]inTokenThank for all your answers!!