RestAPI example

From PKC
Jump to navigation Jump to search


RestAPI testing

    1. User

+ Base Url: https://app.trackonperformance.com/api/user/ + Swagger Url: https://app.trackonperformance.com/swagger/#/User

      1. Description

User's are the primary resource that holds every other resource and they have the following properties:

+ _id | the unique identifier for this entity + name | string | max_length 50 + email | string | max_length 255 + password | string | min_length 3 | max_length 50 + contact | string | max_length 30 + avatarUrl | string + location | string | default: England + language | string | default: auto | Auto by default which allows frontend application to choose from the URL + mainSkills | string | default: + personalInterests | string | default: + lastLogin | Date | ($date-time) + lastWorking | Date | ($date-time) + lastAccount | string + signature | string | default: + birthdate | string or null + clockPaused | boolean | default: false + coffeePauses | + + pauseAt | Date | ($date-time) + + resumedAt | Date | ($date-time) + clockAbsences | + + leftAt | Date | ($date-time) + + returnedAt | Date | ($date-time) + clockBurnedHours | + + credits | number | + + createdAt | Date | ($date-time) + howToBegin | UserHowToBegin + + firstTimeCharter | boolean | default:false + + firstTimeProject | boolean | default:false + + firstTimeOBS | boolean | default:false + isTopAdmin | boolean | default:false + timezone | string | default: Europe/Lisbon + hubspotTokens | + + accessToken | string + + refreshToken | string


user How to begin has a special condition, for the new coming users, on a process of entering:

+ firstTimeCharter | boolean | default: false + firstTimeProject | boolean | default: false + firstTimeOBS | boolean | default: false

      1. Returns user Notifications

Returns user Notifications

Request example: ```typescript

   import axios from 'axios'
   ( async function () {
       const accountId = 1234
       const response = await axios({
           url: `https://app.trackonperformance.com/api/user/notifications`,
           method: 'GET',
           headers: {
               'Content-Type': 'application/json',
               'Authorization': 'Bearer <your token>'
           }
           
       })
       if (response.status === 200) {
           console.log("user was notified")
       }
   } )()

```


      1. Returns user archive

Returns user archive

Request example: ```typescript

   import axios from 'axios'
   ( async function () {
       const accountId = 1234
       const response = await axios({
           url: `https://app.trackonperformance.com/api/user/archive`,
           method: 'GET',
           headers: {
               'Content-Type': 'application/json',
               'Authorization': 'Bearer <your token>'
           }
           
       })
       if (response.status === 200) {
           console.log("user got the archive")
       }
   } )()

```


      1. Returns user projects

Returns the user portfolio and projects

Request example: ```typescript

   import axios from 'axios'
   ( async function () {
       const accountId = 1234
       const response = await axios({
           url: `https://app.trackonperformance.com/api/user/projects`,
           method: 'GET',
           headers: {
               'Content-Type': 'application/json',
               'Authorization': 'Bearer <your token>'
           }
           
       })
       if (response.status === 200) {
           console.log("user got the portfolio or projects")
                   const { data } = response
                   console.log({
                       "current": {
                           "_id": data._id,
                           "name": data.name,
                       "portfolios": {
                           "_id": data._id,
                           "name": data.name,
                           "projects": {
                               "_id": data._id,
                               "name": data.name,
                     }
                           "programs": {
                               "_id": data._id,
                               "name": data.name,
                               "projects":{
                                   "_id": data._id,
                                   "name": data.name,
                           }
                     }
               }               
           })            
       }
   } )()

```



      1. Returns user charters

Returns the list of charters the user can see (members or team leaders dont have access)


Request example: ```typescript

   import axios from 'axios'
   ( async function () {
       const accountId = 1234
       const response = await axios({
           url: `https://app.trackonperformance.com/api/user/charters`,
           method: 'GET',
           headers: {
               'Content-Type': 'application/json',
               'Authorization': 'Bearer <your token>'
           }
           
       })
       if (response.status === 200) {
           console.log("user got the charters")
                   const { data } = response
                   console.log({
                       "_id": data._id,
                       "name": data.name,
                }            
       }
   } )()

```


      1. Returns user orgs

Returns the organizations the authenticated user has access to


Request example: ```typescript

   import axios from 'axios'
   ( async function () {
       const accountId = 1234
       const response = await axios({
           url: `https://app.trackonperformance.com/api/user/orgs`,
           method: 'GET',
           headers: {
               'Content-Type': 'application/json',
               'Authorization': 'Bearer <your token>'
           }
           
       })
       if (response.status === 200) {
           console.log("user got the orgs")
                   const { data } = response
                   console.log({
                       "_id": data._id,
                       "name": data.name,
                       "description": data.description,
                       "creator": data.creator,
                       "jobDescription": data.jobDescription,
                       "admins": data.admins,
                }            
       }
   } )()

```


      1. Returns user logins

Returns the login history


Request example: ```typescript

   import axios from 'axios'
   ( async function () {
       const accountId = 1234
       const response = await axios({
           url: `https://app.trackonperformance.com/api/user/logins`,
           method: 'GET',
           headers: {
               'Content-Type': 'application/json',
               'Authorization': 'Bearer <your token>'
           }
           
       })
       if (response.status === 200) {
           console.log("user got the logins")
                   const { data } = response
                   console.log({
                       "_id": data._id,
                       "loggedAt": data.loggedAt,
                       "userId": data.userId,
                       "platform": data.platform,
                       "browser": data.browser,
                       "location": data.location,
                       "ip": data.ip,
                }            
       }
   } )()

```


      1. Returns user authenticated

Returns the authenticated user information


Request example: ```typescript

   import axios from 'axios'
   ( async function () {
       const accountId = 1234
       const response = await axios({
           url: `https://app.trackonperformance.com/api/user`,
           method: 'GET',
           headers: {
               'Content-Type': 'application/json',
               'Authorization': 'Bearer <your token>'
           }
           
       })
       if (response.status === 200) {
           console.log("user got the auth")
                   const { data } = response
                   console.log({
                       "_id": data._id,
                       "role": data.role,
                       "payroll": data.payroll,
                       "workType": data.workType,
                       "clockPaused": data.clockPaused,
                       "jobDescription": data.jobDescription,
                       "user":{
                           "_id": data._id,
                           "name": data.name,
                           "email": data.email,
                           "contact": data.contact,
                           "avatarUrl": data.avatarUrl,
                           "location": data.location,
                           "language": data.language,
                           "mainSkills": data.mainSkills,
                           "personalInterests": data.personalInterests,
                           "signature": data.signature,
                           "birthdate": data.birthdate,
                           "howToBegin": {
                               "firstTimeCharter": data.firstTimeCharter,
                               "firstTimeProject": data.firstTimeProject,
                               "firstTimeOBS": data.firstTimeOBS,
                           }
                           "isTopAdmin": data.isTopAdmin,
                       }
                       "account": {
                                "_id": data._id,
                                "name": data.name,
                                "creator": data.creator,
                                "creatorMetadata": {
                                       "phone": data.phone,
                                       "licenseCost": data.licenseCost,
                                       "licenses": data.licenses,
                                }
                                "metadata": data.metadata,
                                "description": data.description,
                                "status": data.status,
                                "payrollFrequency": data.payrollFrequency,
                                "admins": data.admins,
                                "schedule": {
                                       "dailyStartTime": data.dailyStartTime,
                                       "dailyEndTime": data.dailyEndTime,
                                       "businessDays": {
                                               "monday": data.monday,
                                               "tuesday": data.tuesday,
                                               "wednesday": data.wednesday,
                                               "thursday": data.thursday,
                                               "friday": data.friday,
                                               "saturday": data.saturday,
                                               "sunday": data.sunday,
                                       }
                                       "breaks": data.breaks,
                                }
                               "autoPlayEnabled": data.autoPlayEnabled,
                               "realTimeEditableBy": data.realTimeEditableBy,
                               "defaultProjectPreferences": data.defaultProjectPreferences,
                               "createdAt": data.createdAt,
                         }
                         "permissions": data.permissions,
                }            
       }
   } )()

```




      1. Update user

Update User information

```typescript

   import axios from 'axios'
   import moment from 'moment'
   ( async function () {
       const response = await axios({
           url: 'https://app.trackonperformance.com/api/user',
           method: 'PATCH',
           headers: {
               'Content-Type': 'application/json',
               'Authorization': 'Bearer <your token>'
           },
           data: {
               userId: 1234, //your user id
               property: 'birthdate',
               value: moment().format('YYYY-MM-DD')
           }
       })
       if (response.status === 200) {
           const { data } = response
           console.log("Returned the new updated data")
           console.log({
               "id": data.id,
               "name": data.name,
               "email": data.email,
               "password": data.password,
               "contact": data.contact,
               "avatarUrl": data.contact,
               "location": data.registerDate,
               "language": data.birthdate,
               "mainSkills": data.avatar,
               "location": data.location,
               "language": data.language,
               "mainSkills": data.mainSkills
               "personalInterests": data.personalInterests
               "lastLogin": data.lastLogin,
               "lastWorking": data.lastWorking,
               "lastAccount": data.lastAccount,
               "signature": data.signature,
               "birthdate": data.birthdate,
               "clockPaused": data.clockPaused,
               "coffeePauses": data.coffeePauses,
               "clockAbsences": data.clockAbsences,
               "clockBurnedHours": data.clockBurnedHours,
               "howToBegin": {
                   "firstTimeCharter": data.firstTimeCharter,
                   "firstTimeProject": data.firstTimeProject,
                   "firstTimeOBS": data.firstTimeOBS,
               }
           })
       }
   } )()

```


      1. Change user avatar

Change the authenticated user avatar image



Request example: ```typescript

   import axios from 'axios'
   ( async function () {
       const accountId = 1234
       const response = await axios({
           url: `https://app.trackonperformance.com/api/user/avatar`,
           method: 'POST',
           headers: {
               'Content-Type': 'application/json',
               'Authorization': 'Bearer <your token>'
           }
           
       })
       if (response.status === 200) {
           console.log("user got the auth")
                   const { data } = response
                   console.log({
                       "url": data.url,
                }            
       }
   } )()

```


      1. Clear user avatar

Clears the current user avatar image



Request example: ```typescript

   import axios from 'axios'
   ( async function () {
       const accountId = 1234
       const response = await axios({
           url: `https://app.trackonperformance.com/api/user/avatarClear`,
           method: 'POST',
           headers: {
               'Content-Type': 'application/json',
               'Authorization': 'Bearer <your token>'
           }
           
       })
       if (response.status === 200) {
           console.log("user got the auth")
                   const { data } = response
                   console.log({
                       "id": data.id,
                       "orgMemberId": data.orgMemberId,
                }            
       }
   } )()

```



      1. Change Auth Password

Changes the authenticated user password



Request example: ```typescript

   import axios from 'axios'
   ( async function () {
       const accountId = 1234
       const response = await axios({
           url: `https://app.trackonperformance.com/api/user/password`,
           method: 'POST',
           headers: {
               'Content-Type': 'application/json',
               'Authorization': 'Bearer <your token>'
           }
           
       })
       if (response.status === 201) {
           console.log("user got the auth")
                   const { data } = response
                   console.log({
                       "currentPassword": data.currentPassword,
                       "newPassword": data.newPassword,
                }            
       }
   } )()

```