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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

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
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.