API Access

Feature available in Enterprise plan and higher.

We are excited to finally give you API access. To start just go to https://www.chatnode.ai/account/settings and you will be able to generate a API key at the bottom of the page.

This key will be use for all your API queries.

We have currently 4 endpoints accessible here: https://api.public.chatnode.ai/redoc and https://api.public.chatnode.ai/docs

  • https://api.public.chatnode.ai/v1/{bot_id}/ to send message to chatbot and get back the AI answer.
  • https://api.public.chatnode.ai/v1/get-conversation-ids/{bot_id}/ to get conversation IDs along with their metadata for a given bot ID. Metadata includes potential, email, tel, name of users
  • https://api.public.chatnode.ai/v1/get-chats/{bot_id}/ to get the chat history of a specific bot using this endpoint.
  • https://api.public.chatnode.ai/v1/bot-metadata/get/{bot_id}/  to get metadata associated with a particular chatbot using the bot ID like the Title, the system prompt, and the greeting
  • https://api.public.chatnode.ai/v1/bot-metadata/set/{bot_id}/ to set the metadata of a chatbot like the Title, the system prompt, and the greeting
  • https://api.public.chatnode.ai/v1/bot/add-data/{bot_id}/  to add text data to a specific chatbot. The bot ID and the text data are required parameters.

If you want your message to keep the conversation knowledge you should create a unique chat_session_id and keep it for the conversation. If you do not want to use the history capability you can generate a new chat_session_id for each query.

We recommend using UUID which is widely available in most programming language. Here it is for javascript https://www.uuidgenerator.net/dev-corner/javascript

This is a javascript example to send a message to your chatbot

async function getMsgTrained(botId, apiKey, message, chatSessionId) {
  const url = `https://api.public.chatnode.ai/v1/${botId}`;
  const headers = {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${apiKey}`
  };
  const body = {
    message: message,
    chat_session_id: chatSessionId
  };

  try {
    const response = await fetch(url, {
      method: 'POST',
      headers: headers,
      body: JSON.stringify(body)
    });

    if (response.ok) {
      const data = await response.json();
      return data.message;
    } else {
      throw new Error('Failed to get trained message');
    }
  } catch (error) {
    console.error(error);
    throw error;
  }
}

 

Here's a JavaScript function based on the "Get Last Conversation" query:

async function getLastConversation(botId, apiKey) {
  const url = `https://api.public.chatnode.ai/v1/get-chats/${botId}`;
  const headers = {
    Authorization: `HTTPBearer ${apiKey}`,
    'Content-Type': 'application/json'
  };

  try {
    const response = await fetch(url, {
      method: 'POST',
      headers: headers
    });

    if (response.ok) {
      const data = await response.json();
      return data.last_conversation;
    } else {
      throw new Error('Failed to get last conversation');
    }
  } catch (error) {
    console.error(error);
    return null;
  }
}