-
Notifications
You must be signed in to change notification settings - Fork 0
Users
The users API is for managing a user's account and its associated details.
Contents
- Creating a new account
- Logging in
- Retrieving user details
- Updating user details
- Resetting a password
- Logging out
To create an account, send the following to /v1/users with a POST request:
{
"name": "$name",
"email": "$email",
"password": "$password",
"token": "$token"
}The response to this request if no errors occur will be:
{
"result": "success"
}import requests
server = 'http://sensly.io/v1%s'
create_data = {'name': 'Bill',
'email': 'bill@example.com',
'password': 'password'}
r1 = requests.post(server % '/tokens')
token = r1.json()['token']
create_data['token'] = token
r2 = requests.post(server % '/users', json=create_data)
print r2.json()To log in via the API, send the following to /v1/users/login using a POST request:
{
"email": "$email",
"password": "$password",
"token": "$token"
}The response to this request if no errors occur will be:
{
"result": "success"
}import requests
session = requests.Session()
server = 'http://sensly.io/v1%s'
login_data = {'email': 'bill@example.com'
'password': 'password'}
r1 = session.post(server % '/tokens')
token = r1.json()['token']
login_data['token'] = token
r2 = session.post(server % '/users/login', json=login_data)
print r2.json()To get a user's details, send a GET request to /v1/users. This action requires a user to be logged in and will return the details of the currently logged in user.
The response to this request if no errors occur will be:
{
"name": "$name",
"password": "$password"
}import requests
session = requests.Session()
server = 'http://sensly.io/v1%s'
login_data = {'email': 'bill@example.com'
'password': 'password'}
r1 = session.post(server % '/tokens')
token = r1.json()['token']
login_data['token'] = token
session.post(server % '/users/login')
r2 = session.get(server % '/users')
print r2.json()To update a user's details, send the following to /v1/users as a PUT request. This requires a user to be logged in.
{
"name": "$new_name",
"token": "$token"
}The attributes of a user that can currently be updated are: name.
The response to this request if no errors occur will be:
{
"name": "$new_name"
}import requests
session = requests.Session()
server = 'http://sensly.io/v1%s'
login_data = {'email': 'bill@example.com'
'password': 'password'}
update_data = {'name': 'Bob'}
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 % '/tokens')
token = r2.json()['token']
update_data['token'] = token
r3 = session.put(server % '/users', json=update_data)
print r3.json()This describes an action that is under development and may not work at this time.
To log out via the API, send a POST request to /v1/users/logout.
The response to this request if no errors occur will be:
{
"result": "success"
}import requests
session = requests.Session()
server = 'http://sensly.io/v1%s'
login_data = {'email': 'bill@example.com'
'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.post(server % '/users/logout')
print r2.json()