Skip to content

API Version 1: User

Nikhil Kansal edited this page Apr 23, 2017 · 5 revisions

GET /app/api/v1/user

The route requires authentication. It returns information about the currently logged in user. If the user is logged in, here is an example usage:

$ curl -H "Authorization: Bearer <TOKEN>" http://localhost/app/api/v1/user
{
    "error":null,
    "user": {
        "firstName": "John",
        "lastName": "Smith",
        "picture": "http://johnsmith.com/profile.jpg",
        "email": "jsmith@example.com",
        "year": 2,
        "major": "Cognitive Science",
        "points": 0
    }
}

If the token has expired, invalid, or not provided, the response will look something like this:

$ curl http://localhost/app/api/v1/user
{
    "error": {
        "status": 401,
        "message": "Unauthorized"
    }
}

PATCH /app/api/v1/user

This route requires authentication. It allows you to send a partial (differential) object of changes to the user information. It expects an application/json request with a body with the following (simplified) schema:

{
    user: {
        firstName: String,
        lastName: String,
        major: String,
        year: Number,
        password: { type: String, required: true },
        newPassword: String,
        confPassword: String
    }
}

The year field must be a number in the range [1, 2, 3, 4, 5], representing values of ['Freshman', 'Sophomore', 'Junior', 'Senior', 'Post-Senior'] respectively. Any field that does not need to be updated can be omitted except the password field, which is required. If the newPassword field is specified, the confPassword field must also be specified.

Common errors thrown by this call ([error.status] error.message):

  • [400] Bad Request – The call is probably missing the user object in the body
  • [400] The password field is required – The user object is missing the password field
  • [200] Passwords do not match – Either the newPassword and confPassword fields do not match or one of them is blank
  • [200] New password must be at least 8 characters – New password must be at least 8 characters
  • [401] Invalid password – The user entered their current password incorrectly

A successful call to this API will return the updated user information. For example, continuing the John Smith user example from above:

$ curl -H "Authorization: Bearer <TOKEN>" \
       --request PATCH \ 
       --data '{ "password": "test1234", "major": "Computer Science"' \
       http://localhost/app/api/v1/user

{
    "error": null,
    "user": {
        "firstName": "John",
        "lastName": "Smith",
        "picture": "http://johnsmith.com/profile.jpg",
        "email": "jsmith@example.com",
        "year": 2,
        "major": "Computer Science",
        "points": 0
    }
}