# Child Users

A Child `User` is a sub-account type designed for managing customers or businesses that use a Forge-Powered shipping solution.
Each Child User can have a unique set of carrier credentials, analytics, and reports, simplifying the management of a platform or marketplace solution.

Beyond organizing activity and `CarrierAccounts`, the primary advantage of a Child `User` is that billing flows through the Parent User’s payment information.
This allows the Parent User to maintain complete control over customers' postage and pricing.

Structurally, a Child `User` mirrors the Parent User, meaning its representation includes many properties that may not be actively used.
However, creating a Child User requires significantly fewer properties than creating a top-level `User`.

---

**Production Only**

## Create a Child User

### Example: POST /users

#### cURL

```shell
curl -X POST https://api.easypost.com/v2/users \
  -u "EASYPOST_API_KEY": \
  -H 'Content-Type: application/json' \
  -d '{
    "user": {
      "name": "Child Account Name"
    }
  }'
```

#### Go

```go
package example

import (
	"fmt"

	"github.com/EasyPost/easypost-go/v5"
)

func create() {
	client := easypost.New("EASYPOST_API_KEY")

	userName := "Child Account Name"
	user, _ := client.CreateUser(
		&easypost.UserOptions{
			Name: &userName,
		},
	)

	fmt.Println(user)
}
```

#### Java

```java
package users;

import com.easypost.exception.EasyPostException;
import com.easypost.model.User;
import com.easypost.service.EasyPostClient;

import java.util.HashMap;

public class Create {
    public static void main(String[] args) throws EasyPostException {
        EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY");

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("name", "Child Account Name");

        User user = client.user.create(params);

        System.out.println(user);
    }
}
```

#### C#

```csharp
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyPost;
using Newtonsoft.Json;

namespace EasyPostExamples
{
    public class Examples
    {
        public static async Task Main()
        {
            var client = new EasyPost.Client(new EasyPost.ClientConfiguration("EASYPOST_API_KEY"));

            EasyPost.Parameters.User.CreateChild parameters = new()
            {
                Name = "Child Account Name",
            };

            EasyPost.Models.API.User user = await client.User.Create(parameters);

            Console.WriteLine(JsonConvert.SerializeObject(user, Formatting.Indented));
        }
    }
}
```

#### Node.js

```javascript
const EasyPostClient = require('@easypost/api');

const client = new EasyPostClient('EASYPOST_API_KEY');

(async () => {
  const user = await client.User.create({
    name: 'Child Account Name',
  });

  console.log(user);
})();
```

#### PHP

```php
<?php

$client = new \EasyPost\EasyPostClient('EASYPOST_API_KEY');

$child = $client->user->create([
    'name' => 'Child Account Name'
]);

echo $child;
```

#### Python

```python
import easypost

client = easypost.EasyPostClient("EASYPOST_API_KEY")

user = client.user.create(name="Child Account Name")

print(user)
```

#### Ruby

```ruby
require 'easypost'

client = EasyPost::Client.new(api_key: 'EASYPOST_API_KEY')

user = client.user.create(
  name: 'Child Account Name',
)

puts user
```

A Child `User` uses the billing information of the parent, and is not able to log in to the website.
Any `User` creation attempt made with an authenticated request (via API key or cookie) is assumed to be the creation of a child of that `User`.

The `name` attribute is the only user-settable value on child accounts.
It is also optional, as one will be automatically generated if it is not supplied.

---

**Production Only**

## Retrieve all Child Users

### Example: GET /users/children

#### cURL

```shell
curl -X GET "https://api.easypost.com/v2/users/children?page_size=5" \
  -u "EASYPOST_API_KEY":
```

#### Go

```go
package example

import (
	"fmt"

	"github.com/EasyPost/easypost-go/v5"
)

func list() {
	client := easypost.New("EASYPOST_API_KEY")

	childUsers, _ := client.ListChildUsers(
		&easypost.ListOptions{
			PageSize: 5,
		},
	)

	fmt.Println(childUsers)
}
```

#### Java

```java
package child_users;

import com.easypost.exception.EasyPostException;
import com.easypost.model.ChildUserCollection;
import com.easypost.service.EasyPostClient;

import java.util.HashMap;

public class List {
    public static void main(String[] args) throws EasyPostException {
        EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY");

        HashMap<String, Object> params = new HashMap<>();

        params.put("page_size", 5);

        ChildUserCollection childUsers = client.user.allChildren(params);

        System.out.println(childUsers);
    }
}
```

#### C#

```csharp
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyPost;
using Newtonsoft.Json;

namespace EasyPostExamples
{
    public class Examples
    {
        public static async Task Main()
        {
            var client = new EasyPost.Client(new EasyPost.ClientConfiguration("EASYPOST_API_KEY"));

            EasyPost.Parameters.Users.AllChildren parameters = new()
            {
                PageSize = 5
            };

            EasyPost.Models.API.ChildUserCollection childUserCollection = await client.User.AllChildren(parameters);

            Console.WriteLine(JsonConvert.SerializeObject(childUserCollection, Formatting.Indented));
        }
    }
}
```

#### Node.js

```javascript
const EasyPostClient = require('@easypost/api');

const client = new EasyPostClient('EASYPOST_API_KEY');

(async () => {
  const childUsers = await client.User.allChildren({
    page_size: 5,
  });

  console.log(childUsers);
})();
```

#### PHP

```php
<?php

$client = new \EasyPost\EasyPostClient('EASYPOST_API_KEY');

$childUsers = $client->user->allChildren([
    'page_size' => 5
]);

echo $childUsers;
```

#### Python

```python
import easypost

client = easypost.EasyPostClient("EASYPOST_API_KEY")

childUsers = client.user.all_children(page_size=5)

print(childUsers)
```

#### Ruby

```ruby
require 'easypost'

client = EasyPost::Client.new(api_key: 'EASYPOST_API_KEY')

child_users = client.user.all_children(
  page_size: 5,
)

puts child_users
```

A list of all Child `User` objects associated with the given `API Key` can also be retrieved. See the Pagination section of our docs for more details on retrieving all records when multiple pages are available.

---

**Production Only**

## Delete a Child User

### Example: DELETE /users/:child_id

#### cURL

```shell
curl -X DELETE https://api.easypost.com/v2/users/user_... \
  -u "EASYPOST_API_KEY":
```

#### Go

```go
package example

import (
	"fmt"

	"github.com/EasyPost/easypost-go/v5"
)

func delete() {
	client := easypost.New("EASYPOST_API_KEY")

	err := client.DeleteUser("user_...")

	fmt.Println(err)
}
```

#### Java

```java
package users;

import com.easypost.exception.EasyPostException;
import com.easypost.service.EasyPostClient;

public class Delete {
    public static void main(String[] args) throws EasyPostException {
        EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY");

        client.user.delete("user_...");
    }
}
```

#### C#

```csharp
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyPost;
using Newtonsoft.Json;

namespace EasyPostExamples
{
    public class Examples
    {
        public static async Task Main()
        {
            var client = new EasyPost.Client(new EasyPost.ClientConfiguration("EASYPOST_API_KEY"));

            await client.User.Delete("user_...");
        }
    }
}
```

#### Node.js

```javascript
const EasyPostClient = require('@easypost/api');

const client = new EasyPostClient('EASYPOST_API_KEY');

(async () => {
  await client.User.delete('user_...');
})();
```

#### PHP

```php
<?php

$client = new \EasyPost\EasyPostClient('EASYPOST_API_KEY');

$client->user->delete('user_...');
```

#### Python

```python
import easypost

client = easypost.EasyPostClient("EASYPOST_API_KEY")

client.user.delete("user_...")
```

#### Ruby

```ruby
require 'easypost'

client = EasyPost::Client.new(api_key: 'EASYPOST_API_KEY')

client.user.delete('user_...')
```

A Child `User` may be removed from its parent.
The parent's Production API Key must be used for the request; a Child `User` may not remove itself from its parent.

A successful delete will return a `204` status code and an empty JSON response.