Gardening Projects API

The Gardening Project

The ET Unity service considers a Gardening Project a canvas for all vegetation, irrigation zones, and landscape related information. Consider the Project as the site or address that contains all the plants and landscape details. After having created an account, the project would be the next step to create, as every environmental datapoint, from plants to weather to soil specifics, requires a Project to relate to. Although technically not a requirement, Projects typically refer to one physical location, and are recommended to be used as one location per project.

How to create a project

Creating a Project is really easy. All it takes is a simple HTTP call with an empty JSON object using the POST method to https://developer-api.etwater.com/api/v1/gardening/projects. As we’re going to send data to the server, we need to specify what kind of data we’re sending using the Content-Type HTTP header. In our case the content type should be application/json. As all calls should include your access token, make sure to replace $ACCESS_TOKEN in the below examples with your access token.

cURL request example

Here is how you’d make the call using cURL:

curl -XPOST -H'Authorization: Bearer $ACCESS_TOKEN' -H'Content-Type: application/json' 'https://developer-api.etwater.com/api/v1/gardening/projects' -d '{}'

Response example

And here is what you’d get back from the Unity API:

{
	"name": "Buena Vista Park,SF",
	"created_at": 1475067523039,
	"updated_at": 1475068440090,
	"version": 4,
	"postal_code": "94117",
	"location": {
		"type": "Point",
		"coordinates": [
			-122.4410896675,
			 37.768361565
		]
	},
	"id": "57ebbe830e8e3d000155552e"
}

The ID is the unique identifier for the Project. You’ll use this ID in al your calls related to this Project. The created_at and updated_at are both timestamps in the EPOCH with milliseconds format (milliseconds since January 1, 1970). The version number increments each time the project is updated. You can use this to track changes and keep projects in sync across multiple devices that are logged on simultaneously.

POSTMAN request and response example

If you’re using Postman, here is what that would look like. First make sure you enter your headers:

Then make your call and see the response:

How to update a project

Whenever you need to update the project you should use the PUT method and call https://developer-api.etwater.com/api/v1/gardening/projects/{projectId}. Where projectId is the ID of a project you’d like to update. Here too we need to specify what kind of data we’re sending using the Content-Type HTTP header application/json.

cURL request example

curl -XPUT -H'Authorization: Bearer $ACCESS_TOKEN' -H'Content-Type: application/json' 'https://developer-api.etwater.com/api/v1/gardening/projects/57ebbe830e8e3d000155552e' -d '{"name": "Buena Vista Park,SF"}'

Response example

{
	"name": "Buena Vista Park,SF",
	"created_at": 1475067523039,
	"updated_at": 1475068440090,
	"version": 4,
	"postal_code": "94117",
	"location": {
		"type": "Point",
		"coordinates": [
			-122.4410896675,
			37.768361565
		]
	},
	"id": "57ebbe830e8e3d000155552e"
}

When updating a project you should only pass the fields you want to change, and remember that not all of the field can be changed (for instance, the ID field can’t be changed in any entity available through the Unity API).

POSTMAN request and response example

Using POSTMAN, first set your headers:

And then send your request:

How to delete a project

To delete a project you should perform an HTTP call to https://developer-api.etwater.com/api/v1/gardening/projects/{projectId} using DELETE HTTP method, where projectId is the ID of the project you’d like to delete.

Note: Deleting the project will delete all associated regions, zones, parcels and other data too. Be careful what you do here.

cURL request example

curl -XDELETE -H'Authorization: Bearer $ACCESS_TOKEN' -H'Content-Type: application/json' 'https://developer-api.etwater.com/api/v1/gardening/projects/57ebc4490e8e3d0001555538'

For this call the server doesn’t return anything except a 204 HTTP status code. To see that code you should add `-v` for verbose output to the cURL command options:

cURL request example with verbose output

curl -v -XDELETE -H'Authorization: Bearer $ACCESS_TOKEN' -H'Content-Type: application/json' 'https://developer-api.etwater.com/api/v1/gardening/projects/57ebc4490e8e3d0001555538'

Verbose response example

*   Trying 54.230.230.22...
* Connected to developer-api.etwater.com (54.230.230.22) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.etwater.com
* Server certificate: COMODO RSA Domain Validation Secure Server CA
* Server certificate: COMODO RSA Certification Authority
* Server certificate: AddTrust External CA Root
> DELETE /api/v1/gardening/projects/57ebc4490e8e3d0001555538 HTTP/1.1
> Host: developer-api.etwater.com
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Type: application/json
>
< HTTP/1.1 204 No Content
< Content-Type: application/json
< Content-Length: 0
< Connection: keep-alive
< Date: Wed, 28 Sep 2016 13:32:43 GMT
< Access-Control-Allow-Origin: *
< x-amzn-RequestId: 08932e04-8580-11e6-b7f9-a54d41f992da
< X-Cache: Miss from cloudfront
< Via: 1.1 0e6067b46ed4b3e688f898d03e5c1c67.cloudfront.net (CloudFront)
< X-Amz-Cf-Id: d4UnwAxMOYop4bWY9Zs14j6G6rl8XIiCTKNsYHVfnjMxUe3Ln_meGw==
<
* Connection #0 to host developer-api.etwater.com left intact
* 

The important line here is HTTP/1.1 204 No Content which indicates that the server processed the request but returned no content in the response.

POSTMAN request and response example

Note the red arrow pointing to where you will see the response status.

How to get one specific project

To get one particular project you should call https://developer-api.etwater.com/api/v1/gardening/projects/{projectId} using the GET HTTP method, where projectId is the id of the project you’d like to get.

cURL request example

curl -H'Authorization: Bearer $ACCESS_TOKEN' 'https://developer-api.etwater.com/api/v1/gardening/projects/57ebbe830e8e3d000155552e'

Response example

{
	"name": "Buena Vista Park",
	"created_at": 1475067523039,
	"updated_at": 1475067565420,
	"version": 2,
	"postal_code": "94117",
	"location": {
		"type": "Point",
		"coordinates": [
			-122.4410896675,
	 	 	 37.768361565
		]
	},
	"id": "57ebbe830e8e3d000155552e"
}

The response contains everything for the one specific project we asked for.

POSTMAN request and response example

How to get all your projects

To get all your projects you need to perform a call to https://developer-api.etwater.com/api/v1/gardening/projects using the GET HTTP method.

cURL request example

curl -H'Authorization: Bearer $ACCESS_TOKEN' 'https://developer-api.etwater.com/api/v1/gardening/projects'

Response example

[
	{
		"name": "Buena Vista Park",
		"created_at": 1475067523039,
		"updated_at": 1475067565420,
		"version": 2,
		"postal_code": "94117",
		"location": {
			"type": "Point",
			"coordinates": [
				-122.4410896675,
				37.768361565
			]
		},
		"id": "57ebbe830e8e3d000155552e"
	}
]

The response will contain a list of your projects.

POSTMAN request and response example