7.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 login page will be displayed.

../_images/admin2beta.png


It is necessary to log in using our credentials. However, during the initial login, we may not have immediate access to the API documentation and encounter the following message:

../_images/api2.png


If you are using the Default Portal, go to the Configuration > Configuration Vars > Generic section.

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


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

If you are using the NextGen Portal, go to the Configure > Configuration > Configuration Vars > General -Frontend section.

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


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

Now, you should 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.