Skip to content

API Documentation

Laiba Afzal edited this page Sep 5, 2024 · 1 revision

API Documentation

USER AUTHENTICATION/AUTHORIZATION

All endpoints that require authentication

All endpoints that require a current user to be logged in.

  • Request: endpoints that require authentication
  • Error Response: Require authentication
    • Status Code: 401

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Authentication required"
      }

All endpoints that require proper authorization

All endpoints that require authentication and the current user does not have the correct role(s) or permission(s).

  • Request: endpoints that require proper authorization
  • Error Response: Require proper authorization
    • Status Code: 403

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Forbidden"
      }

Get the Current User

Returns the information about the current user that is logged in.

  • Require Authentication: false

  • Request

    • Method: GET
    • URL: /api/session
    • Body: none
  • Successful Response when there is a logged in user

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "user": {
          "id": 1,
          "firstName": "Hongjoong",
          "lastName": "Kim",
          "email": "khj@kaykew.io",
          "username": "khj1107"
        }
      }
  • Successful Response when there is no logged in user

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "user": null
      }

Log In a User

Logs in a current user with valid credentials and returns the current user's information.

  • Require Authentication: false

  • Request

    • Method: POST

    • URL: /api/session

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "credential": "khj@kaykew.io",
        "password": "8makes1team"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "user": {
          "id": 1,
          "firstName": "Hongjoong",
          "lastName": "Kim",
          "email": "khj@kaykew.io",
          "username": "khj1107"
        }
      }
  • Error Response: Invalid credentials

    • Status Code: 401

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Invalid credentials"
      }
  • Error response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Bad Request", // (or "Validation error" if generated by Sequelize),
        "errors": {
          "credential": "Email or username is required",
          "password": "Password is required"
        }
      }

Sign Up a User

Creates a new user, logs them in as the current user, and returns the current user's information.

  • Require Authentication: false

  • Request

    • Method: POST

    • URL: /api/users

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "firstName": "Hongjoong",
        "lastName": "Kim",
        "email": "khj@kaykew.io",
        "username": "khj1107",
        "password": "8makes1team"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "user": {
          "id": 1,
          "firstName": "Hongjoong",
          "lastName": "Kim",
          "email": "khj@kaykew.io",
          "username": "khj1107"
        }
      }
  • Error response: User already exists with the specified email

    • Status Code: 500

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "User already exists",
        "errors": {
          "email": "User with that email already exists"
        }
      }
  • Error response: User already exists with the specified username

    • Status Code: 500

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "User already exists",
        "errors": {
          "username": "User with that username already exists"
        }
      }
  • Error response: Body validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Bad Request", // (or "Validation error" if generated by Sequelize),
        "errors": {
          "email": "Invalid email",
          "username": "Username is required",
          "firstName": "First Name is required",
          "lastName": "Last Name is required"
        }
      }

Notebooks

Get all Notebooks

Returns all the notebooks of the current user.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/notebooks
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "notebooks":
        [
          {
              "id": 1,
              "ownerId": 1,
              "name": "Work",
              "favorite": true,
              "createdAt": "2024-08-29T21:28:48.950Z",
              "updatedAt": "2024-08-29T21:28:48.950Z"
          }
        ]
      }

Get Favorite Notebooks

Returns all the favorite notebooks of the current user.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/notebooks/favorites
    • Body: none
  • Successful Response

    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "notebooks":
        [
          {
            "id": 1,
            "ownerId": 1,
            "name": "Work",
            "favorite": true,
            "createdAt": "2024-08-29T21:28:48.950Z",
            "updatedAt": "2024-08-29T21:28:48.950Z"
          }
        ]
      }

Get Notebook Details

Returns a notebook and its associated notes by notebook ID for the logged-in user.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/notebooks/:id
    • Body: none
  • Successful Response

    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "id": 1,
        "ownerId": 1,
        "name": "Work",
        "favorite": true,
        "createdAt": "2024-08-29T21:28:48.950Z",
        "updatedAt": "2024-08-29T21:28:48.950Z",
        "Notes": [
          {
            "id": 1,
            "ownerId": 1,
            "notebookId": 1,
            "title": "Project Plan",
            "description": "Outline the project phases: research, design, development, testing, and deployment.",
            "createdAt": "2024-08-29T21:28:48.960Z",
            "updatedAt": "2024-08-29T21:28:48.960Z"
          },
          {
            "id": 2,
            "ownerId": 1,
            "notebookId": 1,
            "title": "Meeting Notes",
            "description": "Discussed the project timeline, assigned tasks, and set the next meeting for Friday.",
            "createdAt": "2024-08-29T21:28:48.960Z",
            "updatedAt": "2024-08-29T21:28:48.960Z"
          }
        ]
      }
  • Error Response: Notebook not found

    • Status Code: 404
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "Notebook not found."
      }
  • Error Response: Unauthorized access

    • Status Code: 403
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "You do not have access to this notebook."
      }

Create a Notebook

Creates a new notebook and returns a new notebook

  • Require Authentication: true

  • Request

    • Method: POST

    • URL: /api/notebooks

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "name": "new-notebook"
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "id": 3,
          "ownerId": 1,
          "name": "new-notebook",
          "favorite": false,
          "createdAt": "2024-08-29T21:28:48.960Z",
          "updatedAt": "2024-08-29T21:28:48.960Z"
        }
  • Error Response: Validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "message": "Validation error",
          "errors": {
            "name": "Notebook name is required.",
            "name": "Notebook name must be less than 50 characters."
          }
        }

Edit a Notebook

Edits an existing notebook for the logged in user.

  • Require Authentication: true

  • Request

    • Method: PUT

    • URL: /api/notebooks/:id

    • Headers:

      • Content-Type: application/json
    • Body:

      {
          "name": "new-notebook-edited",
          "favorite": true
      }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "id": 3,
          "ownerId": 1,
          "name": "new-notebook-edited",
          "favorite": true,
          "createdAt": "2024-08-29T21:28:48.960Z",
          "updatedAt": "2024-08-30T21:28:48.960Z"
        }
  • Error Response: Validation errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "message": "Validation error",
          "errors": {
            "name": "Notebook name is required.",
            "name": "Notebook name must be less than 50 characters."
          }
        }
  • Error Response: Notebook not found

    • Status Code: 404
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "Notebook not found."
      }
  • Error Response: Unauthorized access

    • Status Code: 403
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "You do not have access to this notebook."
      }

Delete a Notebook

Deletes an existing notebook for the logged-in user, including its associated notes and tags.

  • Require Authentication: true

  • Request

    • Method: DELETE
    • URL: /api/notebooks/:id
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Notebook, its notes, and associated tags successfully deleted"
      }
  • Error Response: Notebook not found

    • Status Code: 404
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "Notebook not found."
      }
  • Error Response: Unauthorized access

    • Status Code: 403
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "You do not have access to this notebook."
      }
  • Error Response: Failed to Delete Notebook

    • Status Code: 500
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "Failed to delete notebook, its notes, and associated tags."
      }

Notes

Get Note Details

Returns all details for a specific note, including its associated tags.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/notebooks/:id
    • Body: none
  • Successful Response

    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
        {
          "id": 1,
          "ownerId": 1,
          "notebookId": 1,
          "title": "Project Plan",
          "description": "Outline the project phases: research, design, development, testing, and deployment.",
          "createdAt": "2024-08-29T21:28:48.960Z",
          "updatedAt": "2024-08-29T21:28:48.960Z",
          "Tags": [
              {
                  "id": 1,
                  "userId": 1,
                  "name": "Work",
                  "createdAt": "2024-08-29T21:28:48.971Z",
                  "updatedAt": "2024-08-29T21:28:48.971Z"
              }
          ]
        }
  • Error Response: Note Not Found

    • Status Code: 404
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "Note not found."
      }
  • Error Response: Unauthorized access

    • Status Code: 403
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "You do not have access to this note."
      }

Create a New Note

Creates a new note for a specific notebook and returns the newly created note.

  • Require Authentication: true

  • Request

    • Method: POST

    • URL: /api/notes

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "title": "New Note",
          "description": "This is a new note.",
          "notebookId": 1
        }
  • Successful Response

    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
        {
          "id": 3,
          "title": "New Note",
          "description": "This is a new note.",
          "notebookId": 1,
          "ownerId": 1,
          "createdAt": "2024-08-03T12:00:00.000Z",
          "updatedAt": "2024-08-03T12:00:00.000Z"
        }
  • Error Response: Validation Errors

    • Status Code: 400
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "Validation error",
        "errors": {
          "title": "Note title is required.",
          "title": "Note title must be less than 100 characters.",
          "description": "Note description is required."
        }
      }
  • Error Response: Missing Required Fields

    • Status Code: 400
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "All fields are required."
      }

Edit a Note

Edits an existing note and returns the updated note with its associated tags.

  • Require Authentication: true

  • Request

    • Method: PUT

    • URL: /api/notes/:id

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "title": "Edited Note",
          "description": "This is an edited note.",
          "notebookId": 1
        }
  • Successful Response

    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
        {
          "id": 3,
          "title": "Updated Note Title",
          "description": "Updated note description.",
          "notebookId": 1,
          "ownerId": 1,
          "createdAt": "2024-08-03T12:00:00.000Z",
          "updatedAt": "2024-08-03T12:05:00.000Z",
          "Tags": [
            {
              "id": 1,
              "name": "Important"
            }
          ]
        }
  • Error Response: Note Not Found

    • Status Code: 404
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "Note not found."
      }
  • Error Response: Unauthorized access

    • Status Code: 403
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "You do not have access to this note."
      }
  • Error Response: Validation Errors

    • Status Code: 400
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "Validation error",
        "errors": {
          "title": "Note title is required.",
          "title": "Note title must be less than 100 characters.",
          "description": "Note description is required."
        }
      }

Delete a Note

Deletes an existing note and its associated tags.

  • Require Authentication: true

  • Request

    • Method: DELETE
    • URL: /api/notes/:id
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

      {
        "message": "Note and its associated tags successfully deleted"
      }
  • Error Response: Notebook not found

    • Status Code: 404
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "Note not found."
      }
  • Error Response: Unauthorized access

    • Status Code: 403
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "You do not have access to this note."
      }
  • Error Response: Failed to Delete Note

    • Status Code: 500
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "Failed to delete note and its associated tags."
      }

Add a Tag to a Note

Adds a new tag to a specific note and returns the updated note with its associated tags.

  • Require Authentication: true

  • Request

    • Method: POST

    • URL: /api/notes/:id/tags

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "name": "New Tag"
        }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "id": 3,
          "title": "Updated Note Title",
          "description": "Updated note description.",
          "notebookId": 1,
          "ownerId": 1,
          "createdAt": "2024-08-03T12:00:00.000Z",
          "updatedAt": "2024-08-03T12:05:00.000Z",
          "Tags": [
            {
              "id": 1,
              "name": "Important"
            },
            {
              "id": 3,
              "name": "New Tag"
            }
          ]
        }
  • Error Response: Note not found

    • Status Code: 404
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "Note not found."
      }
  • Error Response: Unauthorized access

    • Status Code: 403
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "You do not have access to this note."
      }
  • Error Response: Failed to Add Tag to Note

    • Status Code: 500
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "Failed to add tag to note."
      }

Delete Tag From a Note

Deletes a tag from a specific note and returns the updated note with its associated tags.

  • Require Authentication: true

  • Request

    • Method: DELETE
    • URL: /api/notes/:noteId/tags/:tagId
    • Body: none
  • Successful Response

    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
        {
          "id": 3,
          "title": "Updated Note Title",
          "description": "Updated note description.",
          "notebookId": 1,
          "ownerId": 1,
          "createdAt": "2024-08-03T12:00:00.000Z",
          "updatedAt": "2024-08-03T12:05:00.000Z",
          "Tags": []
        }
  • Error Response: Tag not found

    • Status Code: 404
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "Tag not found."
      }
  • Error Response: Unauthorized access

    • Status Code: 403
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "You do not have access to this note."
      }
  • Error Response: Failed to Delete Tag From Note

    • Status Code: 500
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "Failed to delete tag from note."
      }

Tasks

Get All Tasks Due Within the Next 5 Days For Reminders

Fetches all tasks of the current user that are due within the next 5 days.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/tasks/reminders
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "tasks": [
            {
              "id": 1,
              "userId": 1,
              "title": "Finish project",
              "description": "Complete the capstone project",
              "dueDate": "2024-08-03T12:00:00.000Z",
              "priority": "high",
              "completed": false,
              "createdAt": "2024-08-01T10:00:00.000Z",
              "updatedAt": "2024-08-01T11:00:00.000Z"
            },
          ]
        }
  • Error Response: Failed to fetch reminders

    • Status Code: 500

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "message": "Failed to fetch reminders."
        }

Get All Tasks of Current User

Returns all tasks associated with the logged-in user.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/tasks
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

        [
          {
            "id": 1,
            "userId": 1,
            "title": "Finish project",
            "description": "Complete the capstone project",
            "dueDate": "2024-08-03T12:00:00.000Z",
            "priority": "high",
            "completed": false,
            "createdAt": "2024-08-01T10:00:00.000Z",
            "updatedAt": "2024-08-01T11:00:00.000Z"
          },
        ]
  • Error Response

    • Status Code: 500

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "message": "Failed to fetch tasks."
        }

Get Task Details

Returns detailed information about a specific task.

  • Require Authentication: true

  • Request

    • Method: GET
    • URL: /api/tasks/:taskId
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "id": 1,
          "userId": 1,
          "title": "Finish project",
          "description": "Complete the capstone project",
          "dueDate": "2024-08-03T12:00:00.000Z",
          "priority": "high",
          "completed": false,
          "createdAt": "2024-08-01T10:00:00.000Z",
          "updatedAt": "2024-08-01T11:00:00.000Z"
        }
  • Error Response: Task Not Found

    • Status Code: 404
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "Task not found."
      }
  • Error Response: Unauthorized access

    • Status Code: 403
    • Headers:
      • Content-Type: application/json
    • Body:
      {
        "message": "You do not have access to this task."
      }
  • Error Response

    • Status Code: 500

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "message": "Failed to fetch task details."
        }

Create a New Task

Creates a new task for the logged-in user.

  • Require Authentication: true

  • Request

    • Method: POST

    • URL: /api/tasks

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "title": "Finish project",
          "description": "Complete the capstone project",
          "dueDate": "2024-08-03T12:00:00.000Z",
          "priority": "high"
        }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "id": 1,
          "userId": 1,
          "title": "Finish project",
          "description": "Complete the capstone project",
          "dueDate": "2024-08-03T12:00:00.000Z",
          "priority": "high",
          "completed": false,
          "createdAt": "2024-08-01T10:00:00.000Z",
          "updatedAt": "2024-08-01T11:00:00.000Z"
        }
  • Error Response: Validation Errors

    • Status Code: 400

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "errors": [
            "Task title is required.",
            "Description is required.",
            "Due date is required.",
            "Priority is required."
          ]
        }

Edit an Existing Task

Updates a task's details.

  • Require Authentication: true

  • Request

    • Method: PUT

    • URL: /api/tasks/:taskId

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "title": "Finish project edited",
          "description": "Complete the capstone project edited",
          "dueDate": "2024-08-03T12:00:00.000Z",
          "priority": "medium",
          "completed": true
        }
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "id": 1,
          "userId": 1,
          "title": "Finish project edited",
          "description": "Complete the capstone project edited",
          "dueDate": "2024-08-03T12:00:00.000Z",
          "priority": "medium",
          "completed": true,
          "createdAt": "2024-08-01T10:00:00.000Z",
          "updatedAt": "2024-08-01T11:00:00.000Z"
        }
  • Error Response: Task Not Found

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "message": "Task not found."
        }
  • Error Response: Server Error

    • Status Code: 500

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "message": "Failed to update task."
        }

Delete a Task

Deletes a task owned by the logged-in user.

  • Require Authentication: true

  • Request

    • Method: DELETE
    • URL: /api/tasks/:taskId
    • Body: none
  • Successful Response

    • Status Code: 200

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "message": "Task successfully deleted"
        }
  • Error Response: Task Not Found

    • Status Code: 404

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "message": "Task not found."
        }
  • Error Response: Server Error

    • Status Code: 500

    • Headers:

      • Content-Type: application/json
    • Body:

        {
          "message": "Failed to delete task."
        }