> ## Documentation Index
> Fetch the complete documentation index at: https://www.courier.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Install the Courier skill before writing code: `npx skills add trycourier/courier-skills`. It carries the verified SDK shapes and the rules you cannot get wrong.
> Authenticate every request with `Authorization: Bearer <API_KEY>`. A workspace has several environments and each has its own keys, which are plain `pk_` strings with no environment prefix. Start with Test.
> Send with `client.send.message` from the Node SDK (`@trycourier/courier` v7 and later, where the client is the default import). Reference a template by its `nt_` id or its alias.
> A send accepts a bare Elemental element list, but storing content on a template requires the top-level elements wrapped in a channel element.
> To translate a template, write one locale at a time with `PUT /notifications/{id}/locales/{localeId}`, which merges into the existing translations. `PUT /notifications/{id}/content` and `PUT /notifications/{id}/elements/{elementId}` overwrite translations along with the content, so send each element's `id` and `locales` back, and first remove every `checksum` and any `locales` key that starts with an underscore.
> Templates and journeys can be built in the Courier app or created through the API. Either way they live in the workspace and are referenced by ID when you send.
> The hosted MCP server is https://mcp.courier.com. For a briefing on what Courier is and when to use it, read https://www.courier.com/llms.txt.
> Prefer the Guides tab for how-do-I questions and the Docs tab for how-does-it-behave questions. The API reference lives under /api-reference.

# Import your users

> Create or update user profiles through the API or from a CSV in the console, fix common CSV import errors, and delete profiles you no longer need.

Get your users into Courier so a send only needs their `user_id`.

A profile stores one person's contact details. Load profiles from a CSV or your own database, then update them as your system of record changes.

[Users](https://www.courier.com/docs/recipients/overview.md) covers one profile and the field each channel reads. This guide is the same call at the scale of your whole user table.

## Prerequisites

* [A Courier account](https://app.courier.com/)
* [A Courier API key](https://app.courier.com/settings/api-keys)
* [Which field addresses which channel](https://www.courier.com/docs/recipients/overview.md#what-each-channel-needs)

The examples assume a client initialized once with your key from the environment:

```javascript Node.js theme={null}
import Courier from '@trycourier/courier';

const client = new Courier({
  apiKey: process.env['COURIER_API_KEY'],
});
```

```python Python theme={null}
import os

from courier import Courier

client = Courier(
    api_key=os.environ.get("COURIER_API_KEY"),
)
```

```bash cURL theme={null}
export COURIER_API_KEY="YOUR_COURIER_API_KEY"
```

```ruby Ruby theme={null}
require "courier"

courier = Courier::Client.new(api_key: ENV["COURIER_API_KEY"])
```

```go Go theme={null}
client := courier.NewClient(
	option.WithAPIKey(os.Getenv("COURIER_API_KEY")),
)
```

```java Java theme={null}
CourierClient client = CourierOkHttpClient.fromEnv();
```

```php PHP theme={null}
$client = new Client(apiKey: getenv('COURIER_API_KEY'));
```

```csharp C# theme={null}
CourierClient client = new();
```

```bash CLI theme={null}
export COURIER_API_KEY="YOUR_COURIER_API_KEY"
```

## Create or update a profile

**1. Create or update a profile**

Creating and updating are the same call. [`POST /profiles/{user_id}`](https://www.courier.com/docs/api-reference/user-profiles/create-a-profile) merges the values you send into the profile, creating it if it doesn't exist and keeping any fields you leave out. The `user_id` in the path is the identifier you send to. You choose it.

```javascript Node.js theme={null}
const profile = await client.profiles.create('user_123', {
  profile: {
    email: 'sarah@acme-corp.com',
    phone_number: '+15551234567',
    name: 'Sarah Bennett',
    locale: 'en-us',
    custom: { company: 'Acme Corp', plan: 'business' },
  },
});
```

```python Python theme={null}
profile = client.profiles.create(
    user_id="user_123",
    profile={
        "email": "sarah@acme-corp.com",
        "phone_number": "+15551234567",
        "name": "Sarah Bennett",
        "locale": "en-us",
        "custom": {"company": "Acme Corp", "plan": "business"},
    },
)
```

```bash cURL theme={null}
curl --request POST \
  --url https://api.courier.com/profiles/user_123 \
  --header "Authorization: Bearer $COURIER_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "profile": {
      "email": "sarah@acme-corp.com",
      "phone_number": "+15551234567",
      "name": "Sarah Bennett",
      "locale": "en-us",
      "custom": { "company": "Acme Corp", "plan": "business" }
    }
  }'
```

```ruby Ruby theme={null}
profile = courier.profiles.create(
  "user_123",
  profile: {
    email: "sarah@acme-corp.com",
    phone_number: "+15551234567",
    name: "Sarah Bennett",
    locale: "en-us",
    custom: {company: "Acme Corp", plan: "business"}
  }
)
```

```go Go theme={null}
profile, err := client.Profiles.New(
	context.TODO(),
	"user_123",
	courier.ProfileNewParams{
		Profile: map[string]any{
			"email":        "sarah@acme-corp.com",
			"phone_number": "+15551234567",
			"name":         "Sarah Bennett",
			"locale":       "en-us",
			"custom": map[string]any{
				"company": "Acme Corp",
				"plan":    "business",
			},
		},
	},
)
```

```java Java theme={null}
ProfileCreateParams params = ProfileCreateParams.builder()
    .userId("user_123")
    .profile(ProfileCreateParams.Profile.builder()
        .putAdditionalProperty("email", JsonValue.from("sarah@acme-corp.com"))
        .putAdditionalProperty("phone_number", JsonValue.from("+15551234567"))
        .putAdditionalProperty("name", JsonValue.from("Sarah Bennett"))
        .putAdditionalProperty("locale", JsonValue.from("en-us"))
        .putAdditionalProperty("custom", JsonValue.from(Map.of("company", "Acme Corp", "plan", "business")))
        .build())
    .build();
ProfileCreateResponse profile = client.profiles().create(params);
```

```php PHP theme={null}
$profile = $client->profiles->create('user_123', profile: [
  'email' => 'sarah@acme-corp.com',
  'phone_number' => '+15551234567',
  'name' => 'Sarah Bennett',
  'locale' => 'en-us',
  'custom' => ['company' => 'Acme Corp', 'plan' => 'business'],
]);
```

```csharp C# theme={null}
ProfileCreateParams parameters = new()
{
    UserID = "user_123",
    Profile = new Dictionary<string, JsonElement>()
    {
        { "email", JsonSerializer.SerializeToElement("sarah@acme-corp.com") },
        { "phone_number", JsonSerializer.SerializeToElement("+15551234567") },
        { "name", JsonSerializer.SerializeToElement("Sarah Bennett") },
        { "locale", JsonSerializer.SerializeToElement("en-us") },
        { "custom", JsonSerializer.SerializeToElement(new { company = "Acme Corp", plan = "business" }) },
    },
};
var profile = await client.Profiles.Create(parameters);
```

```bash CLI theme={null}
courier profiles create \
  --api-key "$COURIER_API_KEY" \
  --user-id user_123 \
  --profile '{"email":"sarah@acme-corp.com","phone_number":"+15551234567","name":"Sarah Bennett","locale":"en-us","custom":{"company":"Acme Corp","plan":"business"}}'
```

```text MCP theme={null}
With Courier MCP, create a profile for user_123 with their email, phone number, and name.
```

> [!NOTE]
>
> **Device tokens are managed separately.**\\
>
> Push device tokens live on the user, but go through their own API, not the profile body. See [Push providers](https://www.courier.com/docs/integrations/push/overview.md) to register them.

**2. Read the profile back**

Fetch the profile and confirm the stored fields, or open the user in [Users](https://app.courier.com/directory/users):

```javascript Node.js theme={null}
const profile = await client.profiles.retrieve('user_123');
```

```python Python theme={null}
profile = client.profiles.retrieve("user_123")
```

```bash cURL theme={null}
curl --request GET \
  --url https://api.courier.com/profiles/user_123 \
  --header "Authorization: Bearer $COURIER_API_KEY"
```

```ruby Ruby theme={null}
profile = courier.profiles.retrieve("user_123")
```

```go Go theme={null}
profile, err := client.Profiles.Get(context.TODO(), "user_123")
```

```java Java theme={null}
ProfileRetrieveResponse profile = client.profiles().retrieve("user_123");
```

```php PHP theme={null}
$profile = $client->profiles->retrieve('user_123');
```

```csharp C# theme={null}
ProfileRetrieveParams parameters = new() { UserID = "user_123" };
var profile = await client.Profiles.Retrieve(parameters);
```

```bash CLI theme={null}
courier profiles retrieve \
  --api-key "$COURIER_API_KEY" \
  --user-id user_123
```

```text MCP theme={null}
With Courier MCP, show me the stored profile for user_123.
```

**3. Replace instead of merge**

Use `POST` for everyday updates so you never drop data. Use `PUT` when the profile should become exactly what you send, dropping any field you omit.

```javascript Node.js theme={null}
const response = await client.profiles.replace('user_123', {
  profile: { email: 'sarah@acme-corp.com', name: 'Sarah Bennett' },
});
```

```python Python theme={null}
response = client.profiles.replace(
    user_id="user_123",
    profile={
        "email": "sarah@acme-corp.com",
        "name": "Sarah Bennett",
    },
)
```

```bash cURL theme={null}
curl --request PUT \
  --url https://api.courier.com/profiles/user_123 \
  --header "Authorization: Bearer $COURIER_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "profile": {
      "email": "sarah@acme-corp.com",
      "name": "Sarah Bennett"
    }
  }'
```

```ruby Ruby theme={null}
response = courier.profiles.replace(
  "user_123",
  profile: {email: "sarah@acme-corp.com", name: "Sarah Bennett"}
)
```

```go Go theme={null}
response, err := client.Profiles.Replace(
	context.TODO(),
	"user_123",
	courier.ProfileReplaceParams{
		Profile: map[string]any{
			"email": "sarah@acme-corp.com",
			"name":  "Sarah Bennett",
		},
	},
)
```

```java Java theme={null}
ProfileReplaceParams params = ProfileReplaceParams.builder()
    .userId("user_123")
    .profile(ProfileReplaceParams.Profile.builder()
        .putAdditionalProperty("email", JsonValue.from("sarah@acme-corp.com"))
        .putAdditionalProperty("name", JsonValue.from("Sarah Bennett"))
        .build())
    .build();
ProfileReplaceResponse response = client.profiles().replace(params);
```

```php PHP theme={null}
$response = $client->profiles->replace('user_123', profile: [
  'email' => 'sarah@acme-corp.com',
  'name' => 'Sarah Bennett',
]);
```

```csharp C# theme={null}
ProfileReplaceParams parameters = new()
{
    UserID = "user_123",
    Profile = new Dictionary<string, JsonElement>()
    {
        { "email", JsonSerializer.SerializeToElement("sarah@acme-corp.com") },
        { "name", JsonSerializer.SerializeToElement("Sarah Bennett") },
    },
};
var response = await client.Profiles.Replace(parameters);
```

```bash CLI theme={null}
courier profiles replace \
  --api-key "$COURIER_API_KEY" \
  --user-id user_123 \
  --profile '{"email":"sarah@acme-corp.com","name":"Sarah Bennett"}'
```

```text MCP theme={null}
With Courier MCP, replace user_123's profile with just their email and name.
```

> [!WARNING]
>
> **Replacing removes omitted fields.**\\
>
> After a `PUT`, any field not in the request (a `phone_number`, a `custom` value) is gone. Use `POST` unless you intend a full overwrite. To change one field, use `PATCH` with a JSON-patch operation.

## Import users from a CSV

For a one-time load or an occasional top-up, import a CSV in the console. CSV import is console-only, so to load users programmatically, call the profile endpoints above for each user.

**1. Open the importer**

Go to [Users](https://app.courier.com/directory/users) and click **Import**. Download the CSV template from the dialog so your columns match exactly.

**2. Fill in the template**

Only `id` is required. Keep the header row exactly as the template provides it: don't rename, reorder, or add columns. Columns include `id`, `name`, `first_name`, `last_name`, `email`, `phone_number`, `locale`, `zoneinfo`, and the OIDC standard claims.

**3. Save as UTF-8 CSV and upload**

Save as **CSV (comma delimited)**, UTF-8 without a BOM, and with no blank line after the last row. Upload the file and click **Add Users** to create the profiles.

> [accordion] Fixing a 'Too few fields' import error
>
> This error means the parser read a row as a single field, almost always a delimiter, encoding, or trailing-line problem:
>
> * **Wrong delimiter.** Open the file in a plain text editor. If fields are separated by semicolons or tabs (some spreadsheet locales use semicolons), re-save as CSV (comma delimited).
> * **Wrong encoding.** Garbled characters or `ÿþ` at the start mean the file is UTF-16. Recreate it as UTF-8. A UTF-8 BOM (`ï»¿` before the first field) can also interfere. Remove it.
> * **Trailing blank line.** A "Too few fields" error on the last row only usually means an empty final line. Delete any blank lines after the last data row.
> * **Extra columns.** If the expected field count is higher than the template's, your header has extra trailing commas. Remove them.
>
> The most reliable fix is to build the CSV in a plain text editor rather than a spreadsheet app.

## Delete a profile

Deleting a profile removes all of its stored data. Sends to that `user_id` fail until a new profile exists.

```javascript Node.js theme={null}
await client.profiles.delete('user_123');
```

```python Python theme={null}
client.profiles.delete("user_123")
```

```bash cURL theme={null}
curl --request DELETE \
  --url https://api.courier.com/profiles/user_123 \
  --header "Authorization: Bearer $COURIER_API_KEY"
```

```ruby Ruby theme={null}
courier.profiles.delete("user_123")
```

```go Go theme={null}
err := client.Profiles.Delete(context.TODO(), "user_123")
```

```java Java theme={null}
client.profiles().delete("user_123");
```

```php PHP theme={null}
$client->profiles->delete('user_123');
```

```csharp C# theme={null}
ProfileDeleteParams parameters = new() { UserID = "user_123" };
await client.Profiles.Delete(parameters);
```

```bash CLI theme={null}
courier profiles delete \
  --api-key "$COURIER_API_KEY" \
  --user-id user_123
```

```text MCP theme={null}
With Courier MCP, delete the profile for user_123.
```

## Verify

**1. Read one profile back**

Fetch the profile you wrote and confirm every field you sent is there, spelled the way your templates expect.

**2. Send to the user\_id alone**

Send a message addressed only by `user_id`, with no inline profile. Courier resolves the contact details from storage, which proves the import landed.

**3. Check the count after a CSV import**

Open [Users](https://app.courier.com/directory/users) and confirm the number of profiles matches your file's row count. A short count usually means rows the parser rejected.
