# Create or Update Subscription

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /webhooksubscription:
    post:
      summary: Create or Update Subscription
      deprecated: false
      description: >+
        ### Description :

        Client applications subscribe for webhook notifications and listen for
        the various events pertaining to their data in Beetexting, including;
        create or update contact, delete contact, and message outbound events.
        This API helps create or update subscription using "SubscriptionRequest"
        object in the request body. 
         
        ### URL : 

        https://connect.beetexting/prod/webhooksubscription

        (While sending the request please make sure to append
        https://connect.beetexting.com/prod if the url in the cUrl command
        starts with /message ...)


        **Note : To add the OAuth2.0 Auth Token please see the section 'OAuth2.0
        For Beetexting' and 'Postman How-to for Beetexting section'


        Users can subscribe to the inbound message by sending below request to
        Beetexting. 

        #### API End Point :
        https://connect.beetexting.com/prod/webhooksubscription 

        #### Method : POST

        #### Request Body:

        {
          "uri": "https://callbackurl.com/<callback>",
          "eventFilters": [
            "/orgId/<organizationId>/department/<departmentId>/message?direction=inbound"
          ],
          "expiresDateInMillies": <expireTimeInMillis>
        }


        Then, Beetexting will validate by sending a GET call to the callback
        URL, e.g. https://callbackurl.com/<callback> with a validation-token in
        the request header.

        The caller should then send a response with the same validation-token in
        the response header with https 200 status. If the response header
        validation-token matches with the request-header validation-token that
        we sent, we will then send below response for the create subscription
        call as below:

        #### Response:

        {
          "id": "<SubscriptionId>",
          "uri": "https://callbackurl.com",
          "eventFilters": [
            "/orgId/<organizationId>/department/<departmentId>/message?direction=inbound"
          ],
          "disabledFilters": [
            {
              "filter": "string",
              "reason": "string",
              "message": "string",
              "orgId": "string",
              "id": "string"
            }
          ],
          "expirationTime": "2024-03-10T18:07:52.534Z",
          "expiresIn": <expireTimeInMillis>,
          "status": "ACTIVE",
          "createdDateTime": "2023-06-10T18:07:52.534Z",
          "lastUpdateDateTime": "2023-06-10T20:07:52.534Z",
          "orgId": "<organizationId>"
        }


        With this, now the user has subscribed to get notification for any
        inbound/oubound messages.


        Once an Inbound message comes Beetexting will send the following payload
        to the above mentioned uri. 

        See below the sample payload for the inbound message

        #### Payload : 

        {
          "uuid": "<UniqueIdForMessageInfoWebhookEvent>",
          "timestamp": 1704067200000,
          "event": " "/orgId/<organizationId>/department/<departmentId>/message?direction=inbound",
          "subscriptionId": "<SubscriptionId>",
          "messageInfo": {
            "organizationId": "<organizationId>",
            "departmentId": "<departmentId>",
            "lastUpdated": 1704067200000,
            "messageId": "<messageId>",
            "carrierMessageId": "<carrierMessageId>",
            "status": "<messageStatus>"
          }
        }


        Using the messageId part of the above payload, user can call the below
        end point to get the message details.

        #### API End Point :
        https://connect.beetexting.com/prod/message/getmessagebyid/{messageId} 

        #### Method : GET

        #### Response:

        {
          "id": "<messageId>",
          "owner": "user@example.com",
          "time": "2024-01-01T12:00:00Z",
          "direction": "in",
          "to": [
            "<mobileNumber>",
            "<mobileNumber>"
          ],
          "from": "<mobileNumber>",
          "text": "<Message Text>",
          "media": [
            "<MessageRelatedMedia in String>"
          ],
          "attachments": [
            "<AttachementsRelated in String>"
          ]
        }

        #### Sample Response:

        {
            "id": "67070af782b96f464c18bc7b",
            "owner": null,
            "time": null,
            "direction": "in",
            "to": [
                "+112353623623"
            ],
            "from": "",
            "text": "Hi ",
            "media": [],
            "attachments": []
        }

      tags:
        - APIs/Webhook Subscriptions API
      parameters:
        - name: x-api-key
          in: header
          description: ''
          required: true
          example: HvG7OZaxgz3raDMzX9CYp9105hV9VwDa6zrCS234
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties: {}
            example:
              uri: https://beetexting.com
              eventFilters:
                - /orgId/<organizationId>/department/<departmentId>/contact
                - >-
                  /orgId/<organizationId>/department/<departmentId>/message?direction=outbound
              expiresDateInMillies: 0
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties: {}
              example:
                id: string
                uri: string
                eventFilters:
                  - string
                disabledFilters:
                  - filter: string
                    reason: string
                    message: string
                    orgId: string
                    id: string
                expirationTime: '2024-03-10T18:07:52.534Z'
                expiresIn: 0
                status: ACTIVE
                createdDateTime: '2023-06-10T18:07:52.534Z'
                lastUpdateDateTime: '2023-06-10T20:07:52.534Z'
                orgId: string
          headers: {}
          x-apidog-name: Success
      security:
        - oauth21: []
      x-apidog-folder: APIs/Webhook Subscriptions API
      x-apidog-status: released
      x-run-in-apidog: https://app.apidog.com/web/project/1058487/apis/api-21352087-run
components:
  schemas: {}
  securitySchemes:
    oauth21:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: ''
          tokenUrl: ''
          refreshUrl: ''
          scopes: {}
          x-apidog:
            addTokenTo: header
            useTokenType: access_token
            queryParamKey: access_token
            headerPrefix: Bearer
            codeVerifier: ''
            challengeAlgorithm: S256
            clientAuthentication: header
            useTokenConfigAsRefreshTokenConfig: true
            authRequestParams: []
            tokenRequestParams: []
servers: []
security: []

```
