> For the complete documentation index, see [llms.txt](https://docs.tnid.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tnid.com/api-reference/002_company/008_opt_out/002__create_opt_out_request.md).

# Create Opt-out Request

GraphQL endpoint: `/company`

Create an opt-out request to record a user's request to stop receiving communications. This is typically used when processing opt-out keywords (e.g., "STOP") received via SMS.

Required fields:

* `source`: The source/sender of the opt-out request (e.g., phone number)
* `destination`: The destination (e.g., company's phone number that received the request)
* `type`: The communication type (SMS, VOICE, EMAIL)
* `timestamp`: When the opt-out request was received

Optional fields:

* `externalId`: External identifier for reference
* `messageBody`: The content of the opt-out message
* `metadata`: Additional metadata as key-value pairs (flat structure only)

The request is created with status `RECEIVED`, and moves through `NOTIFIED`, `REMINDER_SENT`, `ACCEPTED`, `REJECTED`, `REVOKED` or `EXPIRED` as it is processed. Processing the opt-out may trigger removal of the user from relevant subscriptions.

## Query

```graphql
mutation (
  $source: String!
  $destination: String!
  $externalId: String
  $messageBody: String
  $type: OptOutRequestType!
  $timestamp: NaiveDateTime!
  $metadata: JSON
) {
  createOptOutRequest (
    source: $source
    destination: $destination
    externalId: $externalId
    messageBody: $messageBody
    type: $type
    timestamp: $timestamp
    metadata: $metadata
  ) {
    id
    source
    destination
    externalId
    messageBody
    type
    status
    createdAt
    updatedAt
    timestamp
    metadata
    company {
      id
    }
  }
}

```

## Variables

```json
{
  "destination": "1234130",
  "externalId": "1230",
  "messageBody": "message content",
  "metadata": {
    "test": "value"
  },
  "source": "2132130",
  "timestamp": "2024-10-04 02:52:00",
  "type": "SMS"
}
```

## Response

```json
{
  "data": {
    "createOptOutRequest": {
      "company": {
        "id": "00000000-0000-4000-8000-000000000001"
      },
      "createdAt": null,
      "destination": "1234130",
      "externalId": "1230",
      "id": "00000000-0000-4000-8000-000000000002",
      "messageBody": "message content",
      "metadata": {
        "test": "value"
      },
      "source": "2132130",
      "status": "RECEIVED",
      "timestamp": "2026-01-15T09:00:00.000000",
      "type": "SMS",
      "updatedAt": "2026-01-15T09:00:01"
    }
  }
}
```
