---
# System prepended metadata

title: Video API

---

# Video API

[![Build Status](https://travis-ci.com/whitecodelabs/video-message-backend.svg?token=u9GTxu9hxXbjfCHYQZ9T&branch=main)](https://travis-ci.com/whitecodelabs/video-message-backend)

## Development

`.env` variables.

```
AUTH0_JWKS_URI=https://dev-c4iga5kc.us.auth0.com/.well-known/jwks.json
AUTH0_AUDIENCE=https://www.vshare-api.com
AUTH0_ISSUER=https://dev-c4iga5kc.us.auth0.com/
AUTH0_EMAIL=https://api.getUser.com/email
AUTH0_NAME=https://api.getUser.com/name
AUTH0_PICTURE=https://api.getUser.com/picture
BASE_URL=http://localhost:5000
VIDEO_SERVER_URL=http://localhost:3000
MONGO_SECRET=somesecretekeyhere
MONGO_URL=mongodb+srv://admin:AUsdEsW65SCy6fV3@cluster0.uqd8m.mongodb.net/video-messaging?retryWrites=true&w=majority
AWS_ACCESS_KEY_ID=<aws access id>
AWS_SECRET_ACCESS_KEY=<aws secret>
S3_BUCKET=wcdlbs
```

## **Create Video**

- **URL**

  `/api/v0/video/create`

- **Method:**

  `POST`

- **Data Params**

  Body must contain video_title as `title`, video_description as `description`and videoId as `videoId`.

- **Required:**

  `title=[text]`
  `description=[text]`
  `videoId=[alphanumeric]`

- **Success Response:**

  **Code:** 200 <br />
  **Content:** `{ video : ef19ba00-18ab-411c-9360-e9c8f69eddb8 }`

- **Error Response:**

  **Code:** 401 UNAUTHORIZED <br />
  **Content:** `{ error : "No authorization token was found" }`

- **Sample Call:**

  ```

  axios.post('/uploadToMongo', {
  body: {
  title: "any_title",
  description: "any_description",
  videoId: "ef19ba00-18ab-411c-9360-e9c8f69eddb8"
  },
  headers: {'Authorization': 'Bearer <token>'},
  })
  .then(function (response) {
  console.log(response);
  })

  ```

## **Get Video Information**

- **URL**

`/api/v0/video/getVideo/:videoId`

- **Method:**

  `GET`

- **URL Params**

  url must contain a parameter as `videoId`

- **Required:**

  `videoId=[alphanumeric]`

- **Success Response:**

  **Code:** 200 <br />
  **Content:** `{_id: videoId, title: video_title, ... }`

- **Error Response:**

  **Code:** 401 UNAUTHORIZED <br />
  **Content:** `{ error : "No authorization token was found" }`

- **Sample Call:**

  ```

  axios.post('/video/ef19ba00-18ab-411c-9360-e9c8f69eddb8', {
  headers: {'Authorization': 'Bearer <token>'},
  })
  .then(function (response) {
  console.log(response);
  })

  ```

## **Set Video Share Permission**

- **URL**

  `/updateVideoPrivacy`

- **Method:**

  `POST`

- **Data Params**

  Body must contain shareType as `shareType`, participantEmail as `email`and videoId as `videoId`.

- **Required:**

  `shareType=[public/private]`
  `videoId=[alphanumeric]`

- **Success Response:**

  **Code:** 200 <br />
  **Content:** `{video privacy updated}`

- **Error Response:**

  **Code:** 401 UNAUTHORIZED <br />
  **Content:** `{ error : "No authorization token was found" }`

- **Sample Call:**

  ```

  axios.post('/updateShareInfo', {
  body: {
  email: "email@email.com",
  shareType: "private",
  videoId: "ef19ba00-18ab-411c-9360-e9c8f69eddb8"
  },
  headers: {'Authorization': 'Bearer <token>'},
  })
  .then(function (response) {
  console.log(response);
  })

  ```

## **Allow/Disallow Users for watch permission**

- **URL**

  `/updateVideoUsers`

- **Method:**

  `POST`

- **Data Params**

  Body must contain participantEmail as `email` and videoId as `videoId`.

- **Required:**

  `email=[email@email.com]`
  `videoId=[alphanumeric]`

- **Success Response:**

  **Code:** 200 <br />
  **Content:** `{ user allowed/user disallowed }`

- **Error Response:**

  **Code:** 401 UNAUTHORIZED <br />
  **Content:** `{ error : "No authorization token was found" }`

- **Sample Call:**

  ```

  axios.post('/disallowUser', {
  body: {
  email: "email@email.com",
  videoId: "ef19ba00-18ab-411c-9360-e9c8f69eddb8"
  },
  headers: {'Authorization': 'Bearer <token>'},
  })
  .then(function (response) {
  console.log(response);
  })

  ```

## **Delete Video**

- **URL**

  `/api/v0/video/deleteVideo`

- **Method:**

  `POST`

- **Data Params**

  Body must contain videoId as `videoId`.

- **Required:**

  `videoId=[alphanumeric]`

- **Success Response:**

  **Code:** 200 <br />
  **Content:** `{ video deleted successfully }`

- **Error Response:**

  **Code:** 401 UNAUTHORIZED <br />
  **Content:** `{ error : "No authorization token was found" }`

- **Sample Call:**

  ```

  axios.post('/deleteVideo', {
  body: {
  videoId: "ef19ba00-18ab-411c-9360-e9c8f69eddb8"
  },
  headers: {'Authorization': 'Bearer <token>'},
  })
  .then(function (response) {
  console.log(response);
  })

  ```

# Group API

## Group Schema

```
  Group: {

      Name: String,
      Description: String,
    ImgURl: String,
      Creator: String,
      Members: [Member],
    Videos: [Ref. Videos]
  }
```

- **Member**

```

Member: {
RoleID: [creator/admin/member];
UserID: [Ref. User]
}

```

## **Create Group**

- **URL**

  `/api/v0/group/create`

- **Method:**

  `POST`

- **Data Params**

  Body must contain group_name as `name` and group_description as `description`.

- **Required:**

  `name=[text]`
  `description=[text]`

- **Success Response:**

  **Code:** 200 <br />
  **Content:** `{ groupCreated : {name: string, description: string ... } }`

- **Error Response:**

  **Code:** 404 UNAUTHORIZED <br />
  **Content:** `{ error : "User Not Found" }`

- **Sample Call:**

  ```

  axios.post('/api/v0/group/create', {
  body: {
  name: "any_name",
  description: "any_description",
  },
  headers: {'Authorization': 'Bearer <token>'},
  })
  .then(function (response) {
  console.log(response);
  })

  ```

## **Get group information**

- **URL**

  `/api/v0/group/[:groupId]/get`

- **Method:**

  `GET`

- **URL Params**

  `groupId: [alphanumeric]`

- **Required:**

  `groupId: [alphanumeric]`

- **Success Response:**

  **Code:** 200 <br />
  **Content:** ` {group: {name: string, description: string ... } }`

- **Error Response:**

  **Code:** 404 NO_DATA_FOUND <br />
  **Content:** `{ error : "No data found" }`

- **Sample Call:**

  ```

  axios.get('/api/v0/group/[:groupId]/get', {
  headers: {'Authorization': 'Bearer <token>'},
  })
  .then(function (response) {
  console.log(response);
  })

  ```

## **Group update**

- **URL**

  `/api/v0/group/[:groupId]/update`

- **Method:**

  `POST`

- **URL Params**

  `groupId: [alphanumeric]`

- **Data Params**

  Body should contain group_name as `name` and group_description `description`.

- **Required:**

  `name: [text]`
  `description: [text]`

- **Success Response:**

  **Code:** 200 <br />
  **Content:** ` {success: "success" }`

- **Error Response:**

  **Code:** 404 NO_DATA_FOUND <br />
  **Content:** `{ error : "No data found" }`

- **Sample Call:**

  ```

  axios.post('/api/v0/group/[:groupId]/update', {
  body: {
  name: "group_new_name",
  description: "group_new_description"
  },
  headers: {'Authorization': 'Bearer <token>'},
  })
  .then(function (response) {
  console.log(response);
  })

  ```

## **Share video to group**

- **URL**

  `/api/v0/group/[:groupId]/share`

- **Method:**

  `POST`

- **URL Params**

  `groupId: [alphanumeric]`

- **Data Params**

  Body must contain `videoId` to share.

- **Required:**

  `videoId: [alphanumeric]`

- **Success Response:**

  **Code:** 200 <br />
  **Content:** `{ success: "video sent to the group" }`

- **Error Response:**

  **Code:** 404 NO_DATA_FOUND <br />
  **Content:** `{ error : "No data found" }`

- **Sample Call:**

  ```

  axios.post('/api/v0/group/[:groupId]/share', {
  body: {
  videoId: "60d0abe3190f9a4340cdd39c"
  },
  headers: {'Authorization': 'Bearer <token>'},
  })
  .then(function (response) {
  console.log(response);
  })

  ```

## **Invite members to group**

- **URL**

  `/api/v0/group/[:groupId]/invite`

- **Method:**

  `POST`

- **URL Params**

  `groupId: [alphanumeric]`

- **Data Params**

  Body must contain an array of users to invite.

- **Required:**

  ```
    [
    {
      email: string,
      role: string,
    },
    {
      email: string,
      role: string,
    }
    ]
  ```

- **Success Response:**

  **Code:** 200 <br />
  **Content:** `{ successs : "Users Invited Successfully" }`

- **Error Response:**

  **Code:** 404 NO_DATA_FOUND <br />
  **Content:** `{ error : "No data found" }`

- **Sample Call:**

  ```

  axios.post('/api/v0/group/[:groupId]/invite', {
  body: {
  addUsers: [user_array]
  },
  headers: {'Authorization': 'Bearer <token>'},
  })
  .then(function (response) {
  console.log(response);
  })

  ```

## **Remove group member (admin/member)**

- **URL**

  `/api/v0/group/[:groupId]/kick`

- **Method:**

  `POST`

- **URL Params**

  `groupId: [alphanumeric]`

- **Data Params**

  Body must contain an array of users to remove.

- **Required:**

  ```
    [
    {
      email: string
    },
    {
      email: string
    }
    ]
  ```

- **Success Response:**

  **Code:** 200 <br />
  **Content:** `{ successs : "Users/User kicked Successfully" }`

- **Error Response:**

  **Code:** 404 NO_DATA_FOUND <br />
  **Content:** `{ error : "No data found" }`

- **Sample Call:**

  ```

  axios.post('/api/v0/group/[:groupId]/kick', {
  body: {
  addUsers: [user_array]
  },
  headers: {'Authorization': 'Bearer <token>'},
  })
  .then(function (response) {
  console.log(response);
  })

  ```

## **Delete group**

- **URL**

  `/api/v0/group/[:groupId]/delete`

- **Method:**

  `POST`

- **URL Params**

  `groupId: [alphanumeric]`

- **Required:**

  `groupId: [alphanumeric]`

- **Success Response:**

  **Code:** 200 <br />
  **Content:** `{ success: "Group Deleted successfully" }`

- **Error Response:**

  **Code:** 404 NO_DATA_FOUND <br />
  **Content:** `{ error : "No data found" }`

- **Sample Call:**

  ```

  axios.post('/api/v0/group/[:groupId]/delete', {
  headers: {'Authorization': 'Bearer <token>'},
  })
  .then(function (response) {
  console.log(response);
  })

  ```

# Video Converting API

## **Generate Adaptive Resolution**

- **URL**

  `/transcode`

- **Method:**

  `POST`

- **Data Params**

  Body must contain video_file as `file` and socketId as `randomId`.

- **Required:**

  `file=[file]`
  `randomId=[alphanumeric]`

- **Success Response:**

  **Code:** 200 <br />
  **Content:** `{ video : [alphanumeric] }`

- **Sample Call:**

  ```

  axios.post('/transcode', {
  body: {
  file: video.mp4,
  randomId: xi7s87x,
  },
  headers: {'Authorization': 'Bearer <token>'},
  })
  .then(function (response) {
  console.log(response);
  })

  ```

# Socket Server

## Connect to Socker Server

    import { io } from "socket.io-client";
    import randomString from "randomstring";

    const socket = io("https://vcsock.diplay.app");
    var randId = randomString.generate(7);
    const connectUser = () => { return socket.emit("userConnected", randId);};
    socket.on("connect", connectUser);

## Socket Events

- ## Get Dolby Processing Progress
  socket.on("dolbyProgress", (progress) => {console.log(progress)});
- ## Get Video Converting Progress

  socket.on("getProgress", (progress) => {console.log(progress)});

- ## Get Upload Video Progress
  socket.on("getPercentage", (progress) => {console.log(progress)});


## Setup Swagger Documentation

- **Create Swagger Account on https://swagger.io/**
- **Create New API Documentation**
- **Replace all the pre-written text with the swagger_specification.txt**
- **Add Authentication Token on the Swagger Platform**
- **Try Executing the queries and see results in realtime**