> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.portreeve.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.portreeve.com/_mcp/server.

# Attach your account id to a stored event

PATCH https://api.portreeve.com/v1/events/{id}
Content-Type: application/json

Late user binding: when your auth provider mints the user id (Supabase, Auth0, Clerk, Firebase), there is no `external_user_id` to send at verdict time — screen first, create the user, then attach the id the provider returned. Portreeve keeps the mapping: a later `review.resolved` webhook names this id, and the identity graph gains the account edge as if the id had arrived on the original request.

**Write-once.** The first attach wins; replaying the same value returns `200` idempotently; a different value is a `409 conflict`. An id sent at verdict time counts as the first write.

Reference: https://docs.portreeve.com/api-reference/events/attach-user

## Authentication

- `Authorization` header (bearer token, required) — `Authorization: Bearer sk_live_…` (or `sk_test_…`). Server-side only — never ship a secret key to a browser or a mobile app. The key determines the tenant *and* the mode; there is no mode parameter on any request.

## Request

### Path parameters

- `id` (string, required) — The event id returned by `POST /v1/verdict`.

### Body (application/json)

This endpoint expects an AttachUserRequest.

- `external_user_id` (string, required) — Your user id for the account this event belongs to — the same value you would have sent on the verdict call had your auth provider not minted it afterwards. 1–256 characters, write-once.

## Response

### 200

The id is attached (or was already attached with this exact value).

- `ok` (true, required) — Always `true`. The endpoint has no failure mode that returns 200.

## Errors

### 400 Bad Request Error

The body failed contract validation. `external_user_id` must be a non-empty string of at most 256 characters.

- `error` (string, required) — **This is an open set.** New values ship without a new SDK release and without a breaking change, so this is documented as a plain string rather than a closed enum. Treat an unrecognised value as informational: log it, display it, never crash on it, and never map "unknown" to a punitive action. Publishing a closed enum here would make our next additive release break every generated client that validates responses. The values defined today (also available machine-readably in `x-portreeve-known-values`) are: `invalid_request`, `unauthorized`, `rate_limited`, `idempotency_conflict`, `conflict`, `not_found`, `internal`.
- `message` (string, required) — Human-readable, for your logs. Never show it to an end user — on a `block` it can describe what tripped.
- `details` (map from string to any, optional) — Optional structured context. On a 400 it carries `issues[]`, an array of `{ path, message }` — one entry per validation failure.

### 401 Unauthorized Error

Missing, malformed, unknown, revoked, or wrong-kind API key. A secret key is required.

- `error` (string, required) — **This is an open set.** New values ship without a new SDK release and without a breaking change, so this is documented as a plain string rather than a closed enum. Treat an unrecognised value as informational: log it, display it, never crash on it, and never map "unknown" to a punitive action. Publishing a closed enum here would make our next additive release break every generated client that validates responses. The values defined today (also available machine-readably in `x-portreeve-known-values`) are: `invalid_request`, `unauthorized`, `rate_limited`, `idempotency_conflict`, `conflict`, `not_found`, `internal`.
- `message` (string, required) — Human-readable, for your logs. Never show it to an end user — on a `block` it can describe what tripped.
- `details` (map from string to any, optional) — Optional structured context. On a 400 it carries `issues[]`, an array of `{ path, message }` — one entry per validation failure.

### 404 Not Found Error

No event with that id in this tenant and mode.

- `error` (string, required) — **This is an open set.** New values ship without a new SDK release and without a breaking change, so this is documented as a plain string rather than a closed enum. Treat an unrecognised value as informational: log it, display it, never crash on it, and never map "unknown" to a punitive action. Publishing a closed enum here would make our next additive release break every generated client that validates responses. The values defined today (also available machine-readably in `x-portreeve-known-values`) are: `invalid_request`, `unauthorized`, `rate_limited`, `idempotency_conflict`, `conflict`, `not_found`, `internal`.
- `message` (string, required) — Human-readable, for your logs. Never show it to an end user — on a `block` it can describe what tripped.
- `details` (map from string to any, optional) — Optional structured context. On a 400 it carries `issues[]`, an array of `{ path, message }` — one entry per validation failure.

### 409 Conflict Error

The event already has a different `external_user_id`. The binding is write-once; this is not retryable.

- `error` (string, required) — **This is an open set.** New values ship without a new SDK release and without a breaking change, so this is documented as a plain string rather than a closed enum. Treat an unrecognised value as informational: log it, display it, never crash on it, and never map "unknown" to a punitive action. Publishing a closed enum here would make our next additive release break every generated client that validates responses. The values defined today (also available machine-readably in `x-portreeve-known-values`) are: `invalid_request`, `unauthorized`, `rate_limited`, `idempotency_conflict`, `conflict`, `not_found`, `internal`.
- `message` (string, required) — Human-readable, for your logs. Never show it to an end user — on a `block` it can describe what tripped.
- `details` (map from string to any, optional) — Optional structured context. On a 400 it carries `issues[]`, an array of `{ path, message }` — one entry per validation failure.

### 429 Too Many Requests Error

Per-key rate limit exceeded (default 600 requests/minute per API key; requests with an unparseable key are bucketed per source IP). `retry-after` and `x-ratelimit-*` headers accompany the response. Retry after the window; do not treat this as a verdict.

- `error` (string, required) — **This is an open set.** New values ship without a new SDK release and without a breaking change, so this is documented as a plain string rather than a closed enum. Treat an unrecognised value as informational: log it, display it, never crash on it, and never map "unknown" to a punitive action. Publishing a closed enum here would make our next additive release break every generated client that validates responses. The values defined today (also available machine-readably in `x-portreeve-known-values`) are: `invalid_request`, `unauthorized`, `rate_limited`, `idempotency_conflict`, `conflict`, `not_found`, `internal`.
- `message` (string, required) — Human-readable, for your logs. Never show it to an end user — on a `block` it can describe what tripped.
- `details` (map from string to any, optional) — Optional structured context. On a 400 it carries `issues[]`, an array of `{ path, message }` — one entry per validation failure.

### 500 Internal Server Error

Unhandled server error. The verdict engine itself fails open rather than 500ing — a rules bug returns `allow` with no reasons — so a 500 here means the request never reached a decision. Treat as retryable.

- `error` (string, required) — **This is an open set.** New values ship without a new SDK release and without a breaking change, so this is documented as a plain string rather than a closed enum. Treat an unrecognised value as informational: log it, display it, never crash on it, and never map "unknown" to a punitive action. Publishing a closed enum here would make our next additive release break every generated client that validates responses. The values defined today (also available machine-readably in `x-portreeve-known-values`) are: `invalid_request`, `unauthorized`, `rate_limited`, `idempotency_conflict`, `conflict`, `not_found`, `internal`.
- `message` (string, required) — Human-readable, for your logs. Never show it to an end user — on a `block` it can describe what tripped.
- `details` (map from string to any, optional) — Optional structured context. On a 400 it carries `issues[]`, an array of `{ path, message }` — one entry per validation failure.

## Examples

**Request**

```json
{
  "external_user_id": "string"
}
```

**Response**

```json
{
  "ok": true
}
```

**SDK Code**

```python
import requests

url = "https://api.portreeve.com/v1/events/id"

payload = { "external_user_id": "string" }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.portreeve.com/v1/events/id';
const options = {
  method: 'PATCH',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"external_user_id":"string"}'
};

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://api.portreeve.com/v1/events/id"

	payload := strings.NewReader("{\n  \"external_user_id\": \"string\"\n}")

	req, _ := http.NewRequest("PATCH", 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://api.portreeve.com/v1/events/id")

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

request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"external_user_id\": \"string\"\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.patch("https://api.portreeve.com/v1/events/id")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"external_user_id\": \"string\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://api.portreeve.com/v1/events/id', [
  'body' => '{
  "external_user_id": "string"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.portreeve.com/v1/events/id");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"external_user_id\": \"string\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["external_user_id": "string"] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.portreeve.com/v1/events/id")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PATCH"
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()
```