Forum Discussion
Custom connector API - TOKEN (error binary)
- 8 months ago
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!!
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"