Techfesia2019

General notes

This is the collection of APIs for Techfesia2019 of IIIT Sri City

API detail

Authentication

User Token Pair Obtain

curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{
	"username":"test_user_001",
	"password":"Hello World"
}' "http://localhost:8000/auth/token/"
POST /auth/token/ HTTP/1.1
Host: localhost:8000
Content-Type: application/json
Accept: application/json

{
	"username":"test_user_001",
	"password":"Hello World"
}
Status200 OK
Content-Typeapplication/json
{
    "access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiY29sZF9zdHVmZiI6IuKYgyIsImV4cCI6MTIzNDU2LCJqdGkiOiJmZDJmOWQ1ZTFhN2M0MmU4OTQ5MzVlMzYyYmNhOGJjYSJ9.NHlztMGER7UADHZJlxNG0WSi22a2KaYSfd1S-AuT7lU",
    "refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImNvbGRfc3R1ZmYiOiLimIMiLCJleHAiOjIzNDU2NywianRpIjoiZGUxMmY0ZTY3MDY4NDI3ODg5ZjE1YWMyNzcwZGEwNTEifQ.aEoAYkSJjoWH1boshQAaTkf8G3yn0kapko6HFRt7Rh4"
}

User Token Refresh

curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{
	"refresh":"sample_token"
}' "http://localhost:8000/auth/token/refresh/"
POST /auth/token/refresh/ HTTP/1.1
Host: localhost:8000
Content-Type: application/json
Accept: application/json

{
	"refresh":"sample_token"
}
Status200 OK
Content-Typeapplication/json
{
    "access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiY29sZF9zdHVmZiI6IuKYgyIsImV4cCI6MTIzNTY3LCJqdGkiOiJjNzE4ZTVkNjgzZWQ0NTQyYTU0NWJkM2VmMGI0ZGQ0ZSJ9.ekxRxgb9OKmHkfy-zs1Ro_xs1eMLXiR17dIDBVxeT-w"
}

Staff token pair obtain

curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{
	"username":"test_staff_user_001",
	"password":"Hello Staff Password"
}' "http://localhost:8000/auth/token/"
POST /auth/token/ HTTP/1.1
Host: localhost:8000
Content-Type: application/json
Accept: application/json

{
	"username":"test_staff_user_001",
	"password":"Hello Staff Password"
}
Status200 OK
Content-Typeapplication/json
{
    "access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiY29sZF9zdHVmZiI6IuKYgyIsImV4cCI6MTIzNDU2LCJqdGkiOiJmZDJmOWQ1ZTFhN2M0MmU4OTQ5MzVlMzYyYmNhOGJjYSJ9.NHlztMGER7UADHZJlxNG0WSi22a2KaYSfd1S-AuT7lU",
    "refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImNvbGRfc3R1ZmYiOiLimIMiLCJleHAiOjIzNDU2NywianRpIjoiZGUxMmY0ZTY3MDY4NDI3ODg5ZjE1YWMyNzcwZGEwNTEifQ.aEoAYkSJjoWH1boshQAaTkf8G3yn0kapko6HFRt7Rh4"
}

Staff Token Refresh

curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{
	"refresh":"sample_staff_token"
}' "http://localhost:8000/auth/token/refresh/"
POST /auth/token/refresh/ HTTP/1.1
Host: localhost:8000
Content-Type: application/json
Accept: application/json

{
	"refresh":"sample_staff_token"
}
Status200 OK
Content-Typeapplication/json
{
    "access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiY29sZF9zdHVmZiI6IuKYgyIsImV4cCI6MTIzNTY3LCJqdGkiOiJjNzE4ZTVkNjgzZWQ0NTQyYTU0NWJkM2VmMGI0ZGQ0ZSJ9.ekxRxgb9OKmHkfy-zs1Ro_xs1eMLXiR17dIDBVxeT-w"
}

SuperUser Token Pair obtain

curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{
	"username":"sample_superuser_001",
	"password":"Hello Superuser Password"
}' "http://localhost:8000/auth/token/"
POST /auth/token/ HTTP/1.1
Host: localhost:8000
Content-Type: application/json
Accept: application/json

{
	"username":"sample_superuser_001",
	"password":"Hello Superuser Password"
}
Status200 OK
Content-Typeapplication/json
{
    "access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiY29sZF9zdHVmZiI6IuKYgyIsImV4cCI6MTIzNDU2LCJqdGkiOiJmZDJmOWQ1ZTFhN2M0MmU4OTQ5MzVlMzYyYmNhOGJjYSJ9.NHlztMGER7UADHZJlxNG0WSi22a2KaYSfd1S-AuT7lU",
    "refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImNvbGRfc3R1ZmYiOiLimIMiLCJleHAiOjIzNDU2NywianRpIjoiZGUxMmY0ZTY3MDY4NDI3ODg5ZjE1YWMyNzcwZGEwNTEifQ.aEoAYkSJjoWH1boshQAaTkf8G3yn0kapko6HFRt7Rh4"
}

SuperUser Token Refresh

curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{
	"refresh":"sample_superuser_token"
}' "http://localhost:8000/auth/token/refresh/"
POST /auth/token/refresh/ HTTP/1.1
Host: localhost:8000
Content-Type: application/json
Accept: application/json

{
	"refresh":"sample_superuser_token"
}
Status0
{
    "access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX3BrIjoxLCJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiY29sZF9zdHVmZiI6IuKYgyIsImV4cCI6MTIzNTY3LCJqdGkiOiJjNzE4ZTVkNjgzZWQ0NTQyYTU0NWJkM2VmMGI0ZGQ0ZSJ9.ekxRxgb9OKmHkfy-zs1Ro_xs1eMLXiR17dIDBVxeT-w"
}

Revoke All Tokens (Sign Out from all devices)

curl -X DELETE -H "Accept: application/json" -H "Authorization: Bearer sample_token" "http://localhost:8000/auth/token/"
DELETE /auth/token/ HTTP/1.1
Host: localhost:8000
Accept: application/json
Authorization: Bearer sample_token
Status200 OK
Content-Typeapplication/json
{
    "tokens_deleted": 5
}

Revoke one token (Signout from one device)

curl -X PUT -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: Bearer sample_token" -d '{
	"token":"sample_token"
}' "http://localhost:8000/auth/token/"
PUT /auth/token/ HTTP/1.1
Host: localhost:8000
Content-Type: application/json
Accept: application/json
Authorization: Bearer sample_token

{
	"token":"sample_token"
}
Status200 OK
Content-Typeapplication/json
{
    "tokens_deleted": 1
}

Users

Get Users (Staff only)

curl -X GET -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer sample_staff_token" "http://localhost:8000/users?limit=10"
GET /users?limit=10 HTTP/1.1
Host: localhost:8000
Accept: application/json
Content-Type: application/json
Authorization: Bearer sample_staff_token
Status400 Bad Request
Content-Typeapplication/json
{
    "message": "This page does not exist",
    "pageSize": 10,
    "noOfPages": 5
}
Status200 OK
Content-Typeapplication/json
{
    "currentPage": 2,
    "noOfPages": 5,
    "users": [
        {
            "publicId": "sampleId1",
            "username": "test_user_001",
            "firstName": "Test",
            "lastName": "User",
            "email": "test_user_001@testers.techfesia.iiits.in",
            "phoneNumber": "+911234567890",
            "collegeName": "Test College 123",
            "profilePicture": "url_to_profile_pic",
            "dateJoined": "date_time_in_iso_format",
            "lastLogin": "date_time_in_iso_format"
        },
        {
            "publicId": "sampleId2",
            "username": "test_user_002",
            "firstName": "Test",
            "lastName": "User2",
            "email": "test_user_002@testers.techfesia.iiits.in",
            "phoneNumber": "+911234567890",
            "collegeName": "Test College 123",
            "profilePicture": "url_to_profile_pic",
            "dateJoined": "date_time_in_iso_format",
            "lastLogin": "date_time_in_iso_format"
        },
        {
            "publicId": "sampleId3",
            "username": "test_user_003",
            "firstName": "Test",
            "lastName": "User",
            "email": "test_user_003@testers.techfesia.iiits.in",
            "phoneNumber": "+911234567890",
            "collegeName": "Test College 123",
            "profilePicture": "url_to_profile_pic",
            "dateJoined": "date_time_in_iso_format",
            "lastLogin": "date_time_in_iso_format"
        }
    ]
}

Get User details

curl -X GET -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer sample_token" "http://localhost:8000/users/test_user_001"
GET /users/test_user_001 HTTP/1.1
Host: localhost:8000
Accept: application/json
Content-Type: application/json
Authorization: Bearer sample_token
Status200 OK
Content-Typeapplication/json
{
    "publicId": "sampleId123",
    "username": "test_user_001",
    "firstName": "Test",
    "lastName": "User",
    "email": "test_user_001@testers.techfesia.iiits.in",
    "phoneNumber": "+911234567890",
    "collegeName": "Test College 123",
    "profilePicture": "url_to_profile_pic",
    "dateJoined": "date_time_in_iso_format",
    "lastLogin": "date_time_in_iso_format"
}

Get User State (Staff Only)

curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: Bearer sample_staff_token" "http://localhost:8000/users/test_user_001/privileges"
GET /users/test_user_001/privileges HTTP/1.1
Host: localhost:8000
Content-Type: application/json
Accept: application/json
Authorization: Bearer sample_staff_token
Status200 OK
Content-Typeapplication/json
{
    "state": "normal"
}
Status200 OK
{
    "state": "staff",
    "privileges": {
        "model_name": [
            "array",
            "of",
            "privileges"
        ],
        "user": [
            "read"
        ],
        "event": [
            "read",
            "create",
            "update",
            "delete"
        ],
        "firebaseUser": []
    }
}
Status200 OK
Content-Typeapplication/json
{
    "state": "superuser"
}

Create New User

curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{
	"username":"test_user_001",
	"firstName":"Test",
	"lastName":"User",
	"email":"test_user_001@testers.techfesia.iiits.in",
	"password":"Hello World",
	"phoneNumber":"+911234567890",
	"collegeName":"Test College 123",
	"profilePicture":"url_to_profile_pic"
}' "http://localhost:8000/users/"
POST /users/ HTTP/1.1
Host: localhost:8000
Content-Type: application/json
Accept: application/json

{
	"username":"test_user_001",
	"firstName":"Test",
	"lastName":"User",
	"email":"test_user_001@testers.techfesia.iiits.in",
	"password":"Hello World",
	"phoneNumber":"+911234567890",
	"collegeName":"Test College 123",
	"profilePicture":"url_to_profile_pic"
}
Status201 Created
Content-Typeapplication/json
{
    "publicId": "sampleId123",
    "username": "test_user_001",
    "firstName": "Test",
    "lastName": "User",
    "email": "test_user_001@testers.techfesia.iiits.in",
    "phoneNumber": "+911234567890",
    "collegeName": "Test College 123",
    "profilePicture": "url_to_profile_pic",
    "dateJoined": "date_time_in_iso_format",
    "lastLogin": "date_time_in_iso_format"
}
Status422 Unprocessable Entity (WebDAV) (RFC 4918)
{
    "errors": {
        "username": "This username already exists"
    }
}
Status400 Bad Request
Content-Typeapplication/json
{
    "errors": {
        "username": "missing required field"
    }
}

Update User Details

curl -X PUT -H "Content-Type: application/json" -H "accept: application/json" -H "Authorization: Bearer sample_token" -d '{
	"username":"test_user_001",
	"firstName":"Test",
	"lastName":"User",
	"email":"test_user_001@testers.techfesia.iiits.in",
	"phoneNumber":"+911234567890",
	"collegeName":"Test College 123",
	"profilePicture":"url_to_profile_pic"
}' "http://localhost:8000/users/test_user_001"
PUT /users/test_user_001 HTTP/1.1
Host: localhost:8000
Content-Type: application/json
accept: application/json
Authorization: Bearer sample_token

{
	"username":"test_user_001",
	"firstName":"Test",
	"lastName":"User",
	"email":"test_user_001@testers.techfesia.iiits.in",
	"phoneNumber":"+911234567890",
	"collegeName":"Test College 123",
	"profilePicture":"url_to_profile_pic"
}
Status200 OK
{
    "publicId": "sampleId123",
    "username": "test_user_001",
    "firstName": "Test",
    "lastName": "User",
    "email": "test_user_001@testers.techfesia.iiits.in",
    "phoneNumber": "+911234567890",
    "collegeName": "Test College 123",
    "profilePicture": "url_to_profile_pic"
}

Update profile picture (o-auth)

curl -X PUT -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: Bearer sample_token" -d '{
	"provider":"google"
}' "http://localhost:8000/users/test_user_001/picture"
PUT /users/test_user_001/picture HTTP/1.1
Host: localhost:8000
Content-Type: application/json
Accept: application/json
Authorization: Bearer sample_token

{
	"provider":"google"
}
Status200 OK
{
    "message": "Profile Picture updated"
}

Disable User

curl -X PUT -H "Authorization: Bearer sample_token" "http://localhost:8000/users/test_user_001/disable"
PUT /users/test_user_001/disable HTTP/1.1
Host: localhost:8000
Authorization: Bearer sample_token

Delete User (Staff Only)

curl -X DELETE -H "Authorization: Bearer sample_staff_token" "http://localhost:8000/users/test_user_001/"
DELETE /users/test_user_001/ HTTP/1.1
Host: localhost:8000
Authorization: Bearer sample_staff_token

User Auth

User Auth modes

curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: Bearer sample_token" "http://localhost:8000/users/test_user_001/auth_modes"
GET /users/test_user_001/auth_modes HTTP/1.1
Host: localhost:8000
Content-Type: application/json
Accept: application/json
Authorization: Bearer sample_token
Status200 OK
Content-Typeapplication/json
{
    "password": true,
    "o-auth": [
        "google",
        "github",
        "facebook"
    ]
}

Create Password

curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: Bearer sample_token" -d '{
	"password":"Hello World"
}' "http://localhost:8000/users/test_user_001/password/"
POST /users/test_user_001/password/ HTTP/1.1
Host: localhost:8000
Content-Type: application/json
Accept: application/json
Authorization: Bearer sample_token

{
	"password":"Hello World"
}
Status201 Created
{
    "message": "new password created"
}

Change Password

curl -X PUT -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: Bearer sample_token" -d '{
	"oldPassword":"old_passord",
	"newPassword":"new_password"
}' "http://localhost:8000/users/test_user_001/password/"
PUT /users/test_user_001/password/ HTTP/1.1
Host: localhost:8000
Content-Type: application/json
Accept: application/json
Authorization: Bearer sample_token

{
	"oldPassword":"old_passord",
	"newPassword":"new_password"
}

Reset Password

curl -X PATCH -H "Content-Type: application/json" -H "Accept: application/json" -d '{
	"resetToken":"sampled_reset_token",
	"newPassword":"password"
}' "http://localhost:8000/users/test_user_001/password/"
PATCH /users/test_user_001/password/ HTTP/1.1
Host: localhost:8000
Content-Type: application/json
Accept: application/json

{
	"resetToken":"sampled_reset_token",
	"newPassword":"password"
}
Status200 OK
{
    "message": "Password reset successfully"
}
Status422 Unprocessable Entity (WebDAV) (RFC 4918)
{
    "error": {
        "resetToken": "token is invalid, expired or already used. Please get a new token"
    }
}