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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
yaelmo
New Member

Post Request with Power Query

Hey,

Hi I am trying to send a REST POST API request.
This is the URL: https://api.mypurecloud.de/api/v2/analytics/conversations/aggregates/query
This is the body: 

{
  "interval""2022-04-18T08:00:00.000Z/2022-04-18T08:30:00.000Z",

  "groupBy": [
    "userId"
  ],
  "metrics": [
    "tTalk"
  ],
  "filter": {
    "type""and",
    "predicates": [
      {
        "dimension""mediaType",
        "value""voice"
      }
    ]
  }
}
 
This is how it looks like in Postman:
yaelmo_1-1650827327083.png

 

 
And this is the response:
 
yaelmo_0-1650827093533.png

 

 

I'm trying to send this request in PowerBI, and this is what i got until far.
I don't know where am I wrong...

let
url="https://api.mypurecloud.de/api/v2/analytics/conversations/aggregates/query",
body= "{

""interval"": ""2022-04-18T08:00:00.000Z/2022-04-18T08:30:00.000Z"",

""groupBy"": [
""userId""
],
""metrics"": [
""tTalk""
],
""filter"": {
""type"": ""and"",
""predicates"": [
{
""dimension"": ""mediaType"",
""value"": ""voice""
}
]
},
""paging"": {
""pageSize"": 25,
""pageNumber"": 1
}

}",

json="{""mediaType"":""voice"",""userId"":"" ************* "",""interval"":""2022-04-18T08:00:00.000Z/2022-04-18T08:30:00.000Z"",""metric"":""tTalk"",""max"":""52950"",""min"":""52950"",""count"":""1"",""sum"":""52950""}",
Parsed_JSON = Json.Document(json),
BuildQueryString = Uri.BuildQueryString(Parsed_JSON),
WebCall = Web.Contents(url, [Headers=[Authorization="Bearer ***************************", Accept="application/json", #"Content-Type"="application/json"]]),
LinesFromBinary = Lines.FromBinary(WebCall),
#"Converted to Table" = Table.FromList(LinesFromBinary, Splitter.SplitTextByDelimiter(":"), null, null, ExtraValues.Error)
in
#"Converted to Table"


yaelmo_2-1650827573440.png

 

Would appreciate your help 🙂

@Anonymous @Post

1 ACCEPTED SOLUTION
artemus
Employee
Employee

We don't support authenticating to a website in this way. The only supported way is to use a custom connector.

 

That being said:

To make a POST call add:

WebCall = ... #"Content-Type"="application/json"],Content=Json.Document(Parsed_JSON)])

 

You can remove the unused BuildQueryString = Uri.BuildQueryString(Parsed_JSON),

View solution in original post

4 REPLIES 4
artemus
Employee
Employee

We don't support authenticating to a website in this way. The only supported way is to use a custom connector.

 

That being said:

To make a POST call add:

WebCall = ... #"Content-Type"="application/json"],Content=Json.Document(Parsed_JSON)])

 

You can remove the unused BuildQueryString = Uri.BuildQueryString(Parsed_JSON),

@artemus -It worked, thank you! 

ImkeF
Super User
Super User

Hi @yaelmo ,
you have to use the "Content"-parameter to create a POST request in Power Query:
Easy POST requests with Power BI and Power Query using Json.FromValue – The BIccountant

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

This is my first time working with Power Query, I didn't understand how i need to apply this on my request.
Can you please guide me in more detail?

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Solution Authors
Top Kudoed Authors