> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.tree-nation.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.tree-nation.com/_mcp/server.

# Plant trees

POST https://tree-nation.com/api/plant
Content-Type: application/json

Plants trees on behalf of the authenticated API user.

**Selection logic**:
- If `planter_id` is given, the template for that planter is used; falls back to the
  catch-all template (`planter_id = 0`) if no specific one exists.
- If `recipients` is given, `quantity` trees are planted per recipient.
- If `species_id` is given, it overrides the template's default species.

**Idempotency**: supply `order_id` to prevent duplicate processing.


Reference: https://docs.tree-nation.com/api-reference/plant/trees

## Authentication

- `Authorization` header (bearer token, required) — Bearer token required for all User API endpoints. Routes are additionally guarded by an `active` middleware (account must be active).

## Request

### Body (application/json)

This endpoint expects a PlantRequest.

- `recipients` (list of PlantRecipient, optional) — List of people to plant trees for. If omitted, the API user is the sole recipient.
- `planter_id` (integer, optional) — Target planter user ID. Defaults to the API user's configured planter. Falls back to the catch-all template (`planter_id = 0`) if no specific template exists.
- `species_id` (integer, optional) — Override the species. Must be complete and belong to an affiliated project. If omitted, uses the tree template's default species.
- `quantity` (integer, optional, nullable) — Trees to plant per recipient. Defaults to the tree template's `package_quantity`.
- `order_id` (string, optional) — Idempotency key. If an order with this `order_id` was already processed for the same API user, the request is rejected with `already_processed`.
- `language` (enum, optional) — Locale for certificate/notification emails.
  - Allowed values: `de`, `en`, `es`, `fr`, `it`, `pt`
- `message` (string, optional) — Custom message to include in the planting certificate.
- `hashtag` (string, optional) — Hashtag to associate with all trees in this order.

## Response

### 200

Planting result. Check `status` field — HTTP 200 is returned even for business-logic errors.

- `status` (enum, optional)
  - Allowed values: `ok`, `error`, `processing`
- `payment_id` (integer, optional) — ID of the created payment record (present on success).
- `errorCode` (enum, optional, nullable)
  - Allowed values: `already_processed`, `recipients`, `tree_template`, `quantity`, `species`, `planter`
- `errorMessage` (string, optional, nullable)

## Errors

### 401 Unauthorized Error

Missing or invalid token.

- `any`

### 403 Forbidden Error

Account is inactive.

- `any`

## Types

### PlantRecipient

At least one of `internal_id` or `name` is required per recipient.

- `internal_id` (string, optional) — Your internal identifier for this recipient.
- `name` (string, optional) — Display name shown on the planted tree. Required if `internal_id` is absent.
- `email` (string, optional) — Optional email to send a certificate to the recipient.

## Examples

**Request**

```json
{
  "recipients": [
    {
      "name": "test user",
      "email": "test875349@test.com"
    },
    {
      "name": "test user2",
      "email": "test458954@test.com"
    }
  ],
  "planter_id": 1,
  "species_id": 1,
  "quantity": 2,
  "message": "Thank you for your purchase!"
}
```

**Response**

```json
{
  "status": "ok",
  "payment_id": 1,
  "errorCode": "already_processed",
  "errorMessage": "string"
}
```

**SDK Code**

```python
import requests

url = "https://tree-nation.com/api/plant"

payload = {
    "recipients": [
        {
            "name": "test user",
            "email": "test875349@test.com"
        },
        {
            "name": "test user2",
            "email": "test458954@test.com"
        }
    ],
    "planter_id": 1,
    "species_id": 1,
    "quantity": 2,
    "message": "Thank you for your purchase!"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://tree-nation.com/api/plant';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"recipients":[{"name":"test user","email":"test875349@test.com"},{"name":"test user2","email":"test458954@test.com"}],"planter_id":1,"species_id":1,"quantity":2,"message":"Thank you for your purchase!"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://tree-nation.com/api/plant"

	payload := strings.NewReader("{\n  \"recipients\": [\n    {\n      \"name\": \"test user\",\n      \"email\": \"test875349@test.com\"\n    },\n    {\n      \"name\": \"test user2\",\n      \"email\": \"test458954@test.com\"\n    }\n  ],\n  \"planter_id\": 1,\n  \"species_id\": 1,\n  \"quantity\": 2,\n  \"message\": \"Thank you for your purchase!\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://tree-nation.com/api/plant")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"recipients\": [\n    {\n      \"name\": \"test user\",\n      \"email\": \"test875349@test.com\"\n    },\n    {\n      \"name\": \"test user2\",\n      \"email\": \"test458954@test.com\"\n    }\n  ],\n  \"planter_id\": 1,\n  \"species_id\": 1,\n  \"quantity\": 2,\n  \"message\": \"Thank you for your purchase!\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://tree-nation.com/api/plant")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"recipients\": [\n    {\n      \"name\": \"test user\",\n      \"email\": \"test875349@test.com\"\n    },\n    {\n      \"name\": \"test user2\",\n      \"email\": \"test458954@test.com\"\n    }\n  ],\n  \"planter_id\": 1,\n  \"species_id\": 1,\n  \"quantity\": 2,\n  \"message\": \"Thank you for your purchase!\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://tree-nation.com/api/plant', [
  'body' => '{
  "recipients": [
    {
      "name": "test user",
      "email": "test875349@test.com"
    },
    {
      "name": "test user2",
      "email": "test458954@test.com"
    }
  ],
  "planter_id": 1,
  "species_id": 1,
  "quantity": 2,
  "message": "Thank you for your purchase!"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://tree-nation.com/api/plant");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"recipients\": [\n    {\n      \"name\": \"test user\",\n      \"email\": \"test875349@test.com\"\n    },\n    {\n      \"name\": \"test user2\",\n      \"email\": \"test458954@test.com\"\n    }\n  ],\n  \"planter_id\": 1,\n  \"species_id\": 1,\n  \"quantity\": 2,\n  \"message\": \"Thank you for your purchase!\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "recipients": [
    [
      "name": "test user",
      "email": "test875349@test.com"
    ],
    [
      "name": "test user2",
      "email": "test458954@test.com"
    ]
  ],
  "planter_id": 1,
  "species_id": 1,
  "quantity": 2,
  "message": "Thank you for your purchase!"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://tree-nation.com/api/plant")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```