Sending canned response in chat via API returns 400 Bad Request

Looking for advice on sending a canned response during an active chat interaction using the .NET SDK. I’m building a backend service to push predefined answers to agents, but I keep hitting a wall.

I have the conversation ID and the participant ID. I’m trying to send a message to the conversation. The docs say this works for SMS and web chat. Here is the payload I’m constructing in C#:

var message = new MessagingMessageRequest
{
 To = new List<ParticipantAddress> { new ParticipantAddress { Id = agentParticipantId } },
 Text = "Here is the standard response.",
 Type = "text"
};

var response = client.MessagingApi.PostConversationsMessagingConversationsMessage(conversationId, message);

The request fails with 400 Bad Request. The error response body is vague:

{
 "message": "Invalid message type for this conversation",
 "code": "bad.request",
 "status": 400
}

I’ve checked the Type enum. I tried "text", "application/x-ndjson", and even leaving it null. Nothing works. Is the endpoint different for real-time chat versus async messaging? I feel like I’m missing a specific header or the wrong endpoint entirely. The SDK documentation for PostConversationsMessagingConversationsMessage doesn’t explicitly mention canned responses or agent-side injection.

Also, i’m using the GenesysCloud NuGet package version 3.12.0. Could this be a version issue? I’ve verified the OAuth token has the messaging:send scope. The token is valid for other GET requests on the same conversation.

Just need to know the correct JSON structure or if I should be using a different API method like SendEvent instead. Any code examples would be appreciated. i’m stuck on this for two days now.

If I remember correctly, canned responses need a specific type field. The docs cover it here: https://support.example.com/canned-api. just add "type": "canned" to your payload and it should work.

2 Likes

if i remember correctly the type field is not the main issue here. the endpoint you are using is for general messaging. for canned responses specifically, the system expects the message to be linked to a template id in the backend, not just a generic text payload. also, check if your participant id is actually the agent’s id or the customer’s id. in my tests with the .net sdk, sending to the wrong participant returns a 400 because the permissions don’t match.

try changing the payload to include templateId instead of just text. and make sure the conversation status is active. if it is closed or ended, the api will reject it. i had this problem last week when testing with chrome tools. the error message was vague but the logs showed a permission denied. check the admin ui for the canned response settings too. sometimes they are disabled for specific skill groups. this usually fixes the bad request error.

2 Likes

Check your payload structure. the previous suggestions are close, but there is a subtle difference between sending a raw message and invoking a canned response template via the .

the endpoint POST //v2/conversations/messaging/conversations/{conversationId}/messages is correct for chat. however, you are likely missing the specific headers or the from object structure that ties the message to an agent role. if you just send text, the system treats it as a bot or system message, which triggers a 400 if permissions aren’t set correctly for that user type.

try this python snippet using the pure REST call logic (easier to debug than SDK wrappers sometimes):

import requests

headers = {
 'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
 'Content-Type': 'application/json'
}

payload = {
 "to": [{"id": "CUSTOMER_PARTICIPANT_ID"}], # crucial: target the customer, not agent
 "text": "Here is the standard response.",
 "type": "text", # keep it simple first
 "from": {"id": "AGENT_PARTICIPANT_ID"} # must match the logged in agent
}

response = requests.post(
 f"https://your-subdomain.mypurecloud.com//v2/conversations/messaging/conversations/{CONV_ID}/messages",
 headers=headers,
 json=payload
)

print(response.status_code, response.text)

if you really need to use the canned response template feature (so it pulls from the library), you might need to query the canned response ID first via GET //v2/canned-responses and then pass that ID in a different endpoint, or just inject the text directly as shown above. the 400 usually means the from ID doesn’t have permission to send on behalf of the conversation, or the to ID is invalid for this channel.

verify the participant IDs are from the current session. stale participant IDs cause this error often.

Note: ensure the agent is actually in a ‘connected’ or ‘active’ state for the conversation. sending messages while on hold or in queue often fails silently or with 400s depending on the platform version.

Make sure you aren’t treating this as a pure API problem. The 400 error usually means the participant ID doesn’t match the agent’s actual role in the conversation. Check if you’re using the correct ID for the agent versus the customer. Permissions fail silently in some SDK versions.