# User

The `User` object can be used to manage your own account and to create child accounts.
Only a Production API Key can be used to make requests against the Users API.

There are two kinds of accounts.
The first is the standard (parent) `User` object.
It represents your account state, settings, and credentials to log in via the website.
The second is the child `User`, which is a `User` that belongs to a parent.

Balance and recharge values on `User` objects are expressed in higher precision US Dollars.

  Parent `Users` must be created through the web interface.

---

## User object

| Property | Type | Description |
|----------|------|-------------|
| id | string | Unique, begins with "user_" |
| object | string | "User" |
| name | string | The first and last name of the user |
| email | string | An email address for the user |
| phone_number | string | A phone number for the user |
| balance | string | Wallet balance. Formatted as string "XX.XXXXX" |
| price_per_shipment | string | Cost per shipment purchase. Formatted as string "XX.XXXXX" |
| recharge_amount | string | How much to recharge the user's wallet when the balance drops below the recharge threshold. Formatted as string 'XX.XXXXX' |
| secondary_recharge_amount | string | How much to recharge the user's wallet when the balance drops below the recharge threshold. Formatted as string 'XX.XXXXX' |
| recharge_threshold | string | USD cents value that, when your balance drops below, we automatically recharge your account with your primary payment method |
| cc_fee_rate | string | The fee rate for convenience fees |
| insurance_fee_rate | string | The fee rate for insurance purchases |
| insurance_fee_minimum | string | The minimum cost for insurance purchases |
| children | array | All associated Child Users |

Example Object:

```json
{
  "id": "user_060ab38db3c04ffaa60f262e5781a9be",
  "object": "User",
  "parent_id": null,
  "name": "EasyPost Docs",
  "phone_number": "5555555555",
  "verified": true,
  "created_at": "2022-10-14T17:23:58Z",
  "default_carbon_offset": false,
  "has_elevate_access": false,
  "balance": "0.00000",
  "price_per_shipment": "0.00000",
  "recharge_amount": null,
  "secondary_recharge_amount": null,
  "recharge_threshold": null,
  "has_billing_method": null,
  "cc_fee_rate": "0.0375",
  "default_insurance_amount": null,
  "insurance_fee_rate": "0.005",
  "insurance_fee_minimum": "0.50",
  "email": "dev+easypost-docs@easypost.com",
  "children": [
    {
      "id": "user_0ae8cb7000a1438c8598fa5786fdae84",
      "object": "User",
      "parent_id": "user_060ab38db3c04ffaa60f262e5781a9be",
      "name": "Test User",
      "phone_number": "8005550100",
      "verified": true,
      "created_at": "2022-10-17T17:28:30Z",
      "default_carbon_offset": false,
      "has_elevate_access": false,
      "children": []
    }
  ]
}
```

---

**Production Only**

## Retrieve a User

### Example: GET /users/:id

#### cURL

```shell
# Retrieve the authenticated user
curl -X GET https://api.easypost.com/v2/users \
  -u "EASYPOST_API_KEY":

# Retrieve a child user
curl -X GET https://api.easypost.com/v2/users/user_... \
  -u "EASYPOST_API_KEY":
```

#### Go

```go
package example

import (
	"fmt"

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

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

	// Retrieve the authenticated user
	user, _ := client.RetrieveMe()
	fmt.Println(user)

	// Retrieve a child user
	user, _ = client.GetUser("user_...")
	fmt.Println(user)
}
```

#### Java

```java
package users;

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

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

        // Retrieve the authenticated user
        User parentUser = client.user.retrieveMe();

        System.out.println(parentUser);

        // Retrieve a child user
        User childUser = client.user.retrieve("user_...");

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

#### 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"));

            // Retrieve the authenticated user
            EasyPost.Models.API.User user = await client.User.RetrieveMe();

            // Retrieve a child user
            user = await client.User.Retrieve("user_...");

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

#### Node.js

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

const client = new EasyPostClient('EASYPOST_API_KEY');

(async () => {
  let user;

  // Retrieve the authenticated user
  user = await client.User.retrieveMe();

  // Retrieve a child user
  user = await client.User.retrieve('user_...');

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

#### PHP

```php
<?php

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

// Retrieve the authenticated user
$user = $client->user->retrieveMe();

// Retrieve a child user
$user = $client->user->retrieve('user_...');

echo $user;
```

#### Python

```python
import easypost

client = easypost.EasyPostClient("EASYPOST_API_KEY")

# Retrieve the authenticated user
user = client.user.retrieve_me()

# Retrieve a child user
user = client.user.retrieve("user_...")

print(user)
```

#### Ruby

```ruby
require 'easypost'

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

# Retrieve the authenticated user
user = client.user.retrieve_me

# Retrieve a child user
user = client.user.retrieve('user_...')

puts user
```

Each `User` can be retrieved individually by `id`.
Any `id` provided must be either the `id` of the authenticated `User` or the `id` of one of its Child `Users`.
Additionally, to retrieve the authenticated `User` directly, no `id` is required.

---

**Production Only**

## Update a User

### Example: PATCH /users/:id

#### cURL

```shell
# Update the authenticated user
curl -X PATCH https://api.easypost.com/v2/users \
  -u "EASYPOST_API_KEY": \
  -H 'Content-Type: application/json' \
  -d '{
    "user": {
      "recharge_threshold": "50.00"
    }
  }'

# Update a child user
curl -X PATCH https://api.easypost.com/v2/users/user_... \
  -u "EASYPOST_API_KEY": \
  -H 'Content-Type: application/json' \
  -d '{
    "user": {
      "name": "Test Child"
    }
  }'
```

#### Go

```go
package example

import (
	"fmt"

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

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

	rechargeAmount := "50.00"

	user, _ := client.UpdateUser(
		&easypost.UserOptions{
			ID:             "user_...",
			RechargeAmount: &rechargeAmount,
		},
	)

	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 Update {
    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("recharge_threshold", "50.00");

        User user = client.user.update("user_...", 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.Update parameters = new()
            {
                RechargeThreshold = "50.00"
            };

            EasyPost.Models.API.User user = await client.User.Update("user_...", 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.update('user_...', { recharge_threshold: '50.00' });

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

#### PHP

```php
<?php

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

$user = $client->user->update(
    'user_...',
    ['recharge_threshold' => '50.00']
);

echo $user;
```

#### Python

```python
import easypost

client = easypost.EasyPostClient("EASYPOST_API_KEY")

user = client.user.retrieve_me()

updated_user = client.user.update(user.id, recharge_threshold="50.00")

print(updated_user)
```

#### Ruby

```ruby
require 'easypost'

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

retrieved_user = client.user.retrieve_me

user = client.user.update(retrieved_user.id, recharge_amount: '50.00')

puts user
```

Just like retrieving a `User`, they can be updated using the same patterns.
Passing an `id` will allow the update of a Child `User` or the authenticated `User`.
Passing no `id` will update the authenticated `User`.

Since Child `Users` also have the ability to authenticate themselves, they can be updated without passing an `id`.
Child `Users` may only have their `name` field updated; all other fields are ignored.

An update request for a `User` is a partial update.
Only attributes specifically passed in will be updated.
The `current_password` attribute is required when updating `email` or `password`.