Skip to content

AgroAPI Documentation

Jose Ricardo de Oliveira Damico edited this page Mar 2, 2018 · 53 revisions

SciCropEntity Object:

In order to get the full experience of all resources from AgroAPI, a SciCrop® Product, you need to know how our descriptive data modeling works. All of our systems are based on a main object called: SciCropEntity.

Here you can find an object example:

{"authEntity":{},"payloadEntity":{},"actionEntityLst":[],"responseEntity":
 {"id":-1,"epochTime":1498487542148,"returnId":0,"returnMsg":"Success."}}

Note that it contains 3 other objects and one list.

  • authEntity: This object is used to store all the extra information related to system user authentication like IP, session ID, etc.

  • payloadEntity: This object contains only lists of objects like farmEntityLst, cropEntityLst, personEntityLst, etc. It is used to transfer information in and out of our API.

  • responseEntity: This object is used to set the responses of each action on our API. Success, Expired Session, Database Import Error, etc are examples of returnMsg. Each return message has a specific returnId.

  • actionEntityLst: This is a list of ActionEntity objects. It is used to request a specific process execution by the API scheduler.

Online Support:

For further information, join us at our slack channels: https://join.slack.com/t/agroapi/shared_invite/MjE1Njg3ODI3NjM1LTE1MDA2MDgzMzYtN2ViYzJhZjgwZA

Basic Tests:

In order to access SciCrop API we will show some examples:

First, we will demonstrate a GET call in our API, through a command line interface, using curl.

  • How to install Curl under Debian or Ubuntu Linux distros:

In a terminal window, issue the following command: sudo apt-get install curl

  • How to install Curl under Windows:

Install Chocolatey Package Manager. In a administrative command line window, issue the following command:

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

After installing Chocolatey package manager, use it to install Curl:

choco install curl

With Curl up and running you're now ready to demonstrate a GET call. As a normal user type the following:

$ curl -k --user YOUREMAIL:YOURPASSWORD https://engine.scicrop.com/scicrop-engine-web/api/v1/status/my

The result must be something like this:

{
  "authEntity": {},
  "payloadEntity": {
    "restLst": [
      {
        "restName": "/station/scicrop",
        "restDesc": "Get SciCrop station data and send through API"
      },
      {
        "restName": "/status/my",
        "restDesc": "Available rests for a given account"
      }
    ]
  },
  "actionEntityLst": [],
  "responseEntity": {
    "epochTime": 1499138600682,
    "returnId": 0,
    "returnMsg": "Success."
  }
}

Note that the JSON response of the GET call, shows a restLst array, with the rest services available to you. Then we can go to our second example, a POST call, passing a payload.

First of all, download and install Advanced REST Client, a Google Chrome Extension.

Advanced Rest Client

Launch the app, and at the top of the page, you will have to update the Request URL. Please insert the following URL: https://engine.scicrop.com/scicrop-engine-web/api/v1/station/scicrop

Select the method Post and then select Headers form, as shown below:

At the field Header name, start typing Authorization, it'll auto complete the form:

On the field, Header value, click on the pencil icon and the app will prompt you to enter your email and password:

Enter the email you registered on SciCrop API and then hit the button select, as below:

Click on Raw Payload and paste the code below on the blank box. Please note that you should replace your@email.com by your login email. Also, Also, you should insert your API ID.

{"authEntity":{"userEntity":{"email":"your@email.com","api_id":"contactSciCropInOrderToGetYourAPIId"}},"payloadEntity":{},"actionEntityLst":[],"responseEntity":{}}

After that, click on data form and hit the button USE X-WWW-FORM-URLENCODED as shown below:

Then, hit the button send and you are supposed to get the response 200 ok as shown below:

Scroll down until you find the StationLst. There you will find the info regarding all available stations, as shown below:

stations available

In order to submit the weather forecast data into AgroApi you should already have been installed Advanced REST Client, a Google Chrome Extension as we explained previously.

Launch the app, and at the top of the page, you will have to update the Request URL. Please insert the following URL: https://engine.scicrop.com/scicrop-engine-web/api/v1/station/addSciCropWeatherForecast

Select the method Post and then select Headers form, as shown below:

At the field Header name, start typing Authorization, it'll auto complete the form:

On the field, Header value, click on the pencil icon and the app will prompt you to enter your email and password:

Enter the email you registered on SciCrop API and then hit the button select, as below:

Click on Raw Payload and paste the code with the Weather Forecast data on the blank box. Your code should have the following information Please note that you should replace your@email.com by your login email. Also, you should insert your API ID.

Please make sure you insert all the info to be inserted in our database on PayloadEntity. You can find an example below:

{
    "authEntity": {
        "userEntity": {
            "email": "MYEMAIL",
            "api_id": "MYAPIID"
        }
    },
    "payloadEntity": {
        "sciCropWeatherForecastEntityLst": [{
            "city": {
                "cityId": 8822
            },
            "loc": {},
            "forecastDate": "2017-07-28",
            "maxTemp": 30,
            "minTemp": 10,
            "millimeterRain": 10,
            "percentRain": 10,
            "weatherDescription": 'sun.with.clouds'
        }]
    },
    "actionEntityLst": [],
    "responseEntity": {}
}

After that, click on data form and hit the button USE X-WWW-FORM-URLENCODED as shown below:

Then, hit the button send and you are supposed to get the response 200 ok as shown below:

Scroll down until you find the sciCropWeatherForecastEntityLst. It is the data you just inserted on AgroApi as you can see below:

stations available

You can’t perform that action at this time.