Technical Tip: Set up an API call to FortiManager or FortiAnalyzer Cloud
Description
Â
This article describes how to set up an API call to FortiManager Cloud or FortiAnalyzer Cloud.
Â
Scope
Â
FortiManager Cloud and FortiAnalyzer Cloud.
Â
Solution
Â
Open one of the following URLs depending on the platform:
Â
After opening the corresponding page, locate the instance of choice. Select the API button at the bottom.

Â
From the new panel that appears, select and copy the provided example of the JSON API.
To create an API user, go to Users.
Go to the IAM portal -> Permission Profiles -> Add New.
Â

Â
From Add Portal, choose FortiAnalyzer Cloud / FortiManager Cloud. Then enable access and the proper level of access.
Go to IAM portal -> User Groups -> Add Another Group.

Choose the name of the group and attach the proper permission profile under the IAM portal -> Users -> Add New -> API user.

Â

Â
Choose the proper user group for the user and then download the credentials.
To confirm that the API call is working correctly, use the following methods:
BASH script:
Â
#!/bin/bashnn# IAM API usernurl_base="https://xxx.fortimanager.forticloud.com"nurl="$url_base/jsonrpc"nn# usernuser="6BD4E324xxx"npasswd="xxxxxx"nn# 1, get token from FortiCare, url is defined in admin portal Server Config -> API user setting -> FAC_OAUTH_API_URLntoken=$(curl --silent -k -X POST
https://customerapiauth.fortinet.com/api/v1/oauth/token/
-H 'Content-Type: application/json'
-d '{"username": "'$user'", "password": "'$passwd'", "client_id" : "FortiManager", "grant_type": "password" }' | jq -r '.access_token')necho 'access token is '$tokennn# 2, get session from instancensession=$(curl -k -X POST --http1.1 --silent $url_base/p/forticloud_jsonrpc_login/
-H 'Content-Type: application/json'
-d '{"access_token": "'$token'"}' | jq -r '.session')nn# responsenecho 'session is '$sessionnnecho "******************System Status*************************"n# Get sys status from instancencurl -k -X POST --http1.1 $url
-H 'Content-Type: application/json'
-d '{"method": "get", "params": [{ "url": "/cli/global/system/status"}], "session": "'$session'", "id": 1}' | jq .
The output from the API call:

Â
API Platform to send requests:
Use the credentials and obtain an access token from the OAuth API URLÂ 'https://customerapiauth.fortinet.com/api/v1/oauth/token/'.
Â
{n "content_type": "application/json",n "username": "52C28D9C-XXXX-XXX-XXX-XXXX10F2186",n "password": "c60f4XXXXXXXXXXXXXXXXXXd2!1Aa",n "client_id": "FortiManager",n "grant_type": "password"n}Â
Note:Â The value for client_id can be 'FortiManager' or 'FortiAnalyzer', depending on the cloud service.
Â
Access tokens will be received in response to the above request (make sure the 'Headers' tab also has 'Content-Type' set to 'application/json').


Â
Using the access_token, send a login request to <FortiManager Cloud URL>/p/forticloud_jsonrpc_login/.

The session key will then be received and can be used to send further requests.

Note: Steps are the same for both FortiManager and FortiAnalyzer Cloud.
Related documents:
