Injecting canned responses via POST /api/v2/conversations/chats/{conversationId}/messages in Terraform validation

updating our Terraform modules to include automated validation scripts that simulate chat interactions. The goal is to verify that our custom skill-based routing logic handles specific canned responses correctly. I am attempting to send a predefined canned response during an active chat session using the Conversations API endpoint POST /api/v2/conversations/chats/{conversationId}/messages.

The documentation suggests that the request body should contain the text of the message and potentially a reference to the canned response ID. However, when I include the cannedResponseId in the payload, the API returns a 400 Bad Request with the error message: “Invalid message type for canned response injection.” Here is the JSON payload I am constructing in our Python validation script:

{
 "type": "text",
 "text": "This is a test canned response.",
 "cannedResponseId": "abc123-def456-ghi789"
}

I have verified that the cannedResponseId exists and is accessible to the user associated with the API token. The token has the conversation:write scope. The conversation ID is valid and the chat is in an active state. I have also tried omitting the text field, assuming the API would fetch the text from the canned response definition, but that results in a 422 Unprocessable Entity error stating that the text field is required.

Is there a specific header or query parameter required to trigger the canned response injection? Or is the correct approach to first retrieve the canned response text via GET /api/v2/users/cannedresponses and then send a standard text message? Our current Terraform data sources do not easily support chaining these two API calls within a single validation step, so a single POST request would be preferable. Any insights on the correct payload structure for this specific use case would be appreciated.