Introduction

The Krishitantra API allows the enterprises to
remotely create a farmer and generate a request for running the soil
test for the farmer. Thus, the APIs would allow you to:

  • Create a farmer
  • Get information of the service centers
  • Create a sample test for the farmer
  • Get the results of the soil sample test

Krishitantra APIs workflow

Creating a test request and obtaining the test results through the Krishitantra APIs would first require the enterprises to login and authenticate against the Krishitantra server. Once the authentication token is received by the enterprises,this has to be used for subsequent requests for creation of a farmer,creation of a test order and for getting the results for the test order. Conceptually, the sequence diagram for the following would be as follows:

Service Endpoints

A service endpoint is a base URL that specifies the network address of an API service. The Krishitantra API, for the case of testing has the following service endpoint:


https://soil-api-staging.krishitantra.com/graphql

Methods available

Methods
Description
login
POST https://soil-api-staging.krishitantra.com/graphql LoginMutation Allows the enterprise to login to their account
createFarmer
POST https://soil-api-staging.krishitantra.com/graphql CreateFarmerMutation
createExternalTest
POST https://soil-api-staging.krishitantra.com/graphql CreateExternalTestMutation Creates a test for a farmer and this can be assigned to any of the test centers of Krishitantra
getExternalTestByFarmer
POST https://soil-api-staging.krishitantra.com/graphql getExternalTestsByFarmer Gets the test results for the farmer
resetPassword
POST https://soil-api-staging.krishitantra.com/graphql ResetPasswordMutation The mutation allows for a reset of password for the enterprises account
logout
POST https://soil-api-staging.krishitantra.com/graphql logoutMutation Ends the connection that was established between the third party application and the Krishitantra API
getUsers
POST https://soil-api-staging.krishitantra.com/graphql getUsers Gets the details of the farmers that were added by the enterprise, either through a phone number or through the username
Login

The login mutation allows an enterprise to connect to the Krishitantra API services. 

The  return object would be an authentication token that would have to be provided for any further communication with the Krishitantra API service. 

Request body 

The request body contains data with the following structure:

{
"loginOrganization ": String,
"loginUsername": String,
"loginPassword": String
}

Response body

The response body contains data with the following structure:

JSON Representation

{
  "data":                                                                                                            {
    "login":String
   }
}

Fields
Fields
JSON type Description
loginOrganization
String The organization name that was provided during thetime of registration
loginUsername
String The user name that was shared to the enterprise at the time of registration
loginPassword
String The password that was set by the organization
login
String Output only. This will be the authentication token that will have to be sent for any further communication with the
Krishitantra API service
createFarmer

The createFarmer mutation would allow the enterprises to create a farmer instance in Krishitantra by giving basic details as described in the request body section.

The return object would be the farmer instance created successfully.

Request Body

The request body contains data with the following structure:

JSON Representation

{
 "name": String,
 "address": String,
 "phone": String,
 "latitude":Double,
 "longitude":Double,
 "email": String,
 "username":String
}

Response Body

The response body contains data with the following structure:

JSON  Representation

{
  "data":
 {

   "createFarmer": {
       "id": String,
      "latitude": Double,
      "longitude": Double,
      "email":String
      "name": String,
      "address": String,
      "phone": String,
      "username": String,
      "createdAt": DateTime,
      "updatedAt": DateTime
     }
  }
}

Fields

Fields JSON Type Description
Id
String Output only. The unique ID that is associated with this instance of the farmer
Latitude
Double
The latitude of the farmer’s address
Longitude
Double
The longitude of the farmer’s address
Name
String
Name of the farmer
Address
String
Address of the farmer
Phone
String
The mobile number of the farmer.Please note that the country code has to be
prefixed with the phone number
Email
String
The email id of the farmer Please note that this has to be unique for
individual farmers created by the enterprise
Username
String
The username that is given to the farmer.
CreatedAt
DateTime
Output only. The time at which the farmer instance
is created by the enterprise
UpdatedAt
DateTime
Output only. The latest instance when this farmer
instance was updated by the enterprise
createExternalTest

The createExternalTest would enable the enterprise
to generate a test order for a farmer.

The return object would have the ID for the test order created.

Request Body

The request body contains data with the following structure:

JSON Representation

{
 "expiresAt": DateTime,
 "latitude": Double,
 "longitude": Double,
 "area":Double,
 "cropType": [String],
 "soilType": String,
 "soilDensity": Double,
 "surveyNo": String,
 "sampleDate": DateTime,
 "farmers": String,
 "avgYield": Double
}

Response Body

The response body contains data with the following structure:

JSON Representation

{
 "data":
   {

  "createExternalTest": {
     "id":String,
     "computedID": String,
     "status": String
    }
  }
}

Fields
Fields JSON Type Description
expiresAt DateTime The time at which the test order will
automatically expire if no test is associated with this test order
Latitude
Double
The latitude of the farmer’s  plot from which the soil is collected
Longitude
Double
The longitude of the farmer’s  plot from which the soil is collected
Area
Double
The area of the farmer’s plot (this has to be in hectares)
cropType [String]
An array of strings which collects the type of crops grown on this plot
soilType
String
The soil type for the farmer’s plot
soilDensity
Double
The soil density of the farmer’s plot
surveyNo
String
The survey number of the farmer’s plo
sampleDate
DateTime
Output only. The time at which the farmer instance is created by the enterprise
Farmers
String
The unique ID of the farmer for which the test is created
avgYield
Double
The average yield that was obtained from the plot.
Must be in kg/hec tares
Id
String Output only. The unique ID that is associated with the test order that created
computedID
String
Output only. The ID that will have to be shared
with the test centers for getting the soil test completed.
status
String
Output only. Indicates the status of the test order. Can be “pending” or “completed”
getExternalTestByFarmer

The getexternalTestByFarmer mutation would return all the tests which have been conducted for the farmer specified.

The return object would have an array of test results as described in the response body section.

Request Body

The request body contains data with the following structure:

JSON Representation

{
"getExternalTestsByFarmerFarmer": String
}

Response Body

The response body contains data with the following structure:

JSON Representation

{
  [
    Id:String
    test
      {
        html:String
        results: [Double]
      }
    createdAt:DateTime
    updatedAt: DateTime
    status:String
    expiresAt: DateTime
    latitude:Double
    area:Double
    cropType:[String]
    soilType:String
    soilDensity: Double
    surveyNo:String
    sampleDate: DateTime
    longitude: Double
   ]
}

Fields
Fields JSON Type Description
getExternalTestsByFarmerFarmer
String The username of the farmer for which the test
results have to be retrieved
id String Output only. The unique ID of the test result
test Object Output only. Would have 2 fields in it as described below
Html String The HTML layout on which the test results can be imposed
Results
[Double]
An array of double with the key of the array being
the soil parameter name and the value indicating the results for this parameter
expiresAt DateTime The time at which the test order will
automatically expire if no test is associated with this test order
Latitude
Double
The latitude of the farmer’s  plot from which the soil is collected
Longitude
Double
The longitude of the farmer’s  plot from which the soil is collected
Area
Double
The area of the farmer’s plot (this has to be in hectares)
cropType [String]
An array of strings which collects the type of crops grown on this plot
soilType
String
The soil type for the farmer’s plot
soilDensity
Double
The soil density of the farmer’s plot
surveyNo
String
The survey number of the farmer’s plo
sampleDate
DateTime
Output only. The date at which the soil sample was collected from the farmer’s plot
CreatedAt
DateTime
Output only. The date at which the test result was generated
UpdatedAt
DateTime
Output only. The date at which the test results was modified (if applicable)
Farmers
String
The unique ID of the farmer for which the test is created
computedID
String
Output only. The ID that will have to be shared
with the test centers for getting the soil test completed.
status
String
Output only. Indicates the status of the test order. Can be “pending” or “completed”
resetPassword

The resetPassword mutation allows the enterprise to reset the password for the enterprise’s account.

The return object would only have a Boolean value indicating whether the reset password email has been successfully sent to the email ID mentioned in this mutation.

Request Body

The request body contains data with the following structure:

JSON Representation

{
  "sendResetPasswordEmailOrganization":String,
  "sendResetPasswordEmailUsername":String,
  "sendResetPasswordEmailEmail": String
}

Response Body

The response body contains data with the following structure:

JSON Representation

{
 "data":
   {
     "sendResetPasswordEmail": boolean
   }
}

Fields
Fields JSON type Description
sendResetPasswordEmailOrganization
String The name of the enterprise for which the reset
sendResetPasswordEmailUsername
String The username of the enterprise for which the
password has to be reset
sendResetPasswordEmailEmail
String
The email ID for which the reset password link has
to be sent
sendResetPasswordEmail
Boolean
Output only. The value of “true” indicates that a reset password mail has been successfully sent to the email ID
mentioned in the request body.

getUsers

The getUsers mutation allows the enterprise to fetch the details of the farmer by either specifying the farmer’s username or the phone number.

The return object would have the instance of the farmer object which matches the username or the phone number specified in the requestbody.

Request Body

The request body contains data with the following structure:

JSON Representation

Request Body

{
 "getUsersOrganization": String,
 "getUsersUsername": String,
 "getUsersPhone": String
}

Response Body

The response body contains data with the following structure:

JSON Representation

{
  "data":
    {
    "getUsers": [
        {
         "id": String,
         "latitude": Double,
         "longitude": Double,
         "name": String,
         "address": String,
         "phone": String,
         "email": String,
         "username": String,
         "createdAt": DateTime,
         "updatedAt": DateTime
        }
       ]
    }
}

Fields
Fields JSON type Description
getUsersOrganization
String The name of the enterprise must be specified in this field
getUsersUsername
String The username of the farmer for which the information has to be returned
getUsersPhone
String The phone number of the farmer for which the
information has to be returned. Please note that the country code has to be prefixed for this field.
id String Output only. The unique ID that is associated with this instance of the farmer.
Latitude
Double
Output only. The latitude of the address of the farmer
Longitude
Double Output only. The longitude of the address of the farmer
Name String Output only. Name of the farmer
Address
String Output only. Address of the farmer
Phone String Output only. The mobile number of the farmer.
Please note that the phone number will have the country code prefixed with it.
Email String Output only. The email ID of the farmer
Username String Output only. The username that is given to the farmer. Please note that this has to be unique for individual farmers
created by the enterprise
CreatedAt DateTime Output only. The time at which the farmer instance is created by the enterprise
UpdatedAt DateTime Output only. The latest instance when this farmer instance was updated by the enterprise
Logout

This mutation allows the enterprise to terminate  he connection established between the enterprise’s application and the Krishitantra server.

The return object would only have a Boolean value indicating whether the logout mutation was successful or not.

Request Body

The request body contains data with the following structure:

JSON Representation


  Logout
}

Response Body

The response body contains data with the following structure:

JSON Representation

{
  "data":
    {
     "logout": boolean
    }   
}

Fields
Field JSON type Column 2
logout
Boolean
Output only. A value of true indicates successful termination of the connection.