User & Group Management API Call Examples in Python

With the release of our User and Group Management APIs, we can now create, read, update, and destroy users and groups programmatically. CRUD! Here's the official documentation.

Here are some super 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 & Groups API (upgraded feature)

Users

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

Groups

  • GET Groups
  • GET Single Group
  • CREATE Group
  • UPDATE Group
  • DELETE Group

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/v1/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',
    'HTTP-X-EMAIL': 'useremail@website.com'
}

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

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',
           "groups": [
               'Administrators'
           ],
           "invited_by_email": 'useremail@website.com' }

data = json.dumps(payload)

url = 'https://api.periscopedata.com/api/v1/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',
    'HTTP-X-EMAIL': 'newuseremail@website.com'
}

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


data = json.dumps(payload)

url = 'https://api.periscopedata.com/api/v1/users?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',
    'HTTP-X-EMAIL': 'newuseremail@website.com'
}

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

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

print(json.loads(response.text))

GROUPS

GET Groups

import requests
import json

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

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

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

print(json.loads(response.text))

GET Single Group

import requests
import json

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

url = 'https://api.periscopedata.com/api/v1/groups/Administrators'

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

print(json.loads(response.text))

CREATE Group

import requests
import json

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

payload = {
           "name": "myNewGroup" ,
           "access": "discovery",
           "created_by_email": "useremail@website.com"
}

data = json.dumps(payload)

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

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

print(json.loads(response.text))

UPDATE Group

import requests
import json

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

payload =  {
            "name": "myExistingGroup" ,
            "access": "View"
}


data = json.dumps(payload)

url = 'https://api.periscopedata.com/api/v1/groups/my-new-group?test_mode=true'

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

print(json.loads(response.text))

DELETE Group

import requests
import json

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

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

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

print(response.status_code)
Reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
Like3 Follow
  • 3 Likes
  • 2 mths agoLast active
  • 908Views
  • 1 Following