# Backend REST API

## JobHax Backend REST API

### Overview

JobHax is a platform that allows you to track your job applications, their statuses, take some notes about them and see some metrics about your job seeking process. The JobHax API provides functionality to developers to create users, add job applications and all the related endpoints to manage them. All of the API endpoints work with JSON bodies and responses.

### Postman Collection

You can explore all the endpoints of the JobHax API and their usage using [this](https://www.getpostman.com/collections/2bb6572a9df9802168a8) [Postman](https://www.getpostman.com/) collection.

### Authentication

The JobHax API uses Django framework's OAuth system. In order to get an access\_token to access the endpoints, you'll need to have a JobHax client\_id and a JobHax client\_secret. You can get an access\_token either using email\&password or using a third party access token like (Google access token, LinkedIn access token etc.)

#### How to generate Google access\_token for test purposes:

For testing purposes Google's playground system can be used for generating dummy access tokens to use on JobHax API.

You will need to grant following permissions:

* <https://www.googleapis.com/auth/userinfo.email>
* <https://www.googleapis.com/auth/userinfo.profile>
* <https://www.googleapis.com/auth/gmail.readonly>

To generate a Google access token, please use this [link](https://developers.google.com/oauthplayground/)

### Get an access\_token with using 3rd party provider

#### Request

```
POST https://backend.jobhax.com/api/users/auth_social_user
```

Authenticates the user and returns JobHax access\_token and refresh\_token related datas.

#### Request Body

```javascript
{
   "client_id": "<jobhax-client-id>",
   "client_secret": "<jobhax-client-secret>",
   "provider": "google-oauth2 or linkedin-oauth2",
   "token": "access_token-from-the-3rd-party-provider"
}
```

#### Response

```javascript
{
   "success": true,
    "error_code": 0,
    "error_message": "",
    "data": {
        "access_token": "uoIWl9mk6Uobs4M9r4H8NdBjIDyZK7",
        "expires_in": 36000,
        "token_type": "Bearer",
        "scope": "read write",
        "refresh_token": "4b0XdB9DGtTbHnYI15SkXL9WOUYZ21"
    }  
}
```

### Get an access\_token with using email\&password

#### Request

```
POST https://backend.jobhax.com/api/users/login
```

Authenticates the user and returns JobHax access\_token and refresh\_token related datas.

#### Request Body

```javascript
{
    "client_id": "<jobhax-client-id>",
    "client_secret": "<jobhax-client-secret>",
    "username": "joesmith",
    "password": "123456"
}
```

#### Response

```javascript
{
   "success": true,
    "error_code": 0,
    "error_message": "",
    "data": {
        "access_token": "uoIWl9mk6Uobs4M9r4H8NdBjIDyZK7",
        "expires_in": 36000,
        "token_type": "Bearer",
        "scope": "read write",
        "refresh_token": "4b0XdB9DGtTbHnYI15SkXL9WOUYZ21"
    }  
}
```

## API ENDPOINTS

### USER RELATED API ENDPOINTS

#### Request

```
POST https://backend.jobhax.com/api/users/register
```

Registers a new user with using the details provided in the body

#### Request Body

```javascript
{
    "first_name": "Joe",
    "last_name": "Smith",
    "username": "joesmith",
    "email": "joesmith@joe.com",
    "password": "123456",
    "password2": "123456"
}
```

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": null
}
```

#### Request

```
POST https://backend.jobhax.com/api/users/logout
```

To logout the current user

#### Request Body

```javascript
{
   "client_id": "<jobhax-client-id>",
   "client_secret": "<jobhax-client-secret>",
   "token": "current-jobhax-access-token"
}
```

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": null
}
```

#### Request

```
POST https://backend.jobhax.com/api/users/refresh_token
```

To refresh the JobHax access\_token if its expired.

#### Request Body

```javascript
{
    "client_id": "<jobhax-client-id>",
    "client_secret": "<jobhax-client-secret>",
    "refresh_token": "vSmJDUilg7RIjLXtiTIzoBwvTDN0UN"
}
```

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": {
        "access_token": "RYQidDFQ6w6BQHLkR4CKrKCbUOfcmG",
        "expires_in": 36000,
        "token_type": "Bearer",
        "scope": "read write",
        "refresh_token": "lHc5JiB9SohPjImcSB8aIRF9QNdK77"
    }
}
```

#### Request

```
POST https://backend.jobhax.com/api/users/update_gmail_token
```

To refresh user's GMAIL token. (In such case; user's gmail token refreshed or mail\_read permission granted after login)

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Request Body

```javascript
{
    "token": "access_token-from-the-3rd-party-provider"
}
```

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": null
}
```

#### Request

```
GET https://backend.jobhax.com/api/users/get_linkedin_profile
```

To get user's linkedinIn basic profile if the user logged in with their linkedIn profile.

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Response

```javascript
{
  "success": true,
  "error_code": 0,
  "error_message": "",
  "data": {
    "firstName": {
      "localized": {
        "en_US": "Bob"
      },
      "preferredLocale": {
        "country": "US",
        "language": "en"
      }
    },
    "localizedFirstName": "Bob",
    "headline": {
      "localized": {
        "en_US": "API Enthusiast at LinkedIn"
      },
      "preferredLocale": {
        "country": "US",
        "language": "en"
      }
    },
    "localizedHeadline": "API Enthusiast at LinkedIn",
    "vanityName": "bsmith",
    "id": "yrZCpj2Z12",
    "lastName": {
      "localized": {
        "en_US": "Smith"
      },
      "preferredLocale": {
        "country": "US",
        "language": "en"
      }
    },
    "localizedLastName": "Smith",
    "profilePicture": {
      "displayImage": "urn:li:digitalmediaAsset:C4D00AAAAbBCDEFGhiJ"
    }
  }
}
```

#### Request

```
GET https://backend.jobhax.com/api/users/sync_user_emails
```

To sync user job application emails to JobHax DB if the user logged in with their google account

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": null
}
```

#### Request

```
GET https://backend.jobhax.com/api/users/get_user_google_mails
```

To get all the emails that read from user's inbox which are related with the job applications

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": [
        {
            "subject": "You applied for Android Developer at Genuent",
            "body": "<html><body>HTML content</body></html>",
            "date": "2018-11-14 06:08:19+00:00"
        }
    ]
}
```

### JOB APPLICATION RELATED API ENDPOINTS

#### Request

```
GET https://backend.jobhax.com/api/jobapps/get_jobapps
```

To get user's all job applications from JobHax DB.

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": [
        {
            "id": 31,
            "applicationStatus": {
                "id": 1,
                "value": "Applied"
            },
            "jobTitle": "🤖 Lead Android Engineer",
            "company": "OpenPhone ",
            "companyLogo": "/static/images/errorcvlogobright.png",
            "applyDate": "2019-01-23T14:18:12Z",
            "msgId": "1687ccad52768659",
            "source": "Hired.com",
            "user": 7
        },
        {
            "id": 21,
            "applicationStatus": {
                "id": 1,
                "value": "Applied"
            },
            "jobTitle": "Android Intern (Summer 2019)",
            "company": "Mozilla",
            "companyLogo": "https://media.licdn.com/dms/image/C4E0BAQGHz8JwrMTQ0A/company-logo_100_100/0?e=2159024400&v=beta&t=klSj-Z-6bTQr-5Tfl4HWe8JwjnboGzei8ncYUMs56Pc",
            "applyDate": "2018-11-14T06:08:19Z",
            "msgId": "16710d5be4d0ae7f",
            "source": "LinkedIn",
            "user": 7
        }
    ]
}
```

#### Request

```
GET https://backend.jobhax.com/api/jobapps/get_statuses
```

To get all the job application statuses from JobHax DB.

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": [
        {
            "id": 1,
            "value": "Applied"
        }
    ]
}
```

#### Request

```
GET https://backend.jobhax.com/api/jobapps/get_status_history
```

To get status change history of a specific job application

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### URI Parameters

| Key        | Value      | Required |
| ---------- | ---------- | -------- |
| jobapp\_id | job-app-id | Y        |

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": [
        {
            "applicationStatus": {
                "id": 1,
                "value": "Applied"
            },
            "update_date": "2019-02-10T10:38:36.202351Z"
        }
    ]
}
```

#### Request

```
POST https://backend.jobhax.com/api/jobapps/add_jobapp
```

To add a new Job Application.

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Request Body

```javascript
{
    "job_title": "job_title",
    "status_id": "1",
    "company": "company_test",
    "application_date": "2019-01-31",
    "source": "Vettery"
}
```

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": null
}
```

#### Request

```
POST https://backend.jobhax.com/api/jobapps/update_jobapp
```

To update a Job Application's status or rejection status. 'status\_id' and 'rejected' parameters are optional but at least one of them should be sent.

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Request Body

```javascript
{
    "jobapp_id": "576",
    "status_id": "1",
    "rejected": true
}
```

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": null
}
```

#### Request

```
POST https://backend.jobhax.com/api/jobapps/delete_jobapp
```

To delete a specific Job Application.

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Request Body

```javascript
{
    "jobapp_id": "221"
}
```

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": null
}
```

#### Request

```
GET https://backend.jobhax.com/api/jobapps/get_jobapp_detail
```

To get details of a Job Application

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### URI Parameters

| Key        | Value      | Required |
| ---------- | ---------- | -------- |
| jobapp\_id | job-app-id | Y        |

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": {
        "posterInformation": {},
        "decoratedJobPosting": {},
        "topCardV2": {}
    }
}
```

#### Request

```
POST https://backend.jobhax.com/api/jobapps/add_jobapp_note
```

To add a note to a specific Job Application

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Request Body

```javascript
{
    "jobapp_id": 269,
    "description": "test note"
}
```

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": {
        "id": 1,
        "description": "test note",
        "created_date": "2019-03-18T03:26:27.780072Z",
        "update_date": null
    }
}
```

#### Request

```
POST https://backend.jobhax.com/api/jobapps/update_jobapp_note
```

To update a note of a specific Job Application

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Request Body

```javascript
{
    "jobapp_note_id": 1,
    "description": "test note update"
}
```

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": null
}
```

#### Request

```
POST https://backend.jobhax.com/api/jobapps/delete_jobapp_note
```

To delete a note from a Job Application

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Request Body

```javascript
{
    "jobapp_note_id": 1
}
```

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": null
}
```

#### Request

```
GET https://backend.jobhax.com/api/jobapps/get_jobapp_notes
```

To get details of a Job Application

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### URI Parameters

| Key        | Value      | Required |
| ---------- | ---------- | -------- |
| jobapp\_id | job-app-id | Y        |

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": [
        {
            "id": 2,
            "description": "test note update",
            "created_date": "2019-03-18T03:40:04.770901Z",
            "update_date": "2019-03-18T03:40:15.324041Z"
        },
        {
            "id": 3,
            "description": "test note 2",
            "created_date": "2019-03-18T03:42:21.334071Z",
            "update_date": null
        }
    ]
}
```

### METRICS RELATED API ENDPOINTS

#### Request

```
GET https://backend.jobhax.com/api/metrics/get_total_application_count
```

To get count of user's job application

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": {
        "count": 28
    }
}
```

#### Request

```
GET https://backend.jobhax.com/api/metrics/get_application_count_by_month
```

To get count of user's job application by month

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": [
        [
            {
                "source": "Hired.com",
                "data": [
                    0,
                    0,
                    0,
                    0,
                    0,
                    2,
                    2,
                    0,
                    0,
                    2,
                    1,
                    0
                ]
            },
            {
                "source": "LinkedIn",
                "data": [
                    0,
                    0,
                    0,
                    0,
                    2,
                    1,
                    0,
                    3,
                    0,
                    0,
                    5,
                    1
                ]
            },
            {
                "source": "Indeed",
                "data": [
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    8,
                    6,
                    7,
                    2
                ]
            },
            {
                "source": "Vettery",
                "data": [
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    9,
                    1,
                    1
                ]
            },
            {
                "source": "Others",
                "data": [
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0
                ]
            }
        ],
        [
            "April",
            "May",
            "June",
            "July",
            "August",
            "September",
            "October",
            "November",
            "December",
            "January",
            "February",
            "March"
        ]
    ]
}
```

#### Request

```
GET https://backend.jobhax.com/api/metrics/get_application_count_by_month_with_total
```

To get count of user's job application by month with total

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": [
        [
            {
                "source": "Hired.com",
                "data": [
                    0,
                    0,
                    0,
                    0,
                    0,
                    2,
                    2,
                    0,
                    0,
                    2,
                    1,
                    0
                ]
            },
            {
                "source": "LinkedIn",
                "data": [
                    0,
                    0,
                    0,
                    0,
                    2,
                    1,
                    0,
                    3,
                    0,
                    0,
                    5,
                    1
                ]
            },
            {
                "source": "Indeed",
                "data": [
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    8,
                    6,
                    7,
                    2
                ]
            },
            {
                "source": "Vettery",
                "data": [
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    9,
                    1,
                    1
                ]
            },
            {
                "source": "Others",
                "data": [
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0
                ]
            },
            {
                "source": "Total",
                "data": [
                    0,
                    0,
                    0,
                    0,
                    2,
                    3,
                    2,
                    3,
                    8,
                    17,
                    14,
                    4
                ]
            }
        ],
        [
            "April",
            "May",
            "June",
            "July",
            "August",
            "September",
            "October",
            "November",
            "December",
            "January",
            "February",
            "March"
        ]
    ]
}
```

#### Request

```
GET https://backend.jobhax.com/api/metrics/get_count_by_statuses
```

To get count of user's job application by its statuses

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": [
        {
            "name": "Applied",
            "value": 27
        },
        {
            "name": "Interviewing",
            "value": 1
        }
    ]
}
```

#### Request

```
GET https://backend.jobhax.com/api/metrics/get_word_count
```

To get unique words in job applications

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": [
        {
            "word": "ERG, Inc.",
            "value": 1
        },
        {
            "word": "BrainyPro",
            "value": 1
        },
        {
            "word": "Amazon ",
            "value": 1
        },
        {
            "word": "KgTiger",
            "value": 1
        },
        {
            "word": "Carvana",
            "value": 1
        }
    ]
}
```

#### Request

```
GET https://backend.jobhax.com/api/metrics/get_count_by_jobtitle_and_statuses
```

To get job application count by job title and status

#### Request Headers

| Key           | Value                      | Required |
| ------------- | -------------------------- | -------- |
| Authorization | Bearer jobhax-access-token | Y        |

#### Response

```javascript
{
    "success": true,
    "error_code": 0,
    "error_message": "",
    "data": {
        "jobs": [
            "Android Engineer",
            "Android Developer",
            "Android Application Developer",
            "Mobile Developer (iOS and Android)",
            "Software Engineer",
            "Senior Android Developer",
            "Android Intern (Summer 2019)",
            "Mobile Software Engineer",
            "Urgent: Android Developer",
            "Android",
            "🤖 Lead Android Engineer",
            "Android Software Engineer, Mobile Services",
            "Software Engineer Intern",
            "Android Application Developer (5007)",
            "Software Engineer - Android"
        ],
        "statuses": [
            "Interviewing",
            "Applied"
        ],
        "data": [
            {
                "name": "Interviewing",
                "data": [
                    0,
                    0,
                    0,
                    0,
                    1,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0
                ]
            },
            {
                "name": "Applied",
                "data": [
                    6,
                    8,
                    2,
                    1,
                    0,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1
                ]
            }
        ]
}
```

### ERROR CODES

| Error Code | Description                                            | Explanation |
| ---------- | ------------------------------------------------------ | ----------- |
| 0          | -                                                      | -           |
| 1          | Invalid credentials                                    | -           |
| 2          | User profile not found.                                | -           |
| 3          | Error occured while updating the google token.         | -           |
| 4          | Google token has expired. Please refresh Google token. | -           |
| 5          | Couldnt logout user...                                 | -           |
| 6          | Could not login... Please check your credentials...    | -           |
| 7          | Passwords do not match                                 | -           |
| 8          | That username is taken                                 | -           |
| 9          | That email is being used                               | -           |
| 10         | Invalid parameters...                                  | -           |
| 11         | Record not found...                                    | -           |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.jobhax.com/3.backend_api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
