|
1 | 1 | --- |
2 | 2 | # Introduction |
3 | | -pfSense API is a fast, safe, full-fledged HTTP API. This works by leveraging the same PHP functions and processes used by pfSense's webConfigurator into API endpoints to create, read, update and delete pfSense configurations. All API endpoints enforce input validation to prevent invalid configurations from being made. Configurations made via API are properly written to the master XML configuration and the correct backend configurations are made preventing the need for a reboot. All this results in the fastest, safest, and easiest way to automate pfSense! |
| 3 | +pfSense API is a fast, safe, full-fledged HTTP API. This works by leveraging the same PHP functions and processes used |
| 4 | +by pfSense's webConfigurator into API endpoints to create, read, update and delete pfSense configurations. All API |
| 5 | +endpoints enforce input validation to prevent invalid configurations from being made. Configurations made via API are |
| 6 | +properly written to the master XML configuration and the correct backend configurations are made preventing the need for |
| 7 | + a reboot. All this results in the fastest, safest, and easiest way to automate pfSense! |
4 | 8 |
|
5 | 9 | # Installation |
6 | 10 | To install pfSense API, simply run the following command from the pfSense shell:<br> |
7 | | -`pkg add https://github.com/jaredhendrickson13/pfsense-api/releases/download/v0.0.2/pfSense-2-4-pkg-API-0.0_2.txz`<br> |
| 11 | +`pkg add https://github.com/jaredhendrickson13/pfsense-api/releases/download/v0.0.3/pfSense-2-4-pkg-API-0.0_3.txz`<br> |
8 | 12 |
|
9 | 13 | To uninstall, run the following command:<br> |
10 | 14 | `pkg delete pfSense-pkg-API`<br> |
11 | 15 |
|
12 | | -_Note: if you do not have shell access to pfSense, you can still install via the webConfigurator by navigating to 'Diagnostics > Command Prompt' and enter the commands there_ |
| 16 | +_Note: if you do not have shell access to pfSense, you can still install via the webConfigurator by navigating to |
| 17 | +'Diagnostics > Command Prompt' and enter the commands there_ |
13 | 18 |
|
14 | 19 | # Requirements |
15 | 20 | - pfSense 2.4.4 or later is supported |
16 | | -- pfSense API requires a local user account in pfSense. The same permissions required to make configurations in the webConfigurator are required to make calls to the API endpoints |
17 | | -- While not an enforced requirement, it is STRONGLY recommended that you configure pfSense to use HTTPS instead of HTTP. This ensures that login credentials and/or API tokens remain secure in-transit |
| 21 | +- pfSense API requires a local user account in pfSense. The same permissions required to make configurations in the |
| 22 | +webConfigurator are required to make calls to the API endpoints |
| 23 | +- While not an enforced requirement, it is STRONGLY recommended that you configure pfSense to use HTTPS instead of HTTP. |
| 24 | + This ensures that login credentials and/or API tokens remain secure in-transit |
18 | 25 |
|
19 | 26 | # Authentication |
20 | | -By default, pfSense API uses the same credentials as the webConfigurator. This behavior allows you to configure pfSense from the API out of the box, and user passwords may be changed from the API to immediately add additional security if needed. Alternatively, you can configure pfSense API to create secure API client IDs and tokens for API users. To generate, or delete API keys you can navigate to `System > API` in the UI after installation, and change the authentication mode to `API Token`. |
| 27 | +By default, pfSense API uses the same credentials as the webConfigurator. This behavior allows you to configure pfSense |
| 28 | +from the API out of the box, and user passwords may be changed from the API to immediately add additional security if |
| 29 | +needed. After installation, you can navigate to System > API in the pfSense webConfigurator to configure API |
| 30 | +authentication. |
| 31 | + |
| 32 | +To authenticate your API call, follow the instructions for your configured authentication mode: |
| 33 | + |
| 34 | +- Local Database (default) : Uses the same credentials as the pfSense webConfigurator. To authenticate API calls, simply |
| 35 | +add a `client-id` value containing your username and a `client-token` value containing your password to your payload. For |
| 36 | +example `{"client-id": "admin", "client-token": "pfsense"}` |
| 37 | + |
| 38 | +- JWT : Requires a bearer token to be included in the `Authorization` header of your request. To receive a bearer token, |
| 39 | +you may make a POST request to /api/v1/access_token/ and include a `client-id` value containing your pfSense username |
| 40 | +and a `client-token` value containing your pfSense password to your payload. For example |
| 41 | +`{"client-id": "admin", "client-token": "pfsense"}`. Once you have your bearer token, you can authenticate your API |
| 42 | +call by adding it to the request's authorization header. (e.g. `Authorization: Bearer xxxxxxxx.xxxxxxxxx.xxxxxxxx`) |
| 43 | + |
| 44 | +- API Token : Uses standalone tokens generated via the UI. These are better suited to distribute to systems as they are |
| 45 | +revocable and will only allow API authentication and not UI or SSH authentication (like the local database credentials). |
| 46 | +To generate or revoke credentials, navigate to System > API within the UI and ensure the Authentication Mode is set to |
| 47 | +API token. Then you should have the options to configure API Token generation, generate new tokens, and revoke existing |
| 48 | +tokens. Once you have your API token, you may authenticate your API call by adding a `client-id` value containing your |
| 49 | +API token client ID and a `client-token` value containing your API token client token to your payload. |
| 50 | +(e.g. `{"client-id": "cccdj-311s", "client-token": "42jkjl-k234jlk1b38123kj3kjl-ffwzzuilaei"}` |
21 | 51 |
|
22 | 52 | # Response Codes |
23 | 53 | `200 (OK)` : API call succeeded<br> |
24 | 54 | `400 (Bad Request)` : An error was found within your requested parameters<br> |
25 | | -`401 (Unauthorized)` : API client has not completed authentiation or authorization successfully<br> |
| 55 | +`401 (Unauthorized)` : API client has not completed authentication or authorization successfully<br> |
26 | 56 | `403 (Forbidden)` : The API endpoint has refused your call. Commonly due to your access settings found in `System > API`<br> |
27 | 57 | `404 (Not found)` : Either the API endpoint or requested data was not found<br> |
28 | 58 | `500 (Server error)` : The API endpoint encountered an unexpected error processing your API request<br> |
29 | 59 |
|
30 | 60 | # Error Codes |
31 | | -A full list of error codes can be found by navigating to /api/v1/system/api/errors/ after installation. This will return JSON data containing each error code and their corresponding error message. No authentication is required to view the error code library. This also makes API integration with third-party software easy as the API error codes and messages are always just an HTTP call away! |
| 61 | +A full list of error codes can be found by navigating to /api/v1/system/api/errors/ after installation. This will return |
| 62 | + JSON data containing each error code and their corresponding error message. No authentication is required to view the |
| 63 | + error code library. This also makes API integration with third-party software easy as the API error codes and messages |
| 64 | + are always just an HTTP call away! |
32 | 65 |
|
33 | 66 | # Rate limit |
34 | | -There is no limit to API calls at this time |
| 67 | +There is no limit to API calls at this time. Alternatively, you enable the API in read-only mode to only allow endpoints |
| 68 | +with read access within System > API. |
0 commit comments