Fortinet black logo

Handbook

Using the Rest API

Copy Link
Copy Doc ID 1eee771d-afba-11ea-8b7d-00505692583a: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.

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.

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.

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.

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":""

}