Make POST request from RapidAPI in Power Query (credential key required)

Occasional Contributor

I'm trying to build a query out of PQ to fetch a list of available currencies out of an Investing.com data repository located within RapidAPI.

 

The endpoint uses POST method and RapidAPI requires a credential key.

 

Below is the snippet of the HTTP type code for such request:

 

POST /currencies/get-list-currency HTTP/1.1
X-Rapidapi-Key: ***MY_RapidAPI_KEY***
X-Rapidapi-Host: investing4.p.rapidapi.com
Host: investing4.p.rapidapi.com

 

The endpoint URL is as follows (sitting as a standalone query in text format on PQ):

URL_FX_Lista_Pareshttps://investing4.p.rapidapi.com/currencies/get-list-currency

 

There is no other requested input field, such as country names or such, but there are a couple of what appears to me to be required credentials that apparently need to be sent ("X-Rapidapi-Key:" which I'm illustrating as "***MY_RapidAPI_KEY***" for this purpose, and "X-Rapidapi-Host") and then expect to return the desired list of currencies.

 

At least that's the process I've been led to believe that shall happen every time we run a POST request method (I'm a newbie on this...).

 

Then from some tutorials I've been seeing around I turned those 2 credentials info into an Excel table "Creds" and then created a new query also called "Creds" whose goal is to turn this table into a binary JSON file:

 

let
    Source = Excel.CurrentWorkbook(){[Name="Creds"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Campo", type text}, {"Valor", type text}}),
    #"Transposed Table" = Table.Transpose(#"Changed Type"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
    #"Changed Type Text" = Table.TransformColumnTypes(#"Promoted Headers",{{"X-RapidAPI-Key", type text}, {"X-RapidAPI-Host", type text}}),
    TableRecords = Table.ToRecords(#"Changed Type Text"){0},
    JSONRecords = Json.FromValue(TableRecords)
in
    JSONRecords

 

Then finally I created a final query called "FX_Lista_Pares_POST_Req" that should put it all together:

 

let
    Source = Json.Document(
        Web.Contents(
            URL_FX_Lista_Pares, 
            [
                Headers = [#"Content-Type" = "application/json"], 
                Content = Creds
            ]
        )
    )
in
    Source

 

 

But instead of getting the requested info all I get is the following error message:

PQ_Creds_Error.png

 

And if I go to "Edit Credentials" I still keep getting the same issue on the window editor that pops up.

 

By investigating around I landed on this Microsoft Docs page Web.Contents - PowerQuery M | Microsoft Docs which states that "POST requests may only be made anonymously", so I was wondering whether I'm missing something on my M code or PQ just does not support POST requests that require a credential key, but being that the case, is there a piece of code/technique that would serve as a work around?

 

Any help is greatly appreciated.

 

Leonardo

0 Replies