# Add subscription to a contact

`POST /contacts/{contact_id}/subscriptions`

> This is a subset of the full specification, limited to the `POST /contacts/{contact_id}/subscriptions` operation.
>
> You can find the full specification here: /_bundle/docs/references/@2.12/rest-api/api.intercom.io.yaml

```yaml
openapi: 3.0.1
info:
  title: Intercom API
  version: '2.12'
  description: This is a subset of the full specification, limited to the `POST /contacts/{contact_id}/subscriptions` operation.
  contact:
    name: Intercom Developer Hub
    url: https://developers.intercom.com
  license:
    name: MIT
    url: https://spdx.org/licenses/MIT
servers:
  - url: https://api.intercom.io
    description: The production API server
  - url: https://api.eu.intercom.io
    description: The european API server
  - url: https://api.au.intercom.io
    description: The australian API server
security:
  - bearerAuth: []
tags:
  - name: Contacts
    description: Everything about your contacts
  - name: Subscription Types
    description: Everything about subscription types
paths:
  /contacts/{contact_id}/subscriptions:
    post:
      summary: Add subscription to a contact
      tags:
        - Subscription Types
        - Contacts
      parameters:
        - name: Intercom-Version
          in: header
          schema:
            $ref: '#/components/schemas/intercom_version'
        - name: contact_id
          in: path
          description: The unique identifier for the contact which is given by Intercom
          example: 63a07ddf05a32042dffac965
          required: true
          schema:
            type: string
      operationId: attachSubscriptionTypeToContact
      description: |
        You can add a specific subscription to a contact. In Intercom, we have two different subscription types based on user consent - opt-out and opt-in:

          1.Attaching a contact to an opt-out subscription type will opt that user out from receiving messages related to that subscription type.

          2.Attaching a contact to an opt-in subscription type will opt that user in to receiving messages related to that subscription type.

        This will return a subscription type model for the subscription type that was added to the contact.
      responses:
        '200':
          description: Successful
          content:
            application/json:
              examples:
                Successful:
                  value:
                    type: subscription
                    id: '16'
                    state: live
                    consent_type: opt_in
                    default_translation:
                      name: Newsletters
                      description: Lorem ipsum dolor sit amet
                      locale: en
                    translations:
                      - name: Newsletters
                        description: Lorem ipsum dolor sit amet
                        locale: en
                    content_types:
                      - sms_message
              schema:
                $ref: '#/components/schemas/subscription_type'
        '401':
          description: Unauthorized
          content:
            application/json:
              examples:
                Unauthorized:
                  value:
                    type: error.list
                    request_id: 49a772ef-b946-4a79-8399-c7167c6ebdec
                    errors:
                      - code: unauthorized
                        message: Access Token Invalid
              schema:
                $ref: '#/components/schemas/error'
        '404':
          description: Resource not found
          content:
            application/json:
              examples:
                Contact not found:
                  value:
                    type: error.list
                    request_id: 7651481f-6f68-41b5-b808-8edd118f88cb
                    errors:
                      - code: not_found
                        message: User Not Found
                Resource not found:
                  value:
                    type: error.list
                    request_id: 41900b95-2170-49cf-b995-69e4f8af04d1
                    errors:
                      - code: not_found
                        message: Resource Not Found
              schema:
                $ref: '#/components/schemas/error'
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - id
                - consent_type
              properties:
                id:
                  type: string
                  description: The unique identifier for the subscription which is given by Intercom
                  example: '37846'
                consent_type:
                  type: string
                  description: The consent_type of a subscription, opt_out or opt_in.
                  example: opt_in
            examples:
              successful:
                summary: Successful
                value:
                  id: 16
                  consent_type: opt_in
              contact_not_found:
                summary: Contact not found
                value:
                  id: 20
                  consent_type: opt_in
              resource_not_found:
                summary: Resource not found
                value:
                  id: invalid_id
                  consent_type: opt_in
components:
  schemas:
    error:
      type: object
      title: Error
      description: The API will return an Error List for a failed request, which will contain one or more Error objects.
      properties:
        type:
          type: string
          description: The type is error.list
          example: error.list
        request_id:
          type: string
          nullable: true
          format: uuid
          description: ''
          example: f93ecfa8-d08a-4325-8694-89aeb89c8f85
        errors:
          type: array
          description: An array of one or more error objects
          items:
            properties:
              code:
                type: string
                description: A string indicating the kind of error, used to further qualify the HTTP response code
                example: unauthorized
              message:
                type: string
                nullable: true
                description: Optional. Human readable description of the error.
                example: Access Token Invalid
              field:
                type: string
                nullable: true
                description: Optional. Used to identify a particular field or query parameter that was in error.
                example: email
            required:
              - code
      required:
        - type
        - errors
    intercom_version:
      description: Intercom API version.</br>By default, it's equal to the version set in the app package.
      type: string
      example: '2.12'
      default: '2.12'
      enum:
        - '1.0'
        - '1.1'
        - '1.2'
        - '1.3'
        - '1.4'
        - '2.0'
        - '2.1'
        - '2.2'
        - '2.3'
        - '2.4'
        - '2.5'
        - '2.6'
        - '2.7'
        - '2.8'
        - '2.9'
        - '2.10'
        - '2.11'
        - '2.12'
        - Preview
    subscription_type:
      title: Subscription Types
      type: object
      x-tags:
        - Subscription Types
      description: A subscription type lets customers easily opt out of non-essential communications without missing what's important to them.
      properties:
        type:
          type: string
          description: The type of the object - subscription
          example: subscription
        id:
          type: string
          description: The unique identifier representing the subscription type.
          example: '123456'
        state:
          type: string
          description: The state of the subscription type.
          enum:
            - live
            - draft
            - archived
          example: live
        default_translation:
          $ref: '#/components/schemas/translation'
        translations:
          type: array
          description: An array of translations objects with the localised version of the subscription type in each available locale within your translation settings.
          items:
            $ref: '#/components/schemas/translation'
        consent_type:
          type: string
          description: Describes the type of consent.
          enum:
            - opt_out
            - opt_in
          example: opt_in
        content_types:
          type: array
          description: The message types that this subscription supports - can contain `email` or `sms_message`.
          items:
            type: string
            enum:
              - email
              - sms_message
            example: email
    translation:
      title: Translation
      type: object
      description: A translation object contains the localised details of a subscription type.
      properties:
        name:
          type: string
          description: The localised name of the subscription type.
          example: Announcements
        description:
          type: string
          description: The localised description of the subscription type.
          example: Offers, product and feature announcements
        locale:
          type: string
          description: The two character identifier for the language of the translation object.
          example: en
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
```
