PHP snippet example call to HarvestAPI

_config.yml

I modified some PHP code I found on StackOverflow to make a call to HarvestAPI. This is in hopes that it will make things easier for developers to see how to make calls to this rest API that provides important Jamaican agriculture information to a variety of important stakeholders along the agriculture value chain.

Using HarvestAPI one could for instance find the latest prices for a particular crop such as Okra.

I created this gist on github so hopefully others can learn from it. Please see further notes below.

OK, so the CallAPI function can be included in your own code. Persons will need to register for a HarvestAPI account otherwise an authentication error will be returned:

{"detail": "Invalid username/password"}

To register for an API key, please signup and make a note of your username and password. You will have to modify the code with this information.

//search for farmers named 'johnson' and order by first name
$farmers = CallAPI('GET', 'harvestdata.herokuapp.com/farmers/', array('ordering'=>'first_name', 'search'=>'johnson'));

Another note is I had to install curl before the code would run properly:

//had to install php curl
sudo apt-get install php5-curl
sudo service apache2 restart
//It's possible you'll need to install more:
sudo apt-get install curl libcurl3 libcurl3-dev;
Written on October 7, 2014