Fortinet black logo

Python examples

Copy Link
Copy Doc ID 7e3e6f9e-a082-11ee-8673-fa163e15d75b:104064
Download PDF

Python examples

Get 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://ftc.fortinet.com:9696/api/v1/login', json=payload, verify=False)

access_token = resp.json()['access_token']

Create 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': 'ftc_webapp_user',
    'email': '***@gmail.com'
}

resp = requests.request('post', 'https://ftc.fortinet.com:9696/api/v1/user', headers=headers, json=payload, verify=False)

Get 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://ftc.fortinet.com:9696/api/v1/user', headers=headers, json=payload, verify=False)

Get user via id with access token

import requests

headers = {
   ‘Authorization’: ‘Bearer eyJ0ex*******Q6to’,
   ‘Content-Type’: ‘application/json’

payload = {} 
resp = requests.request('get', 'https://ftc.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":"ftc_webapp_user", 
} 
resp = requests.request('post', 'https://ftc.fortinet.com:9696/api/v1/auth', headers=headers, json=payload, verify=False)

FTM user OTP code authentication with access token

Note

You can also include the ‘auth_method’ field in the payload to specify if the OTP code should be sent via FTM, SMS, email, etc..

import requests

headers = {
   ‘Authorization’: ‘Bearer eyJ0ex*******Q6to’,
   ‘Content-Type’: ‘application/json’

payload = {
   "username":"ftc_webapp_user",
   "token":"123456"
} 
resp = requests.request('post', 'https://ftc.fortinet.com:9696/api/v1/auth', headers=headers, json=payload, verify=False)

Check user authentication status with access token

import requests

headers = {
   ‘Authorization’: ‘Bearer eyJ0ex*******Q6to’,
   ‘Content-Type’: ‘application/json’

payload = {} 
resp = requests.request('get', 'https://ftc.fortinet.com:9696/api/v1/auth/[input auth ID here]', headers=headers, json=payload, verify=False)

Delete user with access token

import requests

headers = {
   ‘Authorization’: ‘Bearer eyJ0ex*******Q6to’,
   ‘Content-Type’: ‘application/json’

payload = {} 
resp = requests.request('delete', 'https://ftc.fortinet.com:9696/api/v1/auth/[input user reference ID here]', headers=headers, json=payload, verify=False)

Python examples

Get 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://ftc.fortinet.com:9696/api/v1/login', json=payload, verify=False)

access_token = resp.json()['access_token']

Create 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': 'ftc_webapp_user',
    'email': '***@gmail.com'
}

resp = requests.request('post', 'https://ftc.fortinet.com:9696/api/v1/user', headers=headers, json=payload, verify=False)

Get 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://ftc.fortinet.com:9696/api/v1/user', headers=headers, json=payload, verify=False)

Get user via id with access token

import requests

headers = {
   ‘Authorization’: ‘Bearer eyJ0ex*******Q6to’,
   ‘Content-Type’: ‘application/json’

payload = {} 
resp = requests.request('get', 'https://ftc.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":"ftc_webapp_user", 
} 
resp = requests.request('post', 'https://ftc.fortinet.com:9696/api/v1/auth', headers=headers, json=payload, verify=False)

FTM user OTP code authentication with access token

Note

You can also include the ‘auth_method’ field in the payload to specify if the OTP code should be sent via FTM, SMS, email, etc..

import requests

headers = {
   ‘Authorization’: ‘Bearer eyJ0ex*******Q6to’,
   ‘Content-Type’: ‘application/json’

payload = {
   "username":"ftc_webapp_user",
   "token":"123456"
} 
resp = requests.request('post', 'https://ftc.fortinet.com:9696/api/v1/auth', headers=headers, json=payload, verify=False)

Check user authentication status with access token

import requests

headers = {
   ‘Authorization’: ‘Bearer eyJ0ex*******Q6to’,
   ‘Content-Type’: ‘application/json’

payload = {} 
resp = requests.request('get', 'https://ftc.fortinet.com:9696/api/v1/auth/[input auth ID here]', headers=headers, json=payload, verify=False)

Delete user with access token

import requests

headers = {
   ‘Authorization’: ‘Bearer eyJ0ex*******Q6to’,
   ‘Content-Type’: ‘application/json’

payload = {} 
resp = requests.request('delete', 'https://ftc.fortinet.com:9696/api/v1/auth/[input user reference ID here]', headers=headers, json=payload, verify=False)