Green API icon

Green API

Send WhatsApp messages via Green API or trigger workflows on webhooks

Overview

The node integrates with Green API to interact with WhatsApp messaging services. Specifically, the Chat - Get Chat History operation retrieves the message history of a specified WhatsApp chat.

This operation is useful when you want to programmatically access past messages from a particular chat for purposes such as:

  • Archiving conversations.
  • Analyzing chat content or trends.
  • Displaying chat history in custom dashboards.
  • Triggering workflows based on historical chat data.

For example, you could use this node to fetch the last 100 messages from a customer support chat to analyze customer inquiries or to synchronize chat logs with a CRM system.

Properties

Name Meaning
Mode Selects the node mode:
- Action: Execute WhatsApp actions via Green API.
- Listen for Incoming Webhook: Trigger workflows on incoming Green API webhooks.
Webhook Filters (Only for "Listen for Incoming Webhook" mode) Filters to restrict which incoming webhooks trigger the workflow:
- Chat ID Filter (comma-separated list)
- Chat Type Filter (All, Group only, Private only)
- Filter Logic (And / Or)
- Instance ID Filter
- Message Content Contains
- Message Type Filter (multiple message types)
- Sender Filter
- Webhook Type Filter (Delivery Receipt, Incoming Messages, Message Status, Outgoing Messages)
Resource (In Action mode) The resource to operate on. For this operation, set to Chat.
Operation (In Action mode) The operation to perform. For this summary, Get Chat History.
Chat ID The unique identifier of the chat to retrieve history from. Format examples:
- Private chat: 972501234567@c.us
- Group chat: 120363369140947676@g.us
Count Number of messages to retrieve from the chat history. Defaults to 100 if not specified.

Output

The output is a JSON array where each item corresponds to the response from the Green API endpoint for the requested chat history.

  • The main JSON object contains the chat history data returned by Green API.
  • This typically includes an array of messages with details such as message IDs, timestamps, sender info, message content, and message type.
  • No binary data output is produced by this operation.

Example output structure (simplified):

[
  {
    "messages": [
      {
        "idMessage": "ABCD1234",
        "timestamp": 1680000000,
        "sender": "972501234567@c.us",
        "typeMessage": "textMessage",
        "textMessageData": {
          "textMessage": "Hello!"
        }
      },
      ...
    ]
  }
]

Dependencies

  • Requires an active Green API account with valid credentials: an instance ID and an API token.
  • The node uses these credentials to authenticate requests to Green API endpoints.
  • Network connectivity to https://api.green-api.com is required.
  • No additional external dependencies beyond standard Node.js modules and n8n helpers.

Troubleshooting

  • Error: "Failed to get chat history"
    Possible causes:

    • Invalid or expired API credentials. Verify your instance ID and API token are correct and active.
    • Incorrect chat ID format or non-existent chat. Ensure the chat ID matches the expected format and exists in your WhatsApp instance.
    • Network issues preventing connection to Green API servers. Check internet connectivity and firewall settings.
  • Node configured as trigger but used as action
    If the node is set to "Listen for Incoming Webhook" mode but executed as an action, it will throw an error instructing to use it as a trigger node instead.

  • Empty or incomplete chat history
    The count parameter limits how many messages are retrieved. Increase the count if you need more messages. Also, some messages might be missing if they were deleted or if the chat is new.

Links and References

Discussion