openapi: 3.0.0
info:
  description: Hootsuite Inbox REST API for 3rd-party CRM app integrations
  version: "1.0"
  title: CRM App Integrations API
  x-spec-id: crm-public-api
  x-sdk-id: crm-public-api
  x-sdk-name: crm_public_api
  contact:
    email: dev.support@hootsuite.com
  license:
    name: Hootsuite Developer Terms and API License Agreement
    url: https://hootsuite.com/legal/dev-api-terms
servers:
  - url: https://platform.hootsuite.com
security:
  - OAuth2: []
tags:
  - name: crm-public-api
    description: Hootsuite Inbox REST API for 3rd-party CRM app integrations
    x-displayName: CRM
paths:
  /v1/crm/connect:
    post:
      tags:
        - crm-public-api
      operationId: connectCRM
      summary: Connect a CRM account to Hootsuite
      description: |
        Connect a CRM account to Hootsuite. The connection's CRM-ID is returned.
        Valid client-credentials for communication from Hootsuite to your service must be provided,  otherwise a 422 error will be returned. The credentials will be used in a call to your service's [/v1/oauth2/token](/api-reference/external-apps/oauth-2-token/) API and this must return a valid token for the credentials to be accepted.
      security:
        - OAuth2: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - orgId
                - appId
                - instanceUrl
                - oauth2ClientId
                - oauth2ClientSecret
              properties:
                orgId:
                  type: string
                  description: Hootsuite organization ID
                appId:
                  type: integer
                  format: int64
                  description: Hootsuite app ID for this CRM app
                instanceUrl:
                  type: string
                  format: uri
                  example: https://hootsuite.example.com
                  description: |
                    Customer-specific instance url for this integration.  This will be provided in requests to /v1/oauth2/token.
                oauth2ClientId:
                  type: string
                  example: client-id
                  description: |
                    Client-credentials Hootsuite can exchange via /v1/oauth2/token for a valid access token to  /v1/case and other CRM APIs.
                oauth2ClientSecret:
                  type: string
                  example: client-secret
                  description: See above
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                required:
                  - crmId
                properties:
                  crmId:
                    type: string
                    format: uuid
                    description: CRM-ID to identify this integration instance in future API requests.
        "400":
          description: Bad request
        "422":
          description: Invalid argument.
        default:
          description: Unexpected error.
  /v1/crm/{crmId}/webhook:
    post:
      tags:
        - crm-public-api
      operationId: crmWebhook
      summary: CRM integration webhook
      description: |
        Webhook for CRM integrations to call.
        A CaseCreated event MUST be sent once a request to your service's [/v1/case](/api-reference/external-apps/create-case/) API has finished processing. In the event of an error, the Error event may be sent to indicate this to Hootsuite.
      security:
        - OAuth2: []
      parameters:
        - in: path
          name: crmId
          schema:
            type: string
          required: true
          description: CRM-ID
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - events
              properties:
                events:
                  type: array
                  items:
                    anyOf:
                      - type: object
                        description: Event to send after a request to /v1/case was successfully processed.
                        required:
                          - eventType
                          - timestamp
                          - version
                          - conversationId
                        properties:
                          eventType:
                            type: string
                          timestamp:
                            type: string
                            format: date-time
                          version:
                            type: number
                            default: 1
                          caseId:
                            type: string
                          crmContactId:
                            type: string
                          conversationId:
                            type: string
                          caseNumber:
                            type: string
                          caseApiName:
                            type: string
                            nullable: true
                      - type: object
                        description: Event to send when a case is closed.
                        required:
                          - eventType
                          - timestamp
                          - version
                          - conversationId
                        properties:
                          eventType:
                            type: string
                          timestamp:
                            type: string
                            format: date-time
                          version:
                            type: number
                            default: 1
                          caseId:
                            type: string
                          conversationId:
                            type: string
                      - type: object
                        description: Event to send when an error occurred.
                        required:
                          - eventType
                          - timestamp
                          - version
                        properties:
                          eventType:
                            type: string
                          timestamp:
                            type: string
                            format: date-time
                          version:
                            type: number
                            default: 1
                          reason:
                            type: string
                            description: Human readable reason
                          command:
                            properties:
                              commandType:
                                type: string
                              version:
                                type: number
                                default: 1
                              createdByMember:
                                type: object
                                properties:
                                  name:
                                    type: string
                                  email:
                                    type: string
                              conversationId:
                                type: string
                      - type: object
                        description: |
                          Event to send when the integration is uninstalled on the CRM side. Hootsuite will disconnect the integration when it receives this event.
                        required:
                          - eventType
                          - timestamp
                          - version
                        properties:
                          eventType:
                            type: string
                          timestamp:
                            type: string
                            format: date-time
                          version:
                            type: number
                            default: 1
                      - type: object
                        description: Test event to verify the connection is functioning.
                        required:
                          - eventType
                          - timestamp
                          - version
                        properties:
                          eventType:
                            type: string
                          timestamp:
                            type: string
                            format: date-time
                          version:
                            type: number
                            default: 1
                    discriminator:
                      propertyName: eventType
                      mapping:
                        CASE_CREATED: "#/components/schemas/CaseCreated"
                        CASE_CLOSED: "#/components/schemas/CaseClosed"
                        ERROR: "#/components/schemas/Error"
                        APP_UNINSTALLED: "#/components/schemas/AppUninstalled"
                        VERIFY: "#/components/schemas/Verify"
      responses:
        "200":
          description: Webhook event(s) processed.
        default:
          description: Unexpected error.
  /v1/crm/{crmId}/contact/custom-attribute:
    get:
      tags:
        - crm-public-api
      operationId: getCustomContactAttribute
      summary: Get custom attributes definitions
      description: |
        This endpoint returns Inbox attribute definitions for the corresponding CRM-ID. 
        Your app should configure a mapping from these attributes to the corresponding attributes in your CRM platform. Hootsuite will provided these attributes in a call to /v1/case.
      security:
        - OAuth2: []
      parameters:
        - in: path
          name: crmId
          schema:
            type: string
          required: true
          description: CRM-ID
      responses:
        "200":
          description: Successful operation.
          content:
            application/json:
              schema:
                type: object
                description: Attribute definitions defined by the customer in Inbox.
                properties:
                  attributes:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        type:
                          type: string
                          enum:
                            - STANDARD
                            - CUSTOM
                            - NETWORK
                        identifier:
                          type: string
                        name:
                          type: string
                        icon:
                          type: string
                        entryMethod:
                          nullable: true
                          type: string
                          enum:
                            - FREEFORM
                            - DROPDOWN
                        freeForm:
                          nullable: true
                          type: object
                          properties:
                            validatorType:
                              type: string
                              enum:
                                - EMAIL
                                - PHONENUMBER
                                - URL
                                - NUMBER
                                - DATE
                                - NONE
                                - BOOLEAN
                            charLimit:
                              type: integer
                        dropdown:
                          nullable: true
                          type: object
                          properties:
                            options:
                              type: array
                              items:
                                type: object
                                properties:
                                  id:
                                    type: string
                                  value:
                                    type: string
                                  displayName:
                                    type: string
                        crmLookup:
                          type: boolean
                        enabled:
                          type: boolean
                        createdAt:
                          type: string
                        updatedAt:
                          type: string
        "400":
          description: Bad request.
        default:
          description: Unexpected error.
components:
  securitySchemes:
    OAuth2:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: https://platform.hootsuite.com/oauth2/auth
          tokenUrl: https://platform.hootsuite.com/oauth2/token
          scopes:
            offline: Request refresh tokens
            analytics:read: Request analytics API access
  schemas:
    CaseCreated:
      type: object
      description: Event to send after a request to /v1/case was successfully processed.
      required:
        - eventType
        - timestamp
        - version
        - conversationId
      properties:
        eventType:
          type: string
        timestamp:
          type: string
          format: date-time
        version:
          type: number
          default: 1
        caseId:
          type: string
        crmContactId:
          type: string
        conversationId:
          type: string
        caseNumber:
          type: string
        caseApiName:
          type: string
          nullable: true
    CaseClosed:
      type: object
      description: Event to send when a case is closed.
      required:
        - eventType
        - timestamp
        - version
        - conversationId
      properties:
        eventType:
          type: string
        timestamp:
          type: string
          format: date-time
        version:
          type: number
          default: 1
        caseId:
          type: string
        conversationId:
          type: string
    Error:
      type: object
      description: Event to send when an error occurred.
      required:
        - eventType
        - timestamp
        - version
      properties:
        eventType:
          type: string
        timestamp:
          type: string
          format: date-time
        version:
          type: number
          default: 1
        reason:
          type: string
          description: Human readable reason
        command:
          properties:
            commandType:
              type: string
            version:
              type: number
              default: 1
            createdByMember:
              type: object
              properties:
                name:
                  type: string
                email:
                  type: string
            conversationId:
              type: string
    AppUninstalled:
      type: object
      description: |
        Event to send when the integration is uninstalled on the CRM side. Hootsuite will disconnect the integration when it receives this event.
      required:
        - eventType
        - timestamp
        - version
      properties:
        eventType:
          type: string
        timestamp:
          type: string
          format: date-time
        version:
          type: number
          default: 1
    Verify:
      type: object
      description: Test event to verify the connection is functioning.
      required:
        - eventType
        - timestamp
        - version
      properties:
        eventType:
          type: string
        timestamp:
          type: string
          format: date-time
        version:
          type: number
          default: 1
