Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

API

notebook/API.livemd

API

Variables

base_url = IO.gets("Base URL") |> String.trim()

Users

GET /v1/me

Used to fetch the current user’s profile details

Requires a valid access_token in the header

200 OK

headers = [access_token: "77564df8-7823-45b2-b9ef-38dac927ddfd"]

LivemanApi.get(base_url, "/v1/me", %{}, headers)

Surveys

GET /v1/surveys

Used to fetch all the available surveys.

Returns a 200 OK response

200 OK

LivemanApi.get(base_url, "/v1/surveys")

Supports pagination by passing the page number and page size as params

LivemanApi.get(base_url, "/v1/surveys", %{page: 2, page_size: 8})

POST /v1/responses

Used to create an answer to a particular survey

Requires a valid access_token in the header

Returns a 201 Created response

201 Created - Valid Params

headers = [access_token: "77564df8-7823-45b2-b9ef-38dac927ddfd"]

body = %{
  survey_id: "d5de6a8f8f5f1cfe51bc",
  questions: [
    %{
      id: "940d229e4cd87cd1e202",
      answers: [
        %{
          id: "037574cb93d16800eecd"
        }
      ]
    }
  ]
}

LivemanApi.post(base_url, "/v1/responses", body, headers)

It will return a 422 Unprocessable Entity response if a survey or question is invalid

422 Unprocessable Entity - Invalid Survey

header = [access_token: "77564df8-7823-45b2-b9ef-38dac927ddfd"]

body = %{
  survey_id: "invalid",
  questions: [
    %{
      id: "940d229e4cd87cd1e202",
      answers: [
        %{
          id: "037574cb93d16800eecd"
        }
      ]
    }
  ]
}

LivemanApi.post(base_url, "/v1/responses", body, headers)

422 Unprocessable Entity - Invalid Question

header = [access_token: "77564df8-7823-45b2-b9ef-38dac927ddfd"]

body = %{
  survey_id: "d5de6a8f8f5f1cfe51bc",
  questions: [
    %{
      id: "invalid",
      answers: [
        %{
          id: "037574cb93d16800eecd"
        }
      ]
    }
  ]
}

LivemanApi.post(base_url, "/v1/responses", body, headers)

Surveys

GET /v1/surveys

Used to fetch all the available surveys.

Returns a 200 OK response

200 OK

LivemanApi.get(base_url, "/v1/surveys")

Supports pagination by passing the page number and page size as params

200 OK

LivemanApi.get(base_url, "/v1/surveys", %{page: 2, page_size: 8})

Registration flow

For a user to register, they first will need to submit their email and password. Upon submitting their email and password, an OTP will be sent to their email which they can use to verify their account before using the rest of the application

POST /users/signup

Used to submit the user’s credientials, and if successful, will return a message about the confirmation email being sent.

This endpoint will raise a 422 Unprocessable Entity error if their email is already taken.

Returns a 200 OK response

200 OK

body = %{
  "email" => "johndoe@email.com",
  "password" => "secret"
}

LivemanApi.post(base_url, "/v1/users/signup", body)

422 Unprocessable Entity - Invalid Email and Password

body = %{
  "email" => "johndoe",
  "password" => "qwe"
}

LivemanApi.post(base_url, "/v1/users/signup", body)

422 Unprocessable Entity - Black Email and Password

body = %{
  "email" => "",
  "password" => ""
}

LivemanApi.post(base_url, "/v1/users/signup", body)

After user registration they will need to submit the OTP they received to the verification endpoint.

POST /users/verify

This endpoint will return a 200 OK response after successfully verifying the user.

200 OK

body = %{
  "otp" => "621951"
}

LivemanApi.post(base_url, "/v1/users/verify", body)

A 422 Unprocessable Entity error will be raised given an invalid OTP

422 Unprocessable Entity - Blank OTP

body = %{
  "otp" => ""
}

LivemanApi.post(base_url, "/v1/users/verify", body)