Skip to content

Repository files navigation

API Documentation

Available endpoints, descriptions and usage

Endpoint Descriptions
.../db/accounts/register Register a new account into FarmCI directory
.../accounts/login Get an authentication token for a user profile account
.../accounts/reset/password Request User's password reset
.../accounts/reset/password/verify Confirms a request for Password Reset with OTP
.../accounts/user/forgot/username Forgotten User's username
.../db/users/farm/profile/get Get the Profile Details of a farmer
.../db/users/farm/profile/update Edit the Profile Details of a farmer
.../db/search?key Search FarmCI farm Directory using keywords

Documentation Descriptions

Registration API

Method: POST
Login endpoint: .../db/accounts/register

Register a new farmer profile. On successful registration, a unique username will be generated for the registered profile

parameters Descriptions
first_name: string First name of the farmer / User
last_name: string Last name of the farmer / User
password: string User's password
email: string Email of the farmer / User
phone: int User phone number
nin (Optional): string National identity Number(NIN) of the user. It must match the name on the user first_name and last_name.
profile_img (Optional): file User profile image
bvn (Optional): string Bank verification Number(BVN). Name must match first_name and last_name
gender: string male / female
street_address: string User street address
lga: string Residentent local government
crop_type: string Farmer's production
state: string Residential state of the user
country: string Resident country

Request Body

{
  
  "account": {
    "first_name": "EXAMPLE FIRST NAME",
    "last_name": "EXAMPLE LAST NAME",
    "email": "example@email.com",
    "phone": "1111111111",
    "password": "myPassword",
    "profile_img": "myProfileImage.png"
  },
  "nin": "14262728101202",
  "bvn": "12933390303",
  "crop_type": "maize",
  "gender": "male",
  "street_address": "12, PO BOX, Angeles Avenue",
  "state": "Lagos",
  "lga": "Alimosho Local Govt",
  "country": "Nigeria"
}

Success Response: status code: 200

{
  "success": true,
  "responseMessage": "success",
  "responseBody": {
    "login": {
      "username": "FSI_Generated Username",
      "password": "myPassword",
      "login_url": "https://api.farmci.com/accounts/login"
    },
    "message": "FSI_Generated Useraname has been registered",
    "info": "Proceed to login to get authentication token"
  }
}

Failed Response. status code: 400 : Used credentials

{
  "success": false,
  "responseMessage": "email used",
  "responseBody": {
    "errors": {
      "account": {
        "email": "A user with this email already exists",
        "phone": "A user with this phone already exists"
      }
    }
  }
  
}

Login API: Get Auth Token

Method: POST
Login endpoint: /accounts/login

Logs into a FarmCI account profile: Get the authentication token for authorizing subsequent requests using either the user's email or the generated username

Request body

{
  "username": "GENERATED USERNAME / USER'S EMAIL",
  "password": "ACCOUNT PASSWORD"
}

Success Response: status code: 200

{
    "success": true,
    "message": "login success",
    "token": "2589bba39f06cbc2db172c9430caf5aed40d003e"
}
Failed Response: Invalid / Unregistered Credential
status code: 403
{
    "success": false,
    "message": "Invalid username"
}

Reset Password API: Request to reset a user's password

Method: POST
Login endpoint: /accounts/reset/password

Request to reset a user's password. An OTP is sent to the user's immediately when the request is received and confirmed NB: OTP is time bound ( expires ) Request body

{
  "email": "User's email",
  "password": "NEW USER PASSWORD"
}

Success Response. status_code: 200

{
  "success": true,
  "responseMessage": "otp has been sent to user's email"
}

Failed Response. status_code: 200

{
  "success": false,
  "responseMessage": "invalid email"
}

Verify Reset Password API: Verify request to reset a user's password

Method: POST
Login endpoint: /accounts/reset/password

Verifies the OTP signed password token Request body

{
  "otp": "OTP_SENT_TO_USER'S MAIL",

}

Success Response. status_code: 200

{
  "success": true,
  "responseMessage": "password changed"
}

Failed Response. status_code: 200

{
  "success": false,
  "responseMessage": "invalid otp" || "expired otp"
}

Forgotten Username API

Request for a user's username if forgotten. The Username will be sent to the user's registered email address.

Method: POST
Endpoint: ../db/accounts/user/forgot/username
Authentication: Token Authentication

Header: {"Authorization": "Token < AUTHENTICATION TOKEN> "}

Success Response. status_code: 200

{
  "success": true,
  "responseMessage": "retrieval successful", 
  "responseBody": "An email containing your username and password has been to sent to the registered email address"
}

Get Farmer's Profile Details API

Method: POST
Authentication: Token header
Endpoint: ../db/users/farm/profile/get

Get the details of a farmer. Include the generated token in the request headers using the below format

{
    "Authorization": "Token < AUTHENTICATION TOKEN >",
    "Content-Type": "application/json"
 }

Success Response. status code: 200

{
  "success": true,
  "responseMessage": "profile retrieved successful",
  "responseBody": {
    "profile": {
      "username": "PROFILE USERNAME",
      "email": "PROFILE EMAIL ADDRESS",
      "first_name": "REGISTERED PROFILE FIRST NAME",
      "last_name": "REGISTERED PROFILE LAST NAME",
      "phone": "PROFILE PHONE NUMBER",
      "crop_type": "PROFILE CROP SPECIFICATION",
      "gender": "male / female",
      "street_address": "PROFILE REGISTERED STREET ADDRESS",
      "state": "PROFILE REGISTERED STATE",
      "lga": "REGISTERED PROFILE LOCAL GOVT",
      "country": "REGISTERED PROFILE COUNTRY"
    }
  }
}

Failed Response: Invalid token. status code: 401

{
  "details": "invalid token"
}

Failed Response: Empty Token header. status code: 401

{ "detail": "Authentication credentials were not provided" }

Update Farm Directory Profile API

``` Method: POST Authentication: Token header Endpoint: ../db/users/farm/profile/update ```

Get the details of a farmer. Include the generated token in the request headers using the below format

{
    "Authorization": "Token < AUTHENTICATION TOKEN >",
    "Content-Type": "application/json"
 }
  • Paramters are all registration fields except for username, email, bvn and nin
  • Parameters are optional but at least one of the expected parameters

Sample Request body

{
  "first_name": "New First Name",
  "last_name": "New last name",
  "phone": "New Phone Number",
  "gender": "female",
  "street_address": "New Address",
  "..."
  
}

Success Request Response: status_code: 200

{
  "success": true,
  "responseMessage": "profile update successful"
}

Failed Response: status_code: 400

{ 
  "success": false,
  "responseMessage": "profile update failed",
  "responseBody": {
    "errors": "empty edit params"
  }
}

Method: GET
Endpoint: ../db/search/?key

Search our farm directory database using keywords. This search focuses on farmers phone, number, state and crop type. The key could be a state name, crop type name (e.g. maize, cassava, tomatoes) or a phone number prefix.

Success Response. status code: 200

{
  "success": true,
  "responseMessage": "success",
  "responseBody": {
    "no_of_matches": 5000,
    "results": [
      {
        "first_name": "Farmer 1",
        "last_name": "Last name",
        "phone": "08123850878",
        "crop_type": "maize",
        "state": "Lagos",
        "profile_img": "https://api.farmci.com/media/images/user_profileImg.png"
      },
      
      ...,
      
      {
        "first_name": "Farmer 2000",
        "last_name": "Last name",
        "phone": "09128389922",
        "crop_type": "cocoa",
        "state": "Ogun",
        "profile_img": "https://api.farmci.com/media/images/user_profileImg.png"
      }
      
    ]
    
  }
}

No match Response: status code: 404

{
  "success": true,
  "responseMessage": "no match",
  "responseBody": "no match"
}

FarmCI Developers Team

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages