> 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.

# Create a B2B user

PUT https://tree-nation.com/api/user/b2b
Content-Type: application/json

Creates a new B2B organisation user account and automatically sets up a
default tree template.

If `password` is not provided, an 8-character random password is generated
and returned in the response.


Reference: https://docs.tree-nation.com/api-reference/plant/create-b-2-b-user

## 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 CreateUserRequest.

- `name` (string, required) — Organisation display name.
- `email` (string, required) — Must be unique across all users.
- `responsible_name` (string, required) — Name of the person responsible for the organisation.
- `password` (string, optional) — Account password. A random 8-character password is generated and returned in the response if this field is omitted.
- `language` (enum, optional) — Preferred locale for the new account.
  - Allowed values: `de`, `en`, `es`, `fr`, `it`, `pt`
- `organization_website` (string, optional) — Organisation website. `http://` is automatically prepended if no scheme is present.

## Response

### 200

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

- `status` (enum, optional)
  - Allowed values: `ok`, `error`
- `user_id` (integer, optional) — ID of the newly created user.
- `password` (string, optional) — The account password (provided or auto-generated).
- `slug` (string, optional) — URL slug for the user's public forest page.
- `forest_url` (string, optional) — Full URL to the user's forest profile.
- `errorCode` (enum, optional, nullable)
  - Allowed values: `data`, `password`, `language`, `user`
- `errorMessage` (string, optional, nullable)

## Errors

### 401 Unauthorized Error

Missing or invalid token.

- `any`

### 403 Forbidden Error

Account is inactive.

- `any`

## Examples

**Request**

```json
{
  "name": "GreenTech Solutions",
  "email": "contact@greentechsolutions.com",
  "responsible_name": "Alice Johnson",
  "password": "SecureP@55",
  "language": "en",
  "organization_website": "https://www.greentechsolutions.com"
}
```

**Response**

```json
{
  "status": "ok",
  "user_id": 1024,
  "password": "SecureP@55",
  "slug": "greentech-solutions",
  "forest_url": "https://tree-nation.com/forests/greentech-solutions",
  "errorCode": "",
  "errorMessage": ""
}
```

**SDK Code**

```python
import requests

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

payload = {
    "name": "GreenTech Solutions",
    "email": "contact@greentechsolutions.com",
    "responsible_name": "Alice Johnson",
    "password": "SecureP@55",
    "language": "en",
    "organization_website": "https://www.greentechsolutions.com"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://tree-nation.com/api/user/b2b';
const options = {
  method: 'PUT',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"name":"GreenTech Solutions","email":"contact@greentechsolutions.com","responsible_name":"Alice Johnson","password":"SecureP@55","language":"en","organization_website":"https://www.greentechsolutions.com"}'
};

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/user/b2b"

	payload := strings.NewReader("{\n  \"name\": \"GreenTech Solutions\",\n  \"email\": \"contact@greentechsolutions.com\",\n  \"responsible_name\": \"Alice Johnson\",\n  \"password\": \"SecureP@55\",\n  \"language\": \"en\",\n  \"organization_website\": \"https://www.greentechsolutions.com\"\n}")

	req, _ := http.NewRequest("PUT", 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/user/b2b")

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

request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"GreenTech Solutions\",\n  \"email\": \"contact@greentechsolutions.com\",\n  \"responsible_name\": \"Alice Johnson\",\n  \"password\": \"SecureP@55\",\n  \"language\": \"en\",\n  \"organization_website\": \"https://www.greentechsolutions.com\"\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.put("https://tree-nation.com/api/user/b2b")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"GreenTech Solutions\",\n  \"email\": \"contact@greentechsolutions.com\",\n  \"responsible_name\": \"Alice Johnson\",\n  \"password\": \"SecureP@55\",\n  \"language\": \"en\",\n  \"organization_website\": \"https://www.greentechsolutions.com\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://tree-nation.com/api/user/b2b', [
  'body' => '{
  "name": "GreenTech Solutions",
  "email": "contact@greentechsolutions.com",
  "responsible_name": "Alice Johnson",
  "password": "SecureP@55",
  "language": "en",
  "organization_website": "https://www.greentechsolutions.com"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://tree-nation.com/api/user/b2b");
var request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"GreenTech Solutions\",\n  \"email\": \"contact@greentechsolutions.com\",\n  \"responsible_name\": \"Alice Johnson\",\n  \"password\": \"SecureP@55\",\n  \"language\": \"en\",\n  \"organization_website\": \"https://www.greentechsolutions.com\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "GreenTech Solutions",
  "email": "contact@greentechsolutions.com",
  "responsible_name": "Alice Johnson",
  "password": "SecureP@55",
  "language": "en",
  "organization_website": "https://www.greentechsolutions.com"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://tree-nation.com/api/user/b2b")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
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()
```