User & Role Management API Call Examples in Python (RBAC)

Similar to the User and Group API, Sites that have RBAC enabled can use the User and Role Management APIs for RBAC allows us to create, read, update, and destroy users and roles programmatically. Here's the official documentation.

Below are simple examples showing how you can test this out in Python 3. 

To use these APIs, you'll need your site name, api-key, and access to the Users & Roles API for RBAC (upgraded feature)

Users

  • GET Users
  • GET Single User
  • CREATE User
  • UPDATE User
  • DELETE User

Roles

  • GET Roles
  • GET Single Role
  • CREATE Role
  • UPDATE Role
  • DELETE Role

Dashboard

  • GET Dashboards

USERS

GET Users

import requests
import json

headers = {
    'HTTP-X-PARTNER-AUTH': 'site-name:api-key',
    'Content-Type' : 'application/json'
}

url = 'https://api.periscopedata.com/api/v2/users'

response = requests.get(url, headers=headers)

print(json.loads(response.text))

GET Single User

import requests
import json

headers = {
    'HTTP-X-PARTNER-AUTH': 'site-name:api-key',
    'Content-Type' : 'application/json'
}

url = 'https://api.periscopedata.com/api/v2/users/0000-test-1111-user-id'

response = requests.get(url, headers=headers)

print(json.loads(response.text))

CREATE User

import requests
import json

headers = {
    'HTTP-X-PARTNER-AUTH': 'site-name:api-key',
    'Content-Type' : 'application/json'
}

payload = {
    "first_name": 'MyFirstName' ,
    "last_name": 'MyLastName',
    "email": 'newuseremail@website.com',
    "roles": [
      '0000-admin-1111-id'
    ],
    "invited_by_email": 'useremail@website.com' }

data = json.dumps(payload)

url = 'https://api.periscopedata.com/api/v2/users?test_mode=true'

response = requests.post(url, headers=headers, data=data)

print(json.loads(response.text))

UPDATE User

import requests
import json

headers = {
    'HTTP-X-PARTNER-AUTH': 'site-name:api-key',
    'Content-Type' : 'application/json'
}

payload = {
    "first_name": 'newFirstName' ,
    "last_name": 'newLastName'
}

data = json.dumps(payload)

url = 'https://api.periscopedata.com/api/v2/users/0000-test-1111-user-id?test_mode=true'

response = requests.put(url, headers=headers, data=data)

print(json.loads(response.text))

DELETE User

import requests
import json

headers = {
    'HTTP-X-PARTNER-AUTH': 'site-name:api-key',
    'Content-Type' : 'application/json'
}

url = 'https://api.periscopedata.com/api/v2/users/0000-test-1111-user-id?test_mode=true'

response = requests.delete(url, headers=headers)

print(response.status_code)

Roles

GET Roles

import requests
import json

headers = {
    'HTTP-X-PARTNER-AUTH': 'site-name:api-key',
    'Content-Type' : 'application/json'
}

url = 'https://api.periscopedata.com/api/v1/roles'

response = requests.get(url, headers=headers)

print(json.loads(response.text))

GET Single Role

import requests
import json

headers = {
    'HTTP-X-PARTNER-AUTH': 'site-name:api-key',
    'Content-Type' : 'application/json'
}

url = 'https://api.periscopedata.com/api/v1/role/0000-test-1111-role-id'

response = requests.get(url, headers=headers)

print(json.loads(response.text))

CREATE Role

import requests
import json

headers = {
    'HTTP-X-PARTNER-AUTH': 'site-name:api-key',
    'Content-Type' : 'application/json'
}

payload = {
    "name": "myNewRole" ,
    "description": "testing",
    "created_by_email": "useremail@website.com",
    "privileges":
    [{
            "object_type":"Dashboard",
            "permissions":["read_dashboards"]
        }]
    ,
    "permissions":
    [{
        "object_type":"Dashboard",
        "object_id":"0000-dashboard-1111-id",
        "permissions":["create_dashboards"]
                       }]
}

data = json.dumps(payload)

url = 'https://api.periscopedata.com/api/v1/roles?test_mode=true'

response = requests.post(url, headers=headers, data=data)

print(json.loads(response.text))

UPDATE Role

import requests
import json

headers = {
    'HTTP-X-PARTNER-AUTH': 'site-name:api-key',
    'Content-Type' : 'application/json'
}

payload =  {
            "name": "myExistingRole" ,
            "description": "NewDescription",
            "updated_by_email": "useremail@website.com"
}

data = json.dumps(payload)

url = 'https://api.periscopedata.com/api/v1/roles/0000-test-1111-role-id?test_mode=true'

response = requests.put(url, headers=headers, data=data)

print(json.loads(response.text))

DELETE Role

import requests
import json

headers = {
    'HTTP-X-PARTNER-AUTH': 'site-name:api-key',
    'Content-Type' : 'application/json',
}

url = 'https://api.periscopedata.com/api/v1/roles/0000-test-1111-role-id?test_mode=true'

response = requests.delete(url, headers=headers)

print(response.status_code)

Dashboards

GET Dashboards

import requests
import json

headers = {
    'HTTP-X-PARTNER-AUTH': 'site-name:api-key',
    'Content-Type' : 'application/json'
}

url = 'https://api.periscopedata.com/api/v1/dashboards'

response = requests.get(url, headers=headers)

print(json.loads(response.text))
Reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
Like1 Follow
  • 1 Likes
  • 2 wk agoLast active
  • 21Views
  • 1 Following