Python examples
Getting access token
The following code example shows how to get an access token.
import requests
client_id = 'ec601e2a-73bbxxxxxxxx'
client_secret = 'mRR6ciFnKxxxxxxxxx'
payload = {
'client_id': client_id,
'client_secret': client_secret
}
resp = requests.request('post', 'https://fic.fortinet.com:9696/api/v1/login', json=payload, verify=False)
access_token = resp.json()['access_token']
Creating user with access token
The following shows how to create a user with the access token.
import requests
headers = {
'Authorization': 'Bearer eyJ0ex*******Q6to',
'Content-Type': 'application/json'
}
payload = {
'username': 'fic_webapp_user',
'email': '***@gmail.com'
}
resp = requests.request('post', 'https://fic.fortinet.com:9696/api/v1/user', headers=headers, json=payload, verify=False)
Getting a list of all users with access token
import requests
headers = {
‘Authorization’: ‘Bearer eyJ0ex*******Q6to’,
‘Content-Type’: ‘application/json’
payload = {}
resp = requests.request('get', 'https://fic.fortinet.com:9696/api/v1/user', headers=headers, json=payload, verify=False)
Getting user via id with access token
import requests
headers = {
‘Authorization’: ‘Bearer eyJ0ex*******Q6to’,
‘Content-Type’: ‘application/json’
payload = {}
resp = requests.request('get', 'https://fic.fortinet.com:9696/api/v1/user/[input user reference ID here]', headers=headers, json=payload, verify=False)
FTM user authentication with access token
import requests
headers = {
‘Authorization’: ‘Bearer eyJ0ex*******Q6to’,
‘Content-Type’: ‘application/json’
payload = {
"username":"fic_webapp_user",
}
resp = requests.request('post', 'https://fic.fortinet.com:9696/api/v1/auth', headers=headers, json=payload, verify=False)
FTM user OTP code authentication with access token
|
|
You can also include the ‘auth_method’ field in the payload to specify whether the OTP code should be sent via FTM, SMS, email, etc.. |
import requests
headers = {
‘Authorization’: ‘Bearer eyJ0ex*******Q6to’,
‘Content-Type’: ‘application/json’
payload = {
"username":"fic_webapp_user",
"token":"123456"
}
resp = requests.request('post', 'https://fic.fortinet.com:9696/api/v1/auth', headers=headers, json=payload, verify=False)
Checking user authentication status with access token
import requests
headers = {
‘Authorization’: ‘Bearer eyJ0ex*******Q6to’,
‘Content-Type’: ‘application/json’
payload = {}
resp = requests.request('get', 'https://fic.fortinet.com:9696/api/v1/auth/[input auth ID here]', headers=headers, json=payload, verify=False)
Deleting user with access token
import requests
headers = {
‘Authorization’: ‘Bearer eyJ0ex*******Q6to’,
‘Content-Type’: ‘application/json’
payload = {}
resp = requests.request('delete', 'https://fic.fortinet.com:9696/api/v1/auth/[input user reference ID here]', headers=headers, json=payload, verify=False)