Tagging conversations via the api, help with ajax

Hey there, I use Rasa X 0.35.0 and a website with my chatbot on it. Sending user responses to my rasa server works perfectly with:

function send(message) {
    console.log(chatbotdns);
    $.ajax({
        url: chatbotdns + "/webhooks/rest/webhook",
        type: "POST",
        contentType: "application/json",
        data: JSON.stringify({ message: message, sender: user_id }),
        
        success: function(botResponse, status) {
            console.log("Response from Rasa: ", botResponse, "\nStatus: ", status);
            }
            setBotResponse(botResponse);
        },

        error: function(xhr, textStatus, errorThrown) {
            setBotResponse("");
            console.log("Error from bot end: ", textStatus);
        }
    });
}

Now I want to set a tag to this conversation. I tried with:

$.ajax({
        url: chatbotdns + `/api/conversations/${user_id}/tags`,
        type: "POST",
        contentType: "application/json",
        data: JSON.stringify({ "value": "tag-label", "color": "eb4034" }),
        success: function(botResponse, status) {
            console.log("set tag successful", botResponse, "\nStatus: ", status);
        },
        error: function(xhr, textStatus, errorThrown) {
            setBotResponse("");
            console.log("Error from bot end: ", textStatus);
        }
    });

But I get POST 400 (Bad Request) The url that is called is correct. Any ideas how to fix this?

Hi @jbrix!

Have you tried wrapping the data object in an array? I just tried this on Postman and that’s what I was missing. So your data line would look like this:

data: JSON.stringify([{ "value": "tag-label", "color": "eb4034" }])

If that doesn’t work, is there anything else in the logs besides 400?

That was actually the cause! Thanks for the hint!

1 Like