Forum Discussion
Power Query- M Language - Failure to Request a json service API -
- 4 years ago
Hi JoseJunior22 ,
This is because you are using an incorrect access token:
authToken = "bearer " & access_token
It is not necessary to prefix the token with "bearer". Please use the following code.
let body = "{ ""grant_type"" : ""client_credentials"" }", minhaURL = "https://api.anbima.com.br/oauth/access-token", getToken = Json.Document(Web.Contents(minhaURL, [ Headers=[#"Content-Type"="application/json", #"Authorization" = "Basic "&Binary.ToText(Text.ToBinary("Uw6QvcZwzRtp:qaRCeKStnXhE"), 0) ], Content=Text.ToBinary(body)]) ), access_token = getToken[access_token], //urlRequest= path & "/feed/precos-indices/v1/titulos-publicos/curvas-juros", urlRequest = "https://api-sandbox.anbima.com.br/feed/precos-indices/v1/titulos-publicos/mercado-secundario-TPF", //keyPhrases = KeyPhrases(), results = Json.Document(Web.Contents( urlRequest, [ Headers=[#"Content-Type"="application/json", client_id = "Uw6QvcZwzRtp", access_token = access_token ] ] ) ) in resultsIf the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi JoseJunior22 ,
This is because you are using an incorrect access token:
authToken = "bearer " & access_token
It is not necessary to prefix the token with "bearer". Please use the following code.
let
body = "{
""grant_type"" : ""client_credentials""
}",
minhaURL = "https://api.anbima.com.br/oauth/access-token",
getToken = Json.Document(Web.Contents(minhaURL,
[
Headers=[#"Content-Type"="application/json",
#"Authorization" = "Basic "&Binary.ToText(Text.ToBinary("Uw6QvcZwzRtp:qaRCeKStnXhE"), 0)
],
Content=Text.ToBinary(body)])
),
access_token = getToken[access_token],
//urlRequest= path & "/feed/precos-indices/v1/titulos-publicos/curvas-juros",
urlRequest = "https://api-sandbox.anbima.com.br/feed/precos-indices/v1/titulos-publicos/mercado-secundario-TPF",
//keyPhrases = KeyPhrases(),
results = Json.Document(Web.Contents(
urlRequest,
[
Headers=[#"Content-Type"="application/json",
client_id = "Uw6QvcZwzRtp",
access_token = access_token
]
]
)
)
in results
If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.