Search code examples
authenticationpowerbibasic-authenticationpowerbi-desktophttp-status-code-500

Error 500 with Basic Authorization and body content in Power Bi (API)


I can't get a connection with login and password (Basic Authorization) for an API.

= let apiUrl = "(censored)",
body = Text.ToBinary("
{
    ""codEmitenteIni"": 000000,
    ""codEmitenteFin"": 999999,
    ""tipoRelatorio"": ""detalhado""
}
"),
result = Json.Document(Web.Contents(apiUrl,[Headers=[#"Authorization"="Basic login:password"], Content=body]))
in
result

Error:

DataSource.Error: '*[...]*' (500) or return a HTML login page

I tried to change "Authorization" to "Accept-Charset" or "Accept" and it still does not work.

The request in postman it's working! It's a totvs API.


Solution

  • Do you encode login and password? In basic authentication, the value sent in the Authorization header should start with the Basic part, then have a base64 url-encoded value of the string created by concatenating login, :, and password.

    Postman does it automatically for you. Inspect the actual Authorization header that is sent in the Postman request. You should see something like Basic bG9naW46cGFzc3dvcmQ=.