6.1. OpenNAC API-Doc

The OpenNAC Enterprise Application Programming Interface (API), shows a formal specification about how external software modules can communicate with OpenNAC Enterprise

You can access the OpenNAC Enterprise API documentation through a web browser using the HTTPS protocol to your OpenNAC web console by adding /api-doc in the end.

https://<open_core_ip>/api-doc

The Administration Portal will appear.

../_images/api1.png


It is necessary to log in with our credentials. The first time we access it, we won’t have access to the API doc and we will see the following message:

../_images/api2.png


It is necessary, then, to access the Administration Portal and go to Configuration -> Configuration Vars -> Generic.

https://<open_core_ip>/admin
../_images/api3.png


The Allow access to API Documentation (api-doc) flag must be changed to yes to allow access to the API-Doc. Save the changes by clicking on the Save button and try to access the /api-doc again.

../_images/api4.png


We will see that now we have access to the API-Doc.

../_images/api5.png


First, we need to authorize our user in the API, and get the API Key. The first API call will allow us to authorize our user.

../_images/api6.png


We can see that for every call we have the parameters needed, with an example of them, and the responses expected. And most important, we have a button called Try it out that allows us to execute the selected call.

By clicking on Try it out we will see the following:

../_images/api7.png


In the blank box, you can enter the parameters needed for the call.

In this case we want to execute this call to get the API Key for the user admin with password opennac. We click on execute to get the API response:

../_images/api8.png


A call to the API has been completed. We can see the curl executed for that call and the response of the API. In this case, we have the API has returned the API Key for admin user.

Once we have the API Key, we need to go to the Authorize button on the top right.

../_images/api10.png


We need to add the token of the previous API call.

../_images/api11.png


As we can see, we would get access to the API.

../_images/api13.png


Now, we can execute all the API calls that we can find on the API Doc.