Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
felipe_pinto
Helper I
Helper I

Multiple criteria for API Power Query

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

 

felipe_pinto_0-1653481785317.png

Could someone help me?

Best regards

1 ACCEPTED SOLUTION
v-kkf-msft
Community Support
Community Support

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.

 

vkkfmsft_0-1653877652481.png

vkkfmsft_1-1653877898809.png

 

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.

View solution in original post

2 REPLIES 2
felipe_pinto
Helper I
Helper I

@v-kkf-msft Thank you so much!! You helped me a lot!! Now, that's working!! 

Ragards!

v-kkf-msft
Community Support
Community Support

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.

 

vkkfmsft_0-1653877652481.png

vkkfmsft_1-1653877898809.png

 

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.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors