FortiMail REST API Reference
FortiMail REST API Reference
Version 6.0.0
1
FORTINET DOCUMENT LIBRARY
https://docs.fortinet.com
FORTINET BLOG
https://blog.fortinet.com
FORTIGUARD CENTER
https://www.fortiguard.com
FEEDBACK
Email: [email protected]
Introduction ........................................................................................................................................................................ 4
Enabling REST API support ............................................................................................................................................ 4
Authentication .................................................................................................................................................................... 4
PKI authentication ............................................................................................................................................................. 5
To use PKI admin authentication ............................................................................................................................ 5
Password-based authentication ...................................................................................................................................... 5
FortiMail REST API HTTP response codes .................................................................................................................. 5
REST API for system level resources ............................................................................................................................ 6
REST API for domain level resources ........................................................................................................................... 7
REST API for administrative actions .............................................................................................................................. 7
System resource list and URLs....................................................................................................................................... 8
Example commands ....................................................................................................................................................... 16
Admin login with PKI certificate-based authentication .......................................................................................... 16
Admin login with password-based authentication .................................................................................................. 16
To get domain information with password-based authentication......................................................................... 16
To get domain information with certificate-based authentication......................................................................... 16
Access control rule management ............................................................................................................................. 16
List Access Control Rules ...................................................................................................................................... 17
Create a new Access Control Rule ...................................................................................................................... 17
Modify an existing Access Control Rule .............................................................................................................. 18
Delete an existing Access Control Rule .............................................................................................................. 18
Move existing Access Control Rules .................................................................................................................... 18
Whitelist/blacklist management................................................................................................................................. 18
3
Introduction
This document provides the REST API information supported in FortiMail version 5.3.4 release. This document
covers the FortiMail GUI supported REST API reference only. These APIs can be used to retrieve, create,
update and delete configuration settings, to retrieve dynamic system statistics, and to perform basic
administrative actions such as reboot and shut down.
Http POST --- To create a new resource or perform certain administrative actions
By default, this feature is disabled on FortiMail. To enable it, use the following CLI command:
Authentication
When making requests to FortiMail appliance using the REST API, you will need to pass the authentication. There
are two authentication options you can use:
4
PKI authentication
For PKI certificate-based authentication, you must create two certificates using the same CA. One certificate will
be used for FML HTTP server and the other certificate will be associated with an admin user. Both the user
certificates and private key has to be moved to the PC running the script. The CA certificate needs to be copied to
the PC as well. Otherwise CURL will not be able to verify the FML certificate.
Password-based authentication
To establish a valid authentication session, you must make a POST request to the FortiMail login handler with
your admin username and password. The POST request should contain JSON data with ‘name’ and ‘password’
fields:
URL: http(s)://host_or_ip/api/v1/AdminLogin/
Method: POST
If login is successful, the response will contain the authentication token in the APSCOOKIE cookie value. This
cookie value must be included in any further requests.
Note: The permissions for the administrative account you use will affect which objects and operations you'll
have access to, so ensure the user has the permissions required for the actions you wish to perform.
5
200-OK API request successful.
403 - Forbidden Request is missing authentication token or administrator is missing access profile
permissions.
405- Method Not Allowed Specified HTTP method is not allowed for this resource
http(s)://host_ip/api/v1/resource_name/resource_id/sub_resource_name/sub_resource_id/
where:
resource_name --- Specifies the type of resource to query (such as SysInterface), required.
resource_id --- Unique ID of the resource as specified by resource_name (such as port1), optional.
If not present, returns entire list of resources.
sub_resource_name --- Some resources may have sub / child resources, use this to query sub resources,
optional
sub_resource_id --- Unique ID of the sub resource as specified by sub_resource_name, optional. If not
present, returns entire list of sub resources.
Examples:
…/api/v1/ProfSession/inbound/ ProfSessionSenderWhitelist/
For a full list of system level resources, refer to the Supported Resources List.
6
REST API for domain level resources
FortiMail also supports retrieval and modification of domain level CMDB configuration settings. The API can be
accessed using the following URL:
http(s)://host_ip/api/v1/domain/domain_name/resource_name/resource_id/sub_r
esource_name/sub_resource_id/
It is very similar to the URL for system level resources, only two new tokens are added:
Examples:
…/api/v1/domain/abc.com/ProfAntispam/
…/api/v1/domain/abc.com/PolicyRcpt/
…/api/v1/domain/abc.com/PolicyRecipient/1/
--- returns details of recipient based policy ‘1’ for domain ‘abc.com’
…/api/v1/domain/abc.com/UserPreference/
For a full list of domain level resources, refer to the Supported Resources List.
URL: http(s)://host_ip/api/v1/SysStatusCommand/
Method: POST
1 --- Restart
7
2 --- Shut down
3 --- Reload
8
/AsSenderReputation/ GET Sender reputation list
9
/LogAltMSetting/ GET, PUT Alert email settings
10
* DELETE
11
/ProfEmail_address_group/ GET, POST, PUT, Email address groups
DELETE
12
/SemailDbUser/ GET, DELETE IBE users
13
DELETE
14
/SysSnmpSnmpv3_userHost/ GET, POST, PUT, Notification hosts for a
DELETE SNMP user
15
Example commands
Admin login with PKI certificate-based authentication
If login is successful, the cookies will be save to cookie.txt, which will be used in the below commands.
If login is successful, the cookies will be save to cookie.txt, which will be used in the below commands.
Note: If your log in to FortiMail with PKI certificate, you must use both the cookie and certificate together to run the
command sessions. If you log in with user name and password, you only need to use the cookie to run the command
sessions. For example:
1 --- safe-relay
2 --- relay
3 --- reject
4 --- discard
5 --- safe
16
0 --- any
1 --- authenticated
2 --- not-authenticated
0 --- ip mask
1 --- ip group
Supported values for 'sortingDirection' attribute of applicable JSON requests (i.e. ACL rule):
1 --- enabled/sorting
2 --- disabled/no sorting
1 --- GET
2 --- CREATE
3 --- DELETE
5 --- UPDATET
14 --- MOVE
Note: If reqAction is present in JSON, it takes precedence over HTTP method header (i.e. HTTP
GET/POST/PUT/DELETE).
17
Modify an existing Access Control Rule
curl -v -H "Content-Type: application/json" -X PUT -d '{"action":3}' -b
cookie.txt http://ip_or_host/api/v1/MailSetAccessRule/1
--"1" is the mkey
--Set access rule "1" action to “Reject”
refMkey: 2 – required, reference ID of the ACL rule when moving before/after this ID
Whitelist/blacklist management
18
'{"extraParam":"whitelist", "listitems":"My5jYQ=="}'
http://IP_Host/api/v1/UserMaillist/system/
19
Copyright© 2019 Fortinet, Inc. All rights reserved. Fortinet®, FortiGate®, FortiCare® and FortiGuard®, and certain other marks are registered trademarks of Fortinet, Inc., in the
U.S. and other jurisdictions, and other Fortinet names herein may also be registered and/or common law trademarks of Fortinet. All other product or company names may be
trademarks of their respective owners. Performance and other metrics contained herein were attained in internal lab tests under ideal conditions, and actual performance and
other results may vary. Network variables, different network environments and other conditions may affect performance results. Nothing herein represents any binding
commitment by Fortinet, and Fortinet disclaims all warranties, whether express or implied, except to the extent Fortinet enters a binding written contract, signed by Fortinet’s
General Counsel, with a purchaser that expressly warrants that the identified product will perform according to certain expressly-identified performance metrics and, in such
event, only the specific performance metrics expressly identified in such binding written contract shall be binding on Fortinet. For absolute clarity, any such warranty will be
limited to performance in the same ideal conditions as in Fortinet’s internal lab tests. In no event does Fortinet make any commitment related to future deliverables, features, or
development, and circumstances may change such that any forward-looking statements herein are not accurate. Fortinet disclaims in full any covenants, representations, and
guarantees pursuant hereto, whether express or implied. Fortinet reserves the right to change, modify, transfer, or otherwise revise this publication without notice, and the most
current version of the publication shall be applicable.