# Client diagnostics and communication consent

Upload a diagnostic for an acknowledged crash and manage communication preferences for an explicitly bound app user.

Source: https://appportal.io/docs/api/client-controls

The [operation reference](https://appportal.io/docs/api/reference/client-controls) and
[OpenAPI JSON](https://appportal.io/docs/api/contracts/client-controls.json) describe diagnostic uploads and existing
communication-preference operations at `https://api.appportal.io`. Use the framework SDK for normal
application delivery.

## Upload an acknowledged crash diagnostic

Deliver the crash first. Its `Accepted` or `AlreadyAccepted` acknowledgement includes an
`occurrenceFingerprint`. Keep that exact value with the diagnostic's journal entry and send it as
`X-AppPortal-Diagnostic-Crash-Occurrence` when calling
`PUT /v1/ingest/crashes/{crashId}/attachments/{attachmentId}`.

The fingerprint is non-secret correlation for one durable crash generation, not a credential.
Authenticate with the app/environment SDK key in `X-AppPortal-SDK-Key` and its `TelemetryIngest`
permission. Both path IDs are opaque and case-sensitive. A delayed upload must not attach to a
new occurrence that reuses the crash ID.

Send strictly UTF-8 `text/plain` or valid `application/json`. JSON scalars and arrays are valid
JSON diagnostics too. Binary dumps and archives are not supported here. The compiled defaults
are 1 MiB per attachment, five attachments and 5 MiB total per occurrence; deployments can configure
these limits. They measure bytes, including after processing, rather than character count.

`X-AppPortal-Diagnostic-File-Name` is optional display metadata, never a storage key. The response
contains an opaque `attachmentRef`, processed display name, content type, byte size, upload time
and sanitization state. The supplied attachment ID and Blob storage keys are not returned.

Fixed credential-safety processing applies before storage. Application-specific PII filtering
and collection consent remain your application's and SDK's responsibilities. A stored diagnostic
is text context, not a debug-symbol upload or proof of a resolved native stack.

## Interpret the attachment outcome

| Response | Delivery action |
| --- | --- |
| `201` | New attachment stored; retire this journal row |
| `200` | The same processed bytes were already stored; retire this row |
| `409` with `Retry-After` | Retain and retry with bounded backoff |
| `409` occurrence mismatch or retired storage generation | Quarantine or retire this item; never rebind it to another crash generation |
| `409` cleanup/schema prerequisite | Retain with conservative backoff and surface the configuration diagnostic |
| `409` unsupported provider retention | Do not retry until the applicable provider configuration changes |
| `409` different content under the same ID | Quarantine or retire the conflicting item |
| `410` | The owning crash expired; retire the orphaned diagnostic |
| `400`, `413` or `415` | Repair or quarantine this item; retrying it unchanged does not fix validation or size limits |
| `401` or `403` | Pause delivery and surface the credential/permission problem |
| `503` temporary v1 | Retain unacknowledged entries and honor the response's retry deadline |

Inspect the exact error code and optional header, not only `409`. Temporary lease contention
uses `Retry-After: 1`; a missing durable crash/generation or changed storage generation uses `2`.
A policy-related temporary `503` follows the existing unsigned v1 contract with a minimum one-hour
delay. It does not authorize queue purge or collection disablement.

Diagnostic storage fails closed when retention cleanup is not armed, its schema is unavailable or
the provider cannot transactionally couple crash expiry to diagnostic cleanup.

## Read or update communication preferences

`GET /v1/consent/{userId}` reads the bound user's stored channel preferences;
`PUT /v1/consent/{userId}` changes one preference. These operations require the SDK credential's
`MessageCenter` permission plus a separate user-installation binding. They do not expose Message
Center messages or send a campaign.

Your authenticated backend issues the binding through
[Automation user bindings](https://appportal.io/docs/api/reference/automation). Request the exact `ConsentRead` or
`ConsentWrite` operation needed. Keep the confidential Automation credential on that backend.
The installed app sends the returned binding in `X-AppPortal-User-Binding` and its exact installation
in `X-AppPortal-Installation-Id`. Percent-encode the exact opaque user ID once as a path segment;
do not change its case, substitute an email/name or infer another user's authority.

An update supplies a defined `channel`, non-null `granted` decision and non-whitespace `source`.
The v1 channel vocabulary is `MessageCenter`, `Push` and `Sms`. A successful response is the updated
preference for the credential's app and bound subject. An authorized empty read means no preferences
are stored for that subject; an unavailable authority returns an error, not an empty list.

Missing/invalid bindings return `401`; subject, scope or operation mismatch returns `403`.
An unavailable binding or organization-policy authority returns `503`. A denied communication-policy
operation returns `423`. Refresh authority through your backend when appropriate; a caller-controlled
bound-user header cannot replace validation.

## Keep the three decisions separate

Communication consent controls a channel preference. Local SDK collection consent controls telemetry
capture and delivery. Local **Reset** pauses delivery and invalidates unfinished captures; local
**Denied** clears the SDK queue. Neither communication preferences nor those local decisions erase
retained server data. Server-held data requires a separate privacy request.
