Skip to main content
Solved

How to authenticate on Centreon's Rest API (v1)

  • June 12, 2024
  • 2 replies
  • 635 views

Forum|alt.badge.img+1

I'm attempting to obtain the authentication token for Centreon's REST API using the ARC client API. Currently, I'm running Centreon version 22.10 and referring to the API documentation (https://docs.centreon.com/docs/22.10/api/rest-api-v1/).

I'm simply including my credentials in the body of my POST query in JSON format like this:

{

  "username": "user_name",

  "password": "admin_passwd"

}

the url i used is 'https://local_domain/centreon/api/index.php?action=authenticate'

However, I'm receiving a 'bad parameters' error response, which I'm unsure how to resolve. I've already checked the syntax using a JSON checker.

I've also tried using Postman with the v2 API, but encountered the same error. Could anyone provide assistance?

Best answer by Stéphane LE CAËR

Here is a test using cURL

curl -s -d "username=my_user&password=my_password" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://centreon-central/centreon/api/index.php?action=authenticate

Another in Python

import requests

username = "my_username"
password = "my_password"

centreon_api_url = "http://my_centreon_central/centreon/api/index.php"
payload = {"username": username,
"password": password
}

param = "action=authenticate"

url = f"{centreon_api_url}?{param}"

r = requests.post(url, data=payload, timeout=300)

if r.ok:
jr = r.json()
print(jr["authToken"])

cCq4owFVqRi53Kmc+mJ0O4UJjSCkObXntO/iSjSn9OkXsZf0+iQfV1U35eyqlEWH

 

2 replies

Stéphane LE CAËR
Forum|alt.badge.img+6

Here is a test using cURL

curl -s -d "username=my_user&password=my_password" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://centreon-central/centreon/api/index.php?action=authenticate

Another in Python

import requests

username = "my_username"
password = "my_password"

centreon_api_url = "http://my_centreon_central/centreon/api/index.php"
payload = {"username": username,
"password": password
}

param = "action=authenticate"

url = f"{centreon_api_url}?{param}"

r = requests.post(url, data=payload, timeout=300)

if r.ok:
jr = r.json()
print(jr["authToken"])

cCq4owFVqRi53Kmc+mJ0O4UJjSCkObXntO/iSjSn9OkXsZf0+iQfV1U35eyqlEWH

 


Forum|alt.badge.img+1
  • Author
  • Steward *
  • 1 reply
  • June 14, 2024

This worked for me, thank you !