> 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/001_user/009_subscriptions/006__upsert_b2c_subscription.md).

# Upsert B2C Subscription

GraphQL endpoint: `/user`

Creates or updates a B2C subscription directly, without going through the request/response flow. The subscription type (EMAIL, SMS, VOICE) determines the required contact reference: emailId for EMAIL, telephoneNumberId for SMS/VOICE. Optionally accepts an expiration date and a notification time window. If a subscription already exists for this company/type combination it is updated; otherwise a new one is created.

## Query

```graphql
mutation (
  $companyId: ID!
  $type: B2cSubscriptionType!
  $emailId: ID
  $telephoneNumberId: ID
  $subscriptionTopicIds: [ID!]!
  $expirationDate: Date
  $notificationStartTime: Time
  $notificationEndTime: Time
) {
  upsertB2cSubscription (
    companyId: $companyId
    type: $type
    emailId: $emailId
    telephoneNumberId: $telephoneNumberId
    subscriptionTopicIds: $subscriptionTopicIds
    expirationDate: $expirationDate
    notificationStartTime: $notificationStartTime
    notificationEndTime: $notificationEndTime
    ) {
      ... on B2cEmailSubscription {
        id
        insertedAt
        updatedAt
        type
        subscriptionTopics
        expirationDate
        notificationStartTime
        notificationEndTime
        email
        company {
          id
        }
        user {
          id
        }
      }

      ... on B2cSmsSubscription {
        id
        insertedAt
        updatedAt
        type
        subscriptionTopics
        expirationDate
        notificationStartTime
        notificationEndTime
        telephoneNumber
        company {
          id
        }
        user {
          id
        }
      }

      ... on B2cVoiceSubscription {
        id
        insertedAt
        updatedAt
        type
        subscriptionTopics
        expirationDate
        notificationStartTime
        notificationEndTime
        telephoneNumber
        company {
          id
        }
        user {
          id
        }
      }
    }
  }

```

## Variables

```json
{
  "companyId": "00000000-0000-4000-8000-000000000001",
  "emailId": "00000000-0000-4000-8000-000000000006",
  "expirationDate": "2030-12-31",
  "notificationEndTime": "16:00:00",
  "notificationStartTime": "08:00:00",
  "subscriptionTopicIds": [
    "00000000-0000-4000-8000-000000000004",
    "00000000-0000-4000-8000-000000000005"
  ],
  "type": "EMAIL"
}
```

## Response

```json
{
  "data": {
    "upsertB2cSubscription": {
      "company": {
        "id": "00000000-0000-4000-8000-000000000001"
      },
      "email": "test1@email.com",
      "expirationDate": "2030-12-31",
      "id": "00000000-0000-4000-8000-000000000002",
      "insertedAt": "2026-01-15T09:00:00",
      "notificationEndTime": "16:00:00",
      "notificationStartTime": "08:00:00",
      "subscriptionTopics": [
        "topic_2",
        "topic_3"
      ],
      "type": "EMAIL",
      "updatedAt": "2026-01-15T09:00:00",
      "user": {
        "id": "00000000-0000-4000-8000-000000000003"
      }
    }
  }
}
```
