Forum Discussion

SylvainN's avatar
SylvainN
Frequent Visitor
2 years ago
Solved

Try to convert curl into powerquery

the Curl where it work

curl --location --request POST "https://MyWebSite:3129/v1/blocklist" ^
--header "X-APIKey: MyKey" ^
--Content-Type"="application/json

 

the answer is {"error":"Success","response":{"blocklists":[{"blocklistid":"11111111111","name":"Serveur 2008"}]}}

 

And the powerquery


let
url = "https://MyWebSite:3129/v1/blocklist",
headers = [#"X-APIKey" ="MyKey",
#"Content-Type"="application/json"],
response = Web.Contents(
url,
[ Headers = headers ]
),
jsonResponse = Json.Document(response)
in
jsonResponse

 

 

Error from powerquery

DataSource.Error: Web.Contents failed to get contents from 'https://MyWebSite:3129/v1/blocklist' (405): Method Not Allowed
Details:
DataSourceKind=Web
DataSourcePath=https://MyWebSite:3129/v1/blocklist
Url=https://MyWebSite:3129/v1/blocklist

 

Don't understand why it not working, thx for the help

  • Ok it good to know I need to specify a payload, but don't know how to apply, I read the website but do not find the info how to apply payload

    I try to appy this 

    let
    url = ...,
    headers = [#"Content-Type" = "application/json"],
    postData = Json.FromValue([x = 235.7, y = 41.53]),
    response = Web.Contents(
    url,
    [
    Headers = headers,
    Content = postData
    ]
    ),
    jsonResponse = Json.Document(response)
    in
    jsonResponse


    let
    url = "https://my website:3129/v1/blocklist",
    headers = [#"X-APIKey" ="my key",
    #"Content-Type"="application/json"],
    postData = Json.FromValue([""]),
    response = Web.Contents(
    url,
    [ Headers = headers
    Content = postData
    ]
    ),
    jsonResponse = Json.Document(response)
    in
    jsonResponse

6 Replies

  • SylvainN's avatar
    SylvainN
    Frequent Visitor

    I'm quite new to powerbi but how do I specify a payload, could you give me an example?

    Or maybe this can work

    postData = Json.FromValue([""]),


  • SylvainN's avatar
    SylvainN
    Frequent Visitor

    Ok it good to know I need to specify a payload, but don't know how to apply, I read the website but do not find the info how to apply payload

    I try to appy this 

    let
    url = ...,
    headers = [#"Content-Type" = "application/json"],
    postData = Json.FromValue([x = 235.7, y = 41.53]),
    response = Web.Contents(
    url,
    [
    Headers = headers,
    Content = postData
    ]
    ),
    jsonResponse = Json.Document(response)
    in
    jsonResponse


    let
    url = "https://my website:3129/v1/blocklist",
    headers = [#"X-APIKey" ="my key",
    #"Content-Type"="application/json"],
    postData = Json.FromValue([""]),
    response = Web.Contents(
    url,
    [ Headers = headers
    Content = postData
    ]
    ),
    jsonResponse = Json.Document(response)
    in
    jsonResponse

    • lbendlin's avatar
      lbendlin
      Icon for Super User rankSuper User

      Did it work?

       

      Try

       

      postData = Json.FromValue([x=0]),

  • SylvainN's avatar
    SylvainN
    Frequent Visitor

    Find the payload


    let
    url = "https://mywebsite:3129/v1/blocklist",
    headers = [#"X-APIKey" ="my key",
    #"Content-Type"="application/json"],
    body = "{""}",
    response = Web.Contents(
    url,
    [ Headers = headers,
    Content = Text.ToBinary((body))
    ]
    ),
    jsonResponse = Json.Document(response),
    response1 = jsonResponse[response],
    blocklists = response1[blocklists],
    blocklists1 = blocklists{0},
    #"Converted to Table" = Record.ToTable(blocklists1)
    in
    #"Converted to Table"