Fortinet black logo

Administration Guide

Using the Rest API

Copy Link
Copy Doc ID 9217125a-7eda-11ec-a0d0-fa163e15d75b:952892
Download PDF

Using the REST API

Introduction

FortiTester supports Representational state transfer application programming interface (REST API) access. These APIs can be used to retrieve, create, update and delete configuration settings, to retrieve system logs and statistics, and to perform basic administrative actions such as reboot and shut down.

FortiTester API are also available on Fortinet Developer Network, at https://fndn.fortinet.net/index.php?/fortiapi/1003-fortitesterbeta/

A few examples of FortiTester API commands are given in this section. For the full list of available commands, see API Browser on the FortiTester landing page.

The API browser in GUI allows users to try out the API in GUI. Users can also find FortiTester API documentation on FNDN (Fortinet Developer Network).

Enabling REST API Support

The API is enabled by default. No additional configuration is required.

Authentication

When making requests to FortiTester using the REST API, you will need:

  1. A valid admin username and password (so that an authenticated session can be established)
  2. Appropriate access permissions for the requested resource (controlled by admin profile)

Using curl, you may save the authentication information as a cookie to allow subsequent requests to be accepted automatically.

curl -k -d'{"name":"<username>","password":"<user password>"}' -c cookies.txt -H "Content-Type: application/json" https://10.220.64.6/api/user/login

curl -k -b cookies.txt https://10.220.64.6/api/case/test2/rerun

Format

FortiTester REST API uses the JSON format.

Error Codes

An error code 0 means the operation was a success. Any error code that is a non-zero integer means an error occurred.

Example API commands

For the full list of available commands, see API Browser on the FortiTester landing page.

User login

HTTP Request: /api/user/login

Method: POST

Parameter Name Type Description
name String User name
Password String Password

Example:

{

"name":"test",

"password":"test123"

}

Response:

{

"ErrorCode":0,

"Data":{

"name": "test",

"_id": "55a5cc185b7e7bf073a98af0",

"role": "tester"

}

}

  • Data: Gives returned data if "ErrorCode" is 0 or an error message if "ErrorCode" is a non-zero integer.

Create user

HTTP Request: /api/user

Method: POST

Parameter Name Type Description
name String User name
Password String Password
cfmPsw String Confirmed password
role String Role of the user

Example:

{

"name":"test",

"password":"test"

"cfmPsw":"test",

"role":"tester"

}

Response:

{

"ErrorCode":0,

"Data":"55c8458e1d41c82b3b3a2604"

}

  • Data:Gives the User ID.

Reboot system

HTTP Request: /api/system/reboot

Method:POST

Parameter Name Type Description
reboot true/false Reboot the system or not.

Response:

{

"ErrorCode":0

"Data":""

}

Using the REST API

Introduction

FortiTester supports Representational state transfer application programming interface (REST API) access. These APIs can be used to retrieve, create, update and delete configuration settings, to retrieve system logs and statistics, and to perform basic administrative actions such as reboot and shut down.

FortiTester API are also available on Fortinet Developer Network, at https://fndn.fortinet.net/index.php?/fortiapi/1003-fortitesterbeta/

A few examples of FortiTester API commands are given in this section. For the full list of available commands, see API Browser on the FortiTester landing page.

The API browser in GUI allows users to try out the API in GUI. Users can also find FortiTester API documentation on FNDN (Fortinet Developer Network).

Enabling REST API Support

The API is enabled by default. No additional configuration is required.

Authentication

When making requests to FortiTester using the REST API, you will need:

  1. A valid admin username and password (so that an authenticated session can be established)
  2. Appropriate access permissions for the requested resource (controlled by admin profile)

Using curl, you may save the authentication information as a cookie to allow subsequent requests to be accepted automatically.

curl -k -d'{"name":"<username>","password":"<user password>"}' -c cookies.txt -H "Content-Type: application/json" https://10.220.64.6/api/user/login

curl -k -b cookies.txt https://10.220.64.6/api/case/test2/rerun

Format

FortiTester REST API uses the JSON format.

Error Codes

An error code 0 means the operation was a success. Any error code that is a non-zero integer means an error occurred.

Example API commands

For the full list of available commands, see API Browser on the FortiTester landing page.

User login

HTTP Request: /api/user/login

Method: POST

Parameter Name Type Description
name String User name
Password String Password

Example:

{

"name":"test",

"password":"test123"

}

Response:

{

"ErrorCode":0,

"Data":{

"name": "test",

"_id": "55a5cc185b7e7bf073a98af0",

"role": "tester"

}

}

  • Data: Gives returned data if "ErrorCode" is 0 or an error message if "ErrorCode" is a non-zero integer.

Create user

HTTP Request: /api/user

Method: POST

Parameter Name Type Description
name String User name
Password String Password
cfmPsw String Confirmed password
role String Role of the user

Example:

{

"name":"test",

"password":"test"

"cfmPsw":"test",

"role":"tester"

}

Response:

{

"ErrorCode":0,

"Data":"55c8458e1d41c82b3b3a2604"

}

  • Data:Gives the User ID.

Reboot system

HTTP Request: /api/system/reboot

Method:POST

Parameter Name Type Description
reboot true/false Reboot the system or not.

Response:

{

"ErrorCode":0

"Data":""

}