Announcement

Collapse
No announcement yet.

API Always returning Unauthorized

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • xoroz
    replied
    Hey.. I had some problem! Lost like an hour to get it working.. Documentation is very poor of EXAMPLES. Please update documentation with real example using curl.



    alvaro try:

    D="https://centreon.local/centreon/api/"
    TOKEN=$(curl -s -X POST -F 'username=admin' -F 'password=sQ123CgUy39rj' "${D}index.php?action=authenticate" | jq '.authToken' |sed 's/"//g')
    if [ $? -eq 0 ]; then
    echo "OK - Got Auth Token $TOKEN"
    else
    echo "ERROR - Could not get Auth Token"
    exit 2
    fi

    URL="${D}index.php?action=list&object=centreon_rea ltime_services&limit=60&viewType=problems&sortType =name&order=desc&fields=id,description,host_id,hos t_name,state,output"
    curl -vv -H "Content-Type: application/json" -H "centreon-auth-token: $TOKEN" $URL


    NOTE1:
    I am still not able to list service by getting only CRITICAL status...

    URL="${D}index.php?action=list&object=centreon_rea ltime_services&viewType=problems&status=critical&f ields=host_name,state,output"

    Lost another hour and no success... documentation is wrong or api broken? I tried also state=2 or status=2 nothing worked I am running
    Centreon 2.8.24

    let me know if it works for you...

    I find this API is hard to work with


    NOTE2: If it dosent work try using LOCAL account just for that case.


    cheers,
    Felipe Ferreira
    https://felipeferreira.net

    Last edited by xoroz; 5th March 2019, 12:35.

    Leave a comment:


  • Alvaro Irontec
    started a topic API Always returning Unauthorized

    API Always returning Unauthorized

    My , dozens times tried, requests :

    - Request *AUTH* :

    curl -s -k -X POST -d "username=myuser&password=mypassword" https://mycentreonserver.com/centreo...n=authenticate

    -====> Authenticated returned token: "NWMyY2IwMGNkMTI2MDkuMTMzNjkwODk="
    - Peticion *LIST* :

    curl -H 'Content-Type: application/json' -H 'centreon-auth-token: "NWMyY2IwMGNkMTI2MDkuMTMzNjkwODk="' https://mycentreonserver.com/centreo...ts&action=list

    -====> "Unauthorized"


    I've checked both checkboxes "Reach API Configuration" and "Reach API realtime" at my Centreon >> Configurations >> Contacts Users <myuser> >> Centreon Authentication

    Authentication source is LDAP.

    Any idea please ? I've tested this many times, googled a lot and all I found is an old "change centreon_auth_token by centreon-auth-token" ...nothing else
Working...
X