Get Chat Session Messages
This API allows you to get a chat session's last 20 messages by your user's unique identifier.
A successful response will not use up any requests from your monthly limit.
Below is the full reference for the GET
request.
Endpoint
GET
https://www.navigable.ai/api/v1/chat
Headers
Key | Value | |
---|---|---|
X-Api-Key | <YOUR_API_KEY> | |
Content-Type | application/json | If using JSON in the request body |
Request parameters can be sent as JSON in the request body, or can be urlencoded.
Key | Type | Required | Description |
---|---|---|---|
identifier | string | Yes | The unique identifier of your user. Must be a valid string. |
Response
On a successful request, the API will return a 200
status code along with the following JSON response:
{
"success": true,
"message": "SUCCESS",
"data": [
{
"sender": "who sent the message, USER or ASSISTANT",
"content": "contents of the message",
"new": "flag indicating if the message is the beginning of a new session",
"createdAt": "timestamp for when the message was created",
"action": "action recommended by the assistant | null"
}
// more messages...
]
}
Key | Type | Description |
---|---|---|
success | boolean | Indicates if the request was successful. |
message | string | The status message. |
data[index].sender | "USER" | "ASSISTANT" | The sender of the message. |
data[index].content | string | The content of the message. |
data[index].new | boolean | A flag indicating if the message is the beginning of a new session. |
data[index].createdAt | string | The timestamp for when the message was created. |
data[index].action | string | null | The action recommended by the assistant. |
Error Response - Unauthorized
On an unauthorized request, the API will return a 401
status code along with the following JSON response:
{
"success": false,
"message": "UNAUTHORIZED"
}
In case of this error, check your API key and ensure your request header has the correct X-Api-Key
value.
Error Response - Bad Request
On a bad request, the API will return a 400
status code along with the following JSON response:
{
"success": false,
"message": "BAD_REQUEST",
"errors": {
"<field>": "<error message>"
// ... other error fields
}
}
Parameter | Error Message |
---|---|
identifier | Property "identifier" must be a valid string. |
In case of this error, check your request parameters for any invalid values.
Error Response - Internal Server Error
On an internal server error, the API will return a 500
status code along with the following JSON response:
{
"success": false,
"message": "UNEXPECTED_ERROR",
// In case the error is known
"error": "<error message>"
}
In case of this error, try again.
Example Requests
- cURL
- Node.js (Axios)
- Python
- Go
- Ruby
- PHP
- Java
- C#
curl -X GET "https://www.navigable.ai/api/v1/chat?identifier=12345" \
-H "X-Api-Key: <YOUR_API_KEY>" \
-H "Content-Type: application/json"
const axios = require("axios");
axios
.get("https://www.navigable.ai/api/v1/chat", {
headers: {
"X-Api-Key": "<YOUR_API_KEY>",
"Content-Type": "application/json",
},
params: {
identifier: "12345",
},
})
.then((response) => console.log(response.data))
.catch((error) => console.error("Error:", error));
import requests
url = 'https://www.navigable.ai/api/v1/chat'
headers = {
'X-Api-Key': '<YOUR_API_KEY>',
'Content-Type': 'application/json'
}
params = {
'identifier': '12345'
}
response = requests.get(url, headers=headers, params=params)
print(response.json())
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
client := &http.Client{}
req, err := http.NewRequest("GET", "https://www.navigable.ai/api/v1/chat", nil)
if err != nil {
fmt.Println("Error creating request:", err)
return
}
req.Header.Set("X-Api-Key", "<YOUR_API_KEY>")
req.Header.Set("Content-Type", "application/json")
q := req.URL.Query()
q.Add("identifier", "12345")
req.URL.RawQuery = q.Encode()
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error making request:", err)
return
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
require 'net/http'
require 'uri'
require 'json'
uri = URI('https://www.navigable.ai/api/v1/chat')
params = { identifier: '12345' }
uri.query = URI.encode_www_form(params)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
request['X-Api-Key'] = '<YOUR_API_KEY>'
request['Content-Type'] = 'application/json'
response = http.request(request)
puts response.body
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.navigable.ai/api/v1/chat?identifier=12345",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"X-Api-Key: <YOUR_API_KEY>",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class GetRequestExample {
public static void main(String[] args) {
try {
String url = "https://www.navigable.ai/api/v1/chat?identifier=12345";
URL obj = new URL(url);
HttpURLConnection conn = (HttpURLConnection) obj.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("X-Api-Key", "<YOUR_API_KEY>");
conn.setRequestProperty("Content-Type", "application/json");
int responseCode = conn.getResponseCode();
System.out.println("Response Code: " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
private static readonly HttpClient client = new HttpClient();
static async Task Main()
{
var url = "https://www.navigable.ai/api/v1/chat?identifier=12345";
client.DefaultRequestHeaders.Add("X-Api-Key", "<YOUR_API_KEY>");
client.DefaultRequestHeaders.Add("Content-Type", "application/json");
try
{
var response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
catch (HttpRequestException e)
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Message :{0} ", e.Message);
}
}
}