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
jofujofu
Frequent Visitor

Web.contents / POST / Wrong Content body (Attribute structure?) / incl. python test programm (proof)

HI,

I am trying to request an external API by bearer Auth with POST method!

Tried with python - it works - see coding My first attempt before starting with MQUERY. Then I tried with postman - it works - to construct the POST Method with Header/Content right again - getting a valid response.

Surfed the forum for many articles for this issue. Found many hints, but no solutions!


Doing the same (until now I see no difference in the code) with mQuery/Web.Contents i got an "data source error"?:

DataSource.Error: Fehler beim Abrufen von Inhalten von "https://api.xxx.at/xxxx/show" (500) durch "Web.Contents": Internal Server Error
Details:
DataSourceKind=Web
DataSourcePath=https://api.xxx.at/xxxx/show
Url=https://api.xxx.at/xxxx/show

Authentification is ok. Looking at the Python code and Postman-Stuff it worked!

Exept the API provider says that the POST Calls must be on HTTP 1.0...?!

But in the following MQUERY there must something different.

 

let
AuthKey = "Bearer xxxxxxxxx",
url = "https://api.xxxx.at/xxxxxx/show",
body = "{""contenttype"": ""application/json"",""format"": ""JSON"",""unikeys"": ""10824500458375491455+7349109128639561310""}",
vHeaders = [#"Authorization"=AuthKey, #"Content-Type"="application/x-www-form-urlencoded"],
Parsed_JSON = Json.Document(body),
qbody = Uri.BuildQueryString(Parsed_JSON),
vBody = Text.ToBinary(qbody),
Source = Json.Document(Web.Contents(url,[Headers = vHeaders, Content = vBody]))
in
Source

Tried the whole weekend to find a solution.... . Therefor I ask the forum for help!

 

To see my python coding:

import requests
contenttype = "application/json"
format = "JSON"
unikeys = "10824500458375491455+7349109128639561310"

headers={"Authorization": "xxxxxxxx", "Content-Type": "application/x-www-form-urlencoded"}
data={"contenttype": contenttype, "format": format, "unikeys": unikeys}
resp = requests.post("https://api.xxx.at/xxxx/show", headers=headers, data=data, timeout=120)
print(resp.text)

#Output is fine! Something like ... JSON...
{
  "results": [
    {
      "uk": "10824500458375491455",
      "head": {
          "VORSPANN": {
            "type": "TEXT",
            "value": [
              "\"Tiro....

 

Thanks alot for your support!

Regards 

Josef

1 ACCEPTED SOLUTION
V-pazhen-msft
Community Support
Community Support

@jofujofu 

For this kind of coding issue that we are not able to reproduce, you need to create a support ticket  Support | Microsoft Power BI with Pro licences. 

 

Before that you might check the discussion in this post.

M Query to use POST method on a Web API - Microsoft Power BI Community

 

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
V-pazhen-msft
Community Support
Community Support

@jofujofu 

For this kind of coding issue that we are not able to reproduce, you need to create a support ticket  Support | Microsoft Power BI with Pro licences. 

 

Before that you might check the discussion in this post.

M Query to use POST method on a Web API - Microsoft Power BI Community

 

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

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.

Top Solution Authors