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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

power query Post request to Web API

Dear Community,

I am trying to connect Power BI with Web Api.

 

This one is working.

let
    Source = Json.Document(Web.Contents("http://api-pub.dudooeat.com/auth/getAccessToken", [Headers=[#"X-Api-Key"="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx755"]]))
in
    Source

 

I try to post the query, the API show error

let
    refreshAccessToken=Json.Document(Web.Contents("http://api-pub.dudooeat.com/auth/getAccessToken", [Headers=[#"X-Api-Key"="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx755"]])),
    body="scope=all",
    Source = try Json.Document(Web.Contents("http://api-pub.dudooeat.com/sales/listCompanyId",[Headers=[#"Access-Token-Api"=refreshAccessToken,#"Content-type"="application/x-www-form-urlencoded",#"Content-Length"="6"],Content=Text.ToBinary(body)]))
in
    Source

 Is there any error in my query? 😞

7 REPLIES 7
PhilipTreacy
Super User
Super User

Hi @Anonymous 

In your 3rd step you have

 

data = Source1[data]

 

 

But Source1 (the JSON) doesn't contain a record named data - that's what's causing your error.

 

For debugging purposes remove all steps after Source1 = ..... and make sure to remove the comma at the end of the Source1 step too.  You also need to tell the query what value is the result.

You should end up with something like this

 

let
   body = .......
   Source1 = ......
in
   Source1

 

 

You can now check what Source1 is actually returning and go from there.

Regards

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


PhilipTreacy
Super User
Super User

Hi @Anonymous 

Your first step is returning a Record, not text. Click on the refreshAccessToken step andyou'll see what I mean.

record-returned.png

So the body parameter is being set to a Record and this is throwing the error.

 

I can't tell you what's in the Record (its structure) as I don't actually have access to the API.  But as you are trying to get the AccessToken I imagine the record will have a field in it named something like Token.  You can check by clicking beside the Record as you did to see the error message.

 

So assuming the Access Token is in a field called Token you need to change the Headers in your second web request to 

 

 

#"Access-Token-Api"=refreshAccessToken[Token]

 

 

Just match the field name from the record in the Header.

Let me know how you get on.

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

Hi, @PhilipTreacy 

I try to avoid the error and use this methods

But found another problem

When I'm in Query Editor I can see the data tables with zero issues, but every single time when I try to do Close & Apply it failed

Betty1211_0-1608190221734.png

Betty1211_1-1608190504609.png

 

Best regards

PhilipTreacy
Super User
Super User

Hi @Anonymous 

Not enough info to know how to help.  The error message willsay more than just Expression.Error - what's the full error message?

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

Hi @PhilipTreacy 

Sorry I did not pay attention.

Put a photo to complete the problem.

Thank you for your help.

error.PNG

PhilipTreacy
Super User
Super User

Hi @Anonymous 

That code is syntactically ok.

What's the error you are getting?

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

@PhilipTreacy 
It shows Expression.Error,but I don't know where is the problem

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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