Supplies are limited. Contact info@espc.tech right away to save your spot before the conference sells out.
Get your discountScore big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount
Hello guys,
I'm having troubles about creating multiples criteria with API in Power Query.
I have this code below where I try to get the data by API. My question is: I have two criteria "UF" and "CNPJ", both can change the value depending of my data base. The criteria for CNPJ is working, but for the "UF", is not and I dont understand why.
See below:
(UF as text, CNPJ as number) =>
let
content = Json.Document(Web.Contents("https://api.directd.com.br/consultas/sintegra/v1/consulta-pj?TOKEN="token value"&UF=" &Text.PadStart((UF),2)&" "&"CNPJ=" &Text.PadStart(Number.ToText(CNPJ),14,"0")& "&async=habilitar")),
Delay = Function.InvokeAfter(content, #duration(0,0,0,5))
in
content
Could someone help me?
Best regards
Solved! Go to Solution.
Hi @felipe_pinto ,
There seems to be a problem with the placement of the double quotes in your code, please try the following code.
(UF as text, CNPJ as number) =>
let
content = Json.Document(Web.Contents("https://api.directd.com.br/consultas/sintegra/v1/consulta-pj?token={token}" & "&uf=" & Text.PadStart(UF,2) & "&cnpj=" &Text.PadStart(Number.ToText(CNPJ),14,"0") & "&async=habilitar")),
Delay = Function.InvokeAfter(content, #duration(0,0,0,5))
in
content
Also, according to the API documentation, the uf parameter requires two characters. But if I use Postman for testing and enter "spaces + a single character" in the uf parameter, it will return an error. So please try using two non-empty characters and see if it returns the correct result.
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.
@v-kkf-msft Thank you so much!! You helped me a lot!! Now, that's working!!
Ragards!
Hi @felipe_pinto ,
There seems to be a problem with the placement of the double quotes in your code, please try the following code.
(UF as text, CNPJ as number) =>
let
content = Json.Document(Web.Contents("https://api.directd.com.br/consultas/sintegra/v1/consulta-pj?token={token}" & "&uf=" & Text.PadStart(UF,2) & "&cnpj=" &Text.PadStart(Number.ToText(CNPJ),14,"0") & "&async=habilitar")),
Delay = Function.InvokeAfter(content, #duration(0,0,0,5))
in
content
Also, according to the API documentation, the uf parameter requires two characters. But if I use Postman for testing and enter "spaces + a single character" in the uf parameter, it will return an error. So please try using two non-empty characters and see if it returns the correct result.
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.