# Create a contact's preference links (/docs/api-reference/contacts/create-preference-links)

The contact's preference center and unsubscribe links, for emails you build yourself. They never expire. Marketing email sent through coss.com gets them (and one-click unsubscribe headers) automatically. Needs `contact:update`: whoever has the links can change the contact's consent.

`POST https://api.coss.com/v1/contacts/{id}/preference_links`

Authenticate with your API key as a bearer token (`Authorization: Bearer coss_test_…`). Responses are JSON with snake_case fields; errors are `{ error: { type, code, message, param?, issues?, request_id } }` (https://coss.com/docs/api-reference/errors.md).

## Path parameters

- `id` (string, required): The contact's id, or its address (URL-encoded).

## Request body

- `topic` (string): The topic your email is about: its unsubscribe link leaves just that topic.

## Example request

TypeScript (the `coss` package):

```ts
import { Coss } from "coss";

const coss = new Coss({
  apiKey: process.env.COSS_API_KEY,
  baseUrl: "https://api.coss.com",
});

const { data, error } = await coss.email.contacts.createPreferenceLinks("contact_01k7c8m4q2f3e9v6t5r1n0p8yz", {
  topic: "newsletter",
});
```

HTTP:

```sh
curl -X POST "https://api.coss.com/v1/contacts/contact_01k7c8m4q2f3e9v6t5r1n0p8yz/preference_links" \
  -H "Authorization: Bearer $COSS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "topic": "newsletter"
}'
```

Python:

```python
from coss import Coss

client = Coss()  # api_key= or COSS_API_KEY

client.email.contacts.create_preference_links(
    id="contact_01k7c8m4q2f3e9v6t5r1n0p8yz",
    topic="newsletter",
)
```

Go:

```go
import (
	"context"

	coss "github.com/cosscom/coss-go"
	cossclient "github.com/cosscom/coss-go/client"
	email "github.com/cosscom/coss-go/email"
)

client := cossclient.NewClient() // option.WithAPIKey(…) or COSS_API_KEY

request := &email.CreatePreferenceLinksRequest{
    ID: "contact_01k7c8m4q2f3e9v6t5r1n0p8yz",
    Topic: coss.String(
        "newsletter",
    ),
}
client.Email.Contacts.CreatePreferenceLinks(
    context.TODO(),
    request,
)
```

Ruby:

```ruby
require "coss"

client = Coss::Client.new # api_key: or COSS_API_KEY

client.email.contacts.create_preference_links(
  id: "contact_01k7c8m4q2f3e9v6t5r1n0p8yz",
  topic: "newsletter"
)
```

PHP:

```php
<?php

use Coss\Coss;
use Coss\Email\Contacts\Requests\CreatePreferenceLinksRequest;

$client = new Coss(); // apiKey: or COSS_API_KEY

$client->email->contacts->createPreferenceLinks(
    'contact_01k7c8m4q2f3e9v6t5r1n0p8yz',
    new CreatePreferenceLinksRequest([
        'topic' => 'newsletter',
    ]),
);
```

Java:

```java
import com.coss.Coss;
import com.coss.resources.email.contacts.requests.CreatePreferenceLinksRequest;

Coss client = Coss.builder().build(); // .apiKey(…) or COSS_API_KEY

client.email().contacts().createPreferenceLinks(
    "contact_01k7c8m4q2f3e9v6t5r1n0p8yz",
    CreatePreferenceLinksRequest
        .builder()
        .topic("newsletter")
        .build()
);
```

.NET:

```csharp
using Coss;
using Coss.Email;

var client = new CossClient(); // apiKey: or COSS_API_KEY

await client.Email.Contacts.CreatePreferenceLinksAsync(
    new CreatePreferenceLinksRequest
    {
        Id = "contact_01k7c8m4q2f3e9v6t5r1n0p8yz",
        Topic = "newsletter",
    }
);
```

## Response 200

The links.

- `object` ("preference_links", required)
- `contact_id` (string, required): The contact's id.
- `preferences_url` (string, required): The contact's preference center.
- `unsubscribe_url` (string, required): A one-button unsubscribe page.

Example:

```json
{
  "object": "preference_links",
  "contact_id": "contact_01k7c8m4q2f3e9v6t5r1n0p8yz",
  "preferences_url": "https://track.cosslinks.com/t/u/aXyZ…",
  "unsubscribe_url": "https://track.cosslinks.com/t/u/aXyZ…/unsubscribe"
}
```

## Errors

- `400`: The body is not valid JSON (`invalid_json`). Also when the `Coss-Version` header names an unknown API version (`invalid_api_version`).
- `401`: The API key is missing, invalid, revoked or expired (`authentication_error`).
- `403`: The API key lacks the permission this endpoint needs (`permission_error`), or its organization is suspended (`organization_suspended`).
- `404`: No contact with this id or address exists in the API key's environment (`not_found`).
- `413`: The request body is larger than 5 MB (`payload_too_large`).
- `415`: The body is not sent as `application/json` (`unsupported_media_type`).
- `422`: The body failed validation (`validation_error`).
- `429`: Too many requests with this API key (`rate_limited`), or too many requests with invalid keys from this address (`too_many_failed_authentications`). Retry after `Retry-After` seconds. Successful responses carry `RateLimit-Limit`, `RateLimit-Remaining` and `RateLimit-Reset` (seconds until the limit is fully restored).
- `500`: Unexpected server error (`api_error` / `internal_error`).
- `503`: The API key could not be verified right now; retry (`service_unavailable`).