Skip to content
Matthew Dowdell edited this page Jan 25, 2017 · 5 revisions

Contents

Creating a group

To create a group, a user must be logged in and not already member of an existing group. The user that creates the group will be the group admin.

To create a group via the API, send the following to /v1/groups as a POST request:

{
	"name": "$group_name"
}

The response to this request if no errors occur will be:

{
	"result": "success"
}

Example

import requests

session = requests.Session()
server = 'http://sensly.io/v1%s'
login_data = {'email': '[email protected]',
              'password': 'password'}
group_data = {'name': 'My Group Name'}

r1 = session.post(server % '/tokens')
token = r1.json()['token']
login_data['token'] = token

session.post(server % '/users/login', json=login_data)

r2 = session.post(server % '/groups', json=group_data)
print r2.json()

Adding users to a group

To add a user to the group, send the following to /v1/groups/add_user as a POST request. Only a logged in group admin may add users to a group. The user being added to the group cannot be a member of an existing group.

{
	"email": "$user_to_add"
}

The response to this request if no errors occur will be:

{
	"result": "success"
}

Example

import requests

session = requests.Session()
server = 'http://sensly.io/v1%s'
login_data = {'email': '[email protected]',
              'password': 'password'}
user_data = {'email': '[email protected]'}

r1 = session.post(server % '/tokens')
token = r1.json()['token']
login_data['token'] = token

session.post(server % '/users/login', json=login_data)

r2 = session.post(server % '/groups/add_user', json=user_data)
print r2.json()

Getting data about a group

To get data about a group, send a GET request to /v1/groups. Only members of the group may access the group's data.

The response to this request if no errors occur will be:

{
	"name": "$group_name",
	"admin": "$group_admin_email",
	"users": [
		{
			"name": "$group_admin_name",
			"email": "$group_admin_email"
		},
		{
			"name": "$group_member_name",
			"email": "$group_member_email"
		}
	]
}

Example

import requests

session = requests.Session()
server = 'http://sensly.io/v1%s'
login_data = {'email': '[email protected]',
              'password': 'password'}

r1 = session.post(server % '/tokens')
token = r1.json()['token']
login_data['token'] = token

session.post(server % '/users/login', json=login_data)

r2 = session.get(server % '/groups')
print r2.json()
Clone this wiki locally