Fortinet Document Library

Version:


Table of Contents

Download PDF
Copy Link

Python code examples

Get access token

The following 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)

Python code examples

Get access token

The following 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)