cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
oguedda
Helper I
Helper I

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 4
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}"]])),

AbirEzzahra
New Member

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, 

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

 

RicoZhou
Community Support
Community Support

Hi @oguedda 

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. 

 

Helpful resources

Announcements
Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May 23 2022 epsiode 5 without aka link.jpg

The Power BI Community Show

Welcome to the Power BI Community Show! Jeroen ter Heerdt talks about the importance of Data Modeling.

Power BI Dev Camp Session 22 with aka link 768x460.jpg

Check it out!

Mark your calendars and join us on Thursday, May 26 at 11a PDT for a great session with Ted Pattison!

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!