Hello 👋🏼 How can we help?

Create message

Post messages to any chat on behalf of a customer or agent
Written by Konstantine
Updated 4 months ago

You can post messages to any chat on behalf of a customer or an agent. To find a customer, use Search for customers method. To find a chat, use Search for chats method.

➡️ Request

URL https://api.helpcrunch.com/v1/messages
Method POST
Headers Authorization: Bearer <your_api_key>

Read more about authorization header here.

Chat id and message attributes should be placed to the body of your POST request. Check the example below.

{
    "chat": 5215261,
    "text": "Can you can a can as a canner can can a can?",
    "markdownText": "Can you can a **can** as a canner can can a **can**",
    "agent": 4188,
    "type": "message"
}

chat, text, agent and type are required when you create a message from agent. For customer message, just skip the agent parameter.

If you want to create a message with the markdown (bold, italic, underline etc.),  specify additionally the markdownText attribute.

Please note that there's no markdownText parameter in the response. The text with the markdown will be placed in the text field.


✅ Successful Response

If your request has succeeded, you'll get a 200 OK success status code together with the following response body.

{
    "id": 9577656,
    "agent": {
        "id": 4188,
        "name": "Sam"
    },
    "type": "message",
    "text": null,
    "read": false,
    "createdAt": "1601557390.769",
    "updatedAt": null,
    "edited": false,
    "broadcastType": null,
    "chat": 5215261,
    "from": "agent"
}

You can get details on every Message Object field in the Message model article.

🛑 Error Responses

You may get one of the following error status codes and responses. More info on the errors is available here.

400 Bad Request

{
    "errors": [
        {
            "code": "invalid_chat_value",
            "message": "Invalid chat ID"
        }
    ]
}

401 Unauthorized

{
    "errors": [
        {
            "code": "invalid_token",
            "message": "Invalid token"
        }
    ]
}

404 Not Found

{
    "errors": [
        {
            "code": "chat_not_found",
            "message": "Chat is missing"
        }
        {
            "code": "entity_not_found",
            "message": "Agent not found"
        }
    ]
}

429 Too Many Requests

{
    "errors": [
        {
            "code": "too_many_requests",
            "message": "You have exceeded your requests limit"
        }
    ]
}

If you have any questions regarding the REST API, feel free to chat us any time.

👩‍💻 Happy Coding! 👨‍💻

Did this answer your question?