Trying to inject a canned response into an active chat via the JS SDK. The flow works for standard messages, but the canned endpoint throws a 400. I’m passing the canned ID from the response of GET /api/v2/canned-responses. The request body is minimal.
const payload = {
cannedResponseId: "123e4567-e89b-12d3-a456-426614174000",
type: "canned"
};
await client.conversationsApi.postConversationsInteractionsMessages(interactionId, payload);
The error response says Invalid request body. I’ve checked the Swagger spec and the model looks correct. Is there a specific header or additional field required for canned responses that isn’t documented in the standard message model? The interaction is definitely in a chat state and the user has the right permissions.
You’re missing the to field in your payload. The API needs to know which participant gets the message, so add to: { id: "participantId" } to that object.
Adding the to field is correct, but you’ll hit a wall if you assume the endpoint accepts the payload structure you posted. The postConversationsInteractionsMessages method expects a specific schema for the message content, not just metadata flags.
Here is the actual payload structure required for a canned response injection. You need to wrap the ID in the content object and specify the media type.
const payload = {
to: { id: participantId },
content: {
cannedResponseId: "123e4567-e89b-12d3-a456-426614174000",
type: "canned"
}
};
await client.conversationsApi.postConversationsInteractionsMessages(interactionId, payload);
The 400 error usually comes from a missing content wrapper or an invalid participantId. Double check that the participant ID belongs to the agent, not the customer, since you’re injecting on behalf of the system. Also, ensure your token has conversation:write scope. If it still fails, check the response body for specific validation errors. They’re often buried in the details array.