Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.

user_endpoints

FusionSid edited this page Aug 10, 2022 · 3 revisions

User/Users endpoints (HTTPS/REST):


Get current logged in user:

GET /api/user/me

Authorization required for this endpoint

Returns the currently logged in user. To see who is logged in it checks who the access token from the Authorization header belongs too.

If authenticated successfully the response will be a user object like this:

Request:

curl -X 'GET' \
  'https://chatapi.fusionsid.xyz/api/user/me' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <access_token>'

Response:

// status code if success: 200
{
  "username": "string",
  "password": "string",
  "email": "string",
  "permissions": {
    "perm_name": boolean,
    ...
  },
  "public_key": "string",
  "user_id": integer
}

Try the endpoint out here: Link


Create new user/signup:

POST /api/users/signup

Authentication not required for this endpoint

This endpoint is used to signup users/create new users for the app.

Request Schema:

drawing

Request
A request to this endpoint will look like this:

curl -X 'POST' \
  'https://chatapi.fusionsid.xyz/api/users/signup' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "username": "string",
  "email": "string",
  "password": "string",
  "public_key": "string"
}'

If successful you will get a user object response.

Example successful response:

{
  "success": true,
  "detail": "User created successfully",
  "user": {
    "username": "string",
    "password": "string",
    "email": "string",
    "permissions": {
      "perm_name": boolean,
      ...
    },
    "public_key": "string",
    "user_id": integer
  }
}

Errors

If you make a request and the username is the same as some user that already exists you will get an error like this:

Unsuccessful Response:

// Status code: 409
{
  "detail": "User with this username already exists"
}

Try the endpoint out here: Link


Get all users

GET /api/users/getAllUsers

Authentication required for this endpoint

This endpoint is used to get all users registered to the app / users in the database.
Its very simple and doesn't require and data passed to it (except auth).

Request Schema:

No data/parameters/arguments are needed for this endpoint

Request

curl -X 'GET' \
  'https://chatapi.fusionsid.xyz/api/users/getAllUsers' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <access token>'

Example successful response:

If successful you will get a list of user objects

[
  {
    "username": "string",
    "password": "string",
    "email": "string",
    "permissions": {
      "perm_name": boolean,
      ...
    },
    "public_key": "string",
    "user_id": integer
  },
  ...
]

Try the endpoint out here: Link


Get user by id:

GET /api/users/{user_id}

Authentication required for this endpoint

This endpoint if for getting a user object by the id. It searches the database for another user who has the same id and if so it will return it. Since no 2 users can have the same id it will only return one user and if it cant find it, it will return an error.

Request Schema:

drawing

user_id must be passed in the path and must be an integer.

Example Request

curl -X 'GET' \
  'https://chatapi.fusionsid.xyz/api/users/690420690' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <access token>'

Example successful response:

If user is found you will get a user object:

{
    "username": "string",
    "password": "string",
    "email": "string",
    "permissions": {
      "perm_name": boolean,
      ...
    },
    "public_key": "string",
    "user_id": integer
}

Errors

Unsuccessful Response:

If user is not found you will get this error:

{
  "detail": "User with this id doesnt exists"
}

Try the endpoint out here: Link


Update user details:

PATCH /api/users/{user_id}

Authentication required for this endpoint

This endpoint is used to update a specific user. For example changing their password or saved public key.

Request Schema:

drawing

The user id just like the get user by id endpoint needs to be passed in the path.

The attribute is the name of the value you want to change.
Options: "username", "password", "email", "public_key"
See the user object section for info about each attribute.

The new_value is the new value of the attribute. So if you want to change the email to "example@gmail.com" you would do:

{
  "attribute": "email",
  "new_value": "example@gmail.com"
}

Example Request

curl -X 'PATCH' \
  'https://chatapi.fusionsid.xyz/api/users/690420690' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <access token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "attribute": "string",
  "new_value": "string"
}'

Example successful response:

If successful you will get a response with the before and after (user objects) of the user:

{
  "result": "User updated successfully",
  "new_user": {
    "username": "string",
    "password": "string",
    "email": "string",
    "permissions": {
      "perm_name": boolean,
      ...
    },
    "public_key": "string",
    "user_id": integer
  },
  "old_user": {
    "username": "string",
    "password": "string",
    "email": "string",
    "permissions": {
      "perm_name": boolean,
      ...
    },
    "public_key": "string",
    "user_id": integer
  }
}

Errors

Unsuccessful Response:

If you enter an attribute that doesn't exist you will get an error like this:

{
  "detail": {
    "error": "Invalid attribute provided.",
    "options": [
      ...
    ]
  }
}

If the user is not found you will get an error like this:

{
  "detail": {
    "error": "User with id provided does not exist",
    "id_provided": ...
  }
}

Try the endpoint out here: Link


Update logged in user's details:

PATCH /api/user/me

Authentication required for this endpoint

This endpoint is used to update a the user who is currently logged in.
It will figure that out by looking at the user id that the token belongs too.
This endpoint is basically the same as the PATCH /api/users/{user_id} endpoint except you don't pass in the user id

Request Schema:

drawing

The attribute is the name of the value you want to change.
Options: "username", "password", "email", "public_key"
See the user object section for info about each attribute.

The new_value is the new value of the attribute. So if you want to change the email to "example@gmail.com" you would do:

{
  "attribute": "email",
  "new_value": "example@gmail.com"
}

Example Request

curl -X 'PATCH' \
  'https://chatapi.fusionsid.xyz/api/user/me' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <access token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "attribute": "string",
  "new_value": "string"
}'

Example successful response:

If successful you will get a response with the before and after (user objects) of the user:

{
  "result": "User updated successfully",
  "new_user": {
    "username": "string",
    "password": "string",
    "email": "string",
    "permissions": {
      "perm_name": boolean,
      ...
    },
    "public_key": "string",
    "user_id": integer
  },
  "old_user": {
    "username": "string",
    "password": "string",
    "email": "string",
    "permissions": {
      "perm_name": boolean,
      ...
    },
    "public_key": "string",
    "user_id": integer
  }
}

Errors

Unsuccessful Response:

If you enter an attribute that doesn't exist you will get an error like this:

{
  "detail": {
    "error": "Invalid attribute provided.",
    "options": [
      ...
    ]
  }
}

Try the endpoint out here: Link

Clone this wiki locally