> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> The CometChat message import API allows customers to import their messages’ data into the CometChat systems.

# Import Messages

For the complete error reference, see [Error Guide](/articles/error-guide).


## OpenAPI

````yaml post /data_import/messages
openapi: 3.0.0
info:
  title: Data Import APIs
  description: Manage messages, users, groups for a particular app using our Chat API.
  version: '3.0'
servers:
  - url: https://{appId}.api-{region}.cometchat.io/v3
    variables:
      appId:
        default: appId
        description: (Required) App ID
      region:
        enum:
          - us
          - eu
          - in
        default: us
        description: Select Region
security: []
tags:
  - name: API Keys
    description: The API keys are used to authorise the APIs
  - name: Roles
    description: The roles are used to give user access rights
  - name: Users
    description: The REST collection for users.
  - name: Auth Tokens
    description: The auth tokens are used to login end users using client SDKs.
  - name: Blocked Users
    description: The REST collections for blocked users.
  - name: Friends
    description: List,add and remove friends by passing UID in path variables
  - name: Groups
    description: The REST collections for groups.
  - name: Banned Users
    description: Ban and Unban user by passing other UID in path variables.
  - name: Group Members
    description: The REST collections for group members.
  - name: Messages
    description: The REST collections for messages.
  - name: Conversations
    description: The REST collections for conversations.
  - name: Restrict Features
    description: Allows Restricting Features
  - name: Metrics
    description: Allows accessing Data Metrics
  - name: Triggers
    description: Allows adding triggers to a webhook.
  - name: Webhooks
    description: Allows accessing Webhooks.
  - name: Push Notifications
    description: Allows configuring Push Notifications.
paths:
  /data_import/messages:
    post:
      tags:
        - Messages
      summary: Import Messages
      description: >-
        The CometChat message import API allows customers to import their
        messages’ data into the CometChat systems.
      operationId: import-messages
      requestBody:
        content:
          application/json:
            schema:
              required:
                - guid
                - name
                - type
              properties:
                messages:
                  description: Wrapper for the messages.
                  required:
                    - muid
                  properties:
                    <muid>:
                      description: >-
                        Wraps a single message object. The <b>&lt;muid&gt;</b>
                        will be a primary key/unique Identifier of the message.
                      required:
                        - muid
                        - sender
                        - receiverType
                        - receiver
                        - sentAt
                      properties:
                        muid:
                          description: >-
                            The value should be the same as value of the
                            placeholder <b>&lt;muid&gt;</b> which wraps the
                            message object.
                          type: string
                        sender:
                          description: UID of the sender.
                          type: string
                        receiverType:
                          description: >-
                            The receiverType of the message. either user or
                            group
                          type: string
                          enum:
                            - user
                            - group
                        receiver:
                          description: >-
                            If the receiverType == “user” the UID of a user
                            receiving the message. else GUID of the group.
                          type: string
                        category:
                          description: >-
                            Category of the message. The available categories
                            are message and custom.
                          type: string
                          enum:
                            - message
                            - custom
                        type:
                          description: >-
                            If category==”message” then the allowed values for
                            the type are: text: for a plain text message. image:
                            for an image message audio: for an audio message
                            video: for a video message file: for any file if
                            category==”custom” the customized type can be used.
                            The developer can send the type as any random string
                            and can use it in the implementation at the UI
                          type: string
                          enum:
                            - text
                            - image
                            - file
                            - audio
                            - video
                        data:
                          description: >-
                            Can contain any additional properties except for the
                            key properties.
                          properties:
                            text:
                              description: >-
                                The property has a fixed meaning for: 1.
                                category==”message” && type ==”text” ⇒ it stores
                                the text message 2. category==”message” && type
                                !=”text” ⇒ it stores a caption for the
                                attachment
                              type: string
                            customData:
                              description: >-
                                when category==”custom”, this property can have
                                any JSON object.
                              type: object
                            attachments:
                              description: >-
                                For the messages with image, video, audio or
                                file type (i.e. category=="message" && type
                                !="text"), the property contains an array of
                                attachment objects.
                              type: array
                              items:
                                required:
                                  - name
                                  - mimeType
                                  - extension
                                  - url
                                properties:
                                  url:
                                    description: >-
                                      Contains the URL of the attachment. The
                                      developer has to make sure that the URL is
                                      accessible while calling the data_import
                                      API. The API will be downloading the
                                      attachment from its current location and
                                      upload it to CometChat’s attachment
                                      storage.
                                    type: string
                                  name:
                                    description: Name of the attachment.
                                    type: string
                                  mimeType:
                                    description: Mime Type of attachment.
                                    type: string
                                  extension:
                                    description: The extension of the attachment.
                                    type: string
                                  size:
                                    description: The size of the attachment(in bytes).
                                    type: string
                                type: object
                            metadata:
                              type: object
                          type: object
                        tags:
                          description: String array containing developer defined tags.
                          type: array
                          items:
                            type: string
                        sentAt:
                          description: >-
                            10-digit UNIX timestamp for the time at which the
                            message was sent.
                          type: integer
                        deliveredAt:
                          description: >-
                            A 10-digit UNIX timestamp at which the message was
                            delivered to the receiver.
                          type: integer
                        readAt:
                          description: >-
                            A 10-digit UNIX timestamp at which the message was
                            read by the receiver.
                          type: integer
                        senderUserDetails:
                          description: >-
                            If all the users are imported before importing the
                            messages. The JSON object contains the user details
                            of the sender.
                          required:
                            - uid
                            - name
                          properties:
                            uid:
                              description: >-
                                The primary-key/ unique identifier of the
                                sender.
                              type: string
                            name:
                              description: Name of the sender.
                              type: string
                            avatar:
                              description: >-
                                URL to the profile picture of the user sending
                                the message.
                              type: string
                            link:
                              description: Profile page URL of the sender.
                              type: string
                            role:
                              description: >-
                                Role of the sender. Should be created already
                                via the Create role API.
                              type: string
                            createdAt:
                              description: >-
                                A 10-digit timestamp at which the sender was
                                created.
                              type: integer
                            lastActiveAt:
                              description: >-
                                A 10-digit UNIX timestamp at which the sender
                                was most recently online.
                              type: integer
                            metadata:
                              description: Additional details about the sender.
                              type: object
                            tags:
                              description: A string array containing sender tags.
                              type: array
                              items:
                                type: string
                              default: []
                            deactivatedAt:
                              description: >-
                                A 10-digit UNIX timestamp at which the sender
                                was deactivated/soft-deleted/blocked to use the
                                chat services.
                              type: integer
                          type: object
                        receiverUserDetails:
                          description: >-
                            If all the users are imported before importing the
                            messages or else required if receiverType==”user”.
                            The JSON object contains the user details of the
                            receiver.
                          required:
                            - uid
                            - name
                          properties:
                            uid:
                              description: >-
                                The primary-key/ unique identifier of the user
                                receiving the message.
                              type: string
                            name:
                              description: Name of the receiver.
                              type: string
                            avatar:
                              description: ' URL to the profile picture of the receiver.'
                              type: string
                            link:
                              description: Profile page URL of the receiver.
                              type: string
                            role:
                              description: >-
                                Role of the receiver. Should be created already
                                via the Create role API.
                              type: string
                            createdAt:
                              description: >-
                                A 10-digit timestamp at which the receiver was
                                created.
                              type: integer
                            lastActiveAt:
                              description: >-
                                A 10-digit UNIX timestamp at which the receiver
                                was most recently online.
                              type: integer
                            metadata:
                              description: Additional details about the receiver.
                              type: object
                            tags:
                              description: A string array containing receiver tags.
                              type: array
                              items:
                                type: string
                              default: []
                            deactivatedAt:
                              description: >-
                                A 10-digit UNIX timestamp at which the receiver
                                was deactivated/soft-deleted/blocked to use the
                                chat services.
                              type: integer
                          type: object
                        receiverGroupDetails:
                          description: >-
                            The JSON object contains the group details of the
                            receiver.
                          required:
                            - guid
                            - name
                            - type
                          properties:
                            guid:
                              description: The primary-key/ unique identifier of the group.
                              type: string
                            name:
                              description: Name of the group.
                              type: string
                            icon:
                              description: An URL for a group icon.
                              type: string
                            type:
                              description: >-
                                Type of the group. Can be public, password or
                                private.
                              type: string
                              enum:
                                - public
                                - password
                                - private
                            password:
                              description: >-
                                A password required to join the the group with
                                type password
                              type: string
                            owner:
                              description: Owner of the group.
                              type: string
                            createdAt:
                              description: ' A 10-digit UNIX timestamp at which the group was created.'
                              type: integer
                            metadata:
                              description: Additional data for the group.
                              type: object
                            tags:
                              description: A string array containing grouptags.
                              type: array
                              items:
                                type: string
                              default: []
                          type: object
                        receiverGroupOwnerDetails:
                          description: >-
                            The JSON object contains the user details of the
                            owner.
                          required:
                            - uid
                            - name
                          properties:
                            uid:
                              description: The primary-key/ unique identifier of the owner.
                              type: string
                            name:
                              description: Name of the owner.
                              type: string
                            avatar:
                              description: URL to the profile picture of the owner.
                              type: string
                            link:
                              description: Profile page URL of the owner.
                              type: string
                            role:
                              description: >-
                                Role of the owner. Should be created already via
                                the Create role API.
                              type: string
                            createdAt:
                              description: >-
                                A 10-digit timestamp at which the owner was
                                created.
                              type: integer
                            lastActiveAt:
                              description: >-
                                A 10-digit UNIX timestamp at which the owner was
                                most recently online.
                              type: integer
                            metadata:
                              description: Additional details about the owner.
                              type: object
                            tags:
                              description: A string array containing owner tags.
                              type: array
                              items:
                                type: string
                              default: []
                            deactivatedAt:
                              description: >-
                                A 10-digit UNIX timestamp at which the owner was
                                deactivated/soft-deleted/blocked to use the chat
                                services.
                              type: integer
                          type: object
                      type: object
                  type: object
                  example:
                    '3118':
                      muid: '3118'
                      sender: s12
                      receiverType: user
                      receiver: r123
                      type: text
                      category: message
                      data:
                        text: Hi there,
                        attachments:
                          - name: hi.png
                            extension: png
                            size: '350.2'
                            mimeType: image/png
                            url: >-
                              https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp
                        metadata:
                          key: value
                        custodata:
                          key: value
                      sentAt: '1674104348'
                      deliveredAt: '1674224684'
                      readAt: '1674224684'
                      senderUserDetails:
                        uid: s12
                        name: user1
                        avatar: >-
                          https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp
                        createdAt: '1674228536'
                        metadata:
                          key: value
                      receiverUserDetails:
                        uid: r123
                        name: cometchat-uid-
                        type: public
                        description: Hello group
                        icon: >-
                          https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp
                        owner: cometchat-uid-1
                        avatar: >-
                          https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp
                        createdAt: '1674228536'
                        metadata:
                          key: value
                      tags:
                        - tag1
              type: object
      responses:
        '200':
          description: Import Message(s)
          content:
            application/json:
              schema:
                properties:
                  data:
                    properties:
                      <muid>:
                        type: object
                        allOf:
                          - properties:
                              sentAt:
                                type: integer
                                description: Unix timestamp
                              deliveredAt:
                                type: integer
                                description: Unix timestamp
                              readAt:
                                type: integer
                                description: Unix timestamp
                            type: object
                          - $ref: '#/components/schemas/messageSchema'
                    type: object
                type: object
              example:
                data:
                  '3117':
                    success: true
                    data:
                      id: '1029'
                      muid: '3117'
                      conversationId: r123_user_s12
                      sender: s12
                      receiverType: user
                      receiver: r123
                      category: message
                      type: text
                      data:
                        text: Hi there,
                        attachments:
                          - name: hi.png
                            extension: png
                            size: '350.2'
                            mimeType: image/png
                            url: >-
                              https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp
                        metad2ata:
                          key: value
                        custodata:
                          key: value
                        entities:
                          sender:
                            entity:
                              uid: s12
                              name: user1
                              avatar: >-
                                https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp
                              metadata:
                                key: value
                              status: offline
                              role: default
                              createdAt: 1674228536
                              updatedAt: 1674232131
                            entityType: user
                          receiver:
                            entity:
                              uid: r123
                              name: cometchat-uid-
                              avatar: >-
                                https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp
                              metadata:
                                key: value
                              status: offline
                              role: default
                              createdAt: 1674228536
                              updatedAt: 1674232131
                              conversationId: r123_user_s12
                            entityType: user
                      sentAt: 1674104348
                      deliveredAt: 1674224684
                      readAt: 1674224684
                      updatedAt: 1674104348
                      tags:
                        - tag1
      security:
        - apiKey: []
components:
  schemas:
    messageSchema:
      description: Response data
      properties:
        id:
          type: string
        conversationId:
          type: string
        sender:
          type: string
        receiverType:
          type: string
        receiver:
          type: string
        category:
          type: string
        type:
          type: string
        data:
          properties:
            text:
              type: string
            metadata:
              type: object
            entities:
              properties:
                sender:
                  properties:
                    entity:
                      properties:
                        uid:
                          type: string
                        name:
                          type: string
                        role:
                          type: string
                        avatar:
                          type: string
                        status:
                          type: string
                        createdAt:
                          type: integer
                        conversationId:
                          type: string
                      type: object
                    entityType:
                      type: string
                  type: object
                receiver:
                  properties:
                    entity:
                      properties:
                        uid:
                          type: string
                        name:
                          type: string
                        role:
                          type: string
                        avatar:
                          type: string
                        status:
                          type: string
                        createdAt:
                          type: integer
                        conversationId:
                          type: string
                      type: object
                    entityType:
                      type: string
                  type: object
              type: object
          type: object
        sentAt:
          type: integer
        updatedAt:
          type: integer
      type: object
  securitySchemes:
    apiKey:
      type: apiKey
      description: API Key with fullAccess scope(i.e. Rest API Key from the Dashboard).
      name: apikey
      in: header

````