Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Connect to REST API using X-AUTH-TOKEN and POST method (ERROR : please specify how to connect)

Hello everybody, i tried to connect to rest api using X-AUTH-TOKEN and POST method but i got this error :

 

Please specify how to connect

 here is the code :

let
url = "https://centreon.xxxxxxx/centreon/api/v2/login",
GetJson = Web.Contents(url,
[
Headers = [#"Accept"="application/json",
#"Content-Type"="application/Json"],
Content = Text.ToBinary("{""security"": {""credentials"": {""login"": ""xxxxxxxx"",""password"": ""xxxxxxxx""}}")
]
),
FormatAsJson = Json.Document(GetJson),
// Gets token from the Json response
AccessToken = FormatAsJson[token],
AccessTokenHeader = "X-AUTH-TOKEN " & AccessToken,
GetJsonQuery = Web.Contents("https://centreon.xxxxxxxx/centreon/api/beta/monitoring/hosts/",
[
Headers = [#"Authorization"=AccessTokenHeader]
]
),
FormatAsJsonQuery = Json.Document(GetJsonQuery)
in
FormatAsJsonQuery

in postman i got the right result with this information

curl --location --request POST 'https://centreon.xxxxxxxx/centreon/api/v2/login' \
--header 'Content-Type: application/json' \
--data-raw '{
  "security": {
    "credentials": {
      "login""xxxxxxxxxx",
      "password""xxxxxxxxxxx"
    }
  }
}'

and

curl --location --request GET 'https://centreon.xxxxxxxx/centreon/api/beta/monitoring/hosts/' \
--header 'X-AUTH-TOKEN: xxxxxxxxxxxxxxxx'

Thank you in advance for your answers,

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous 

    You may refer to this blog for more details: Web Services And POST Requests In Power Query

    You can try Anonymous access, for more details: Anonymous access

     

    Best Regards,

    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

     

  • Hello, 

    I really hope you have found the solution. If yes, would you please share it with us ? I am facing the same problem. 

    thank you, 

    • Anonymous's avatar
      Anonymous
      Not applicable

      hi, i am sorry i did not find a solution for this problem but i proceeded otherwise to resolve it. indeed I used an etl (talend) to establish the connection with Centreon and to import the necessary data into my data warehouse to then retrieve them on power bi. I hope it can help you.

      Good luck

       

  • JeffManley's avatar
    JeffManley
    Frequent Visitor

    In case you still needed an answer for this...the following worked for me

     

    let
    Source = Json.Document(Web.Contents("{add URL here}", [Headers=[#"Content-Type"="application/json", #"X-ApiToken"="{add token here}"]])),