# get\_\_conversation\_{conversationId}\_messages

{% hint style="info" %}
This API endpoint is currently available only in the TEST environment. It is not yet available in production.
{% endhint %}

`GET /conversation/{conversationId}/messages`

*Get Conversation Messages*

Retrieve all messages from a conversation, including both user prompts and assistant responses. This endpoint returns the complete conversation history in chronological order.

**Key Features:**

* Returns all messages from a conversation (user and assistant)
* Messages are ordered chronologically (oldest first)
* Includes message metadata such as token counts and model information
* Supports conversation context retrieval for AI operations
* Respects workspace and organization access controls

**Message Types:**

* **User messages** - Prompts sent by users
* **Assistant messages** - Responses generated by the AI

**Important Notes:**

* Users must have access to the conversation's workspace
* The conversation must exist and not be deleted
* Organization administrators can view all conversations
* Workspace administrators can view conversations in their workspaces
* Regular users can only view their own conversations
* Messages are retrieved from the external conversation API engine

**Security:**

* Access is validated against workspace permissions
* Only users with appropriate workspace access can retrieve messages
* Message content is subject to policy enforcement and audit logging

**Integration:**

This endpoint integrates with external conversation API engines to retrieve conversation history. The system handles:

* Fetching messages from the conversation store
* Formatting and structuring message data
* Including metadata and context information
* Maintaining message order and timestamps

#### TypeScript Client Library

```typescript
public getConversationMessages = async (conversationId: string): Promise<GetConversationMessagesResponse> => {
  return this.makeRequest<GetConversationMessagesResponse>(`conversation/${conversationId}/messages`, 'GET', null);
};
```

#### Code Samples

{% tabs %}
{% tab title="Shell" %}

```shell
# You can also use wget
curl -X GET https://backend.flashback.tech/conversation/{conversationId}/messages \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access-token}'
```

{% endtab %}

{% tab title="HTTP" %}

```http
GET https://backend.flashback.tech/conversation/{conversationId}/messages HTTP/1.1
Host: backend.flashback.tech
Accept: application/json
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const headers = {
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('https://backend.flashback.tech/conversation/{conversationId}/messages',
{
  method: 'GET',
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json',
  'Authorization' => 'Bearer {access-token}'
}

result = RestClient.get 'https://backend.flashback.tech/conversation/{conversationId}/messages',
  params: {
  }, headers: headers

p JSON.parse(result)
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
headers = {
  'Accept': 'application/json',
  'Authorization': 'Bearer {access-token}'
}

r = requests.get('https://backend.flashback.tech/conversation/{conversationId}/messages', headers = headers)

print(r.json())
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

require 'vendor/autoload.php';

$headers = array(
    'Accept' => 'application/json',
    'Authorization' => 'Bearer {access-token}',
);

$client = new \GuzzleHttp\Client();

try {
    $response = $client->request('GET','https://backend.flashback.tech/conversation/{conversationId}/messages', array(
        'headers' => $headers,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...
```

{% endtab %}

{% tab title="Java" %}

```java
URL obj = new URL("https://backend.flashback.tech/conversation/{conversationId}/messages");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Accept": []string{"application/json"},
        "Authorization": []string{"Bearer {access-token}"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("GET", "https://backend.flashback.tech/conversation/{conversationId}/messages", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}
```

{% endtab %}
{% endtabs %}

#### Parameters <a href="#get__conversation_-conversationid-_messages-parameters" id="get__conversation_-conversationid-_messages-parameters"></a>

| Name           | In   | Type   | Required | Description                           |
| -------------- | ---- | ------ | -------- | ------------------------------------- |
| conversationId | path | string | true     | Unique identifier of the conversation |

> Example responses

> 200 Response

```json
{
  "success": true,
  "messages": [
    {
      "id": "msg-123",
      "conversationId": "conv-456",
      "role": "user",
      "content": "What is the best practice for securing API keys?",
      "tokenCount": 12,
      "model": null,
      "metadata": {},
      "createdAt": "2024-01-15T10:30:00.000Z"
    },
    {
      "id": "msg-124",
      "conversationId": "conv-456",
      "role": "assistant",
      "content": "The best practices for securing API keys include:\n\n1. Never commit API keys to version control\n2. Store keys in environment variables or secure vaults\n3. Rotate keys regularly\n4. Use least privilege access principles\n5. Monitor key usage for anomalies",
      "tokenCount": 87,
      "model": "gpt-4",
      "metadata": {
        "temperature": 0.7,
        "maxTokens": 1000
      },
      "createdAt": "2024-01-15T10:30:05.000Z"
    }
  ]
}
```

#### Responses <a href="#get__conversation_-conversationid-_messages-responses" id="get__conversation_-conversationid-_messages-responses"></a>

| Status | Meaning                                                                    | Description                     | Schema |
| ------ | -------------------------------------------------------------------------- | ------------------------------- | ------ |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)                    | Successfully retrieved messages | Inline |
| 400    | [Bad Request](https://tools.ietf.org/html/rfc7231#section-6.5.1)           | Invalid request                 | Inline |
| 403    | [Forbidden](https://tools.ietf.org/html/rfc7231#section-6.5.3)             | Insufficient permissions        | Inline |
| 404    | [Not Found](https://tools.ietf.org/html/rfc7231#section-6.5.4)             | Conversation not found          | Inline |
| 500    | [Internal Server Error](https://tools.ietf.org/html/rfc7231#section-6.6.1) | Failed to retrieve messages     | Inline |

#### Response Schema <a href="#get__conversation_-conversationid-_messages-responseschema" id="get__conversation_-conversationid-_messages-responseschema"></a>

Status Code **200**

| Name              | Type      | Required | Restrictions | Description                                  |
| ----------------- | --------- | -------- | ------------ | -------------------------------------------- |
| » success         | boolean   | false    | none         | Operation success status                     |
| » messages        | \[object] | false    | none         | Array of message objects                     |
| »» id             | string    | false    | none         | Unique identifier for the message            |
| »» conversationId | string    | false    | none         | Conversation ID this message belongs to      |
| »» role           | string    | false    | none         | Message role ("user" or "assistant")         |
| »» content        | string    | false    | none         | Message content text                         |
| »» tokenCount     | integer   | false    | none         | Number of tokens in the message              |
| »» model          | string    | false    | none         | AI model used (for assistant messages)       |
| »» metadata       | object    | false    | none         | Additional metadata (model parameters, etc.) |
| »» createdAt      | string    | false    | none         | ISO 8601 timestamp when message was created  |

**Enumerated Values**

| Parameter | Value     |
| --------- | --------- |
| »» role   | user      |
| »» role   | assistant |

Status Code **400**

| Name       | Type    | Required | Restrictions | Description   |
| ---------- | ------- | -------- | ------------ | ------------- |
| » success  | boolean | false    | none         | none          |
| » messages | array   | false    | none         | none          |
| » message  | string  | false    | none         | Error message |

Status Code **403**

| Name       | Type    | Required | Restrictions | Description   |
| ---------- | ------- | -------- | ------------ | ------------- |
| » success  | boolean | false    | none         | none          |
| » messages | array   | false    | none         | none          |
| » message  | string  | false    | none         | Error message |

Status Code **404**

| Name       | Type    | Required | Restrictions | Description   |
| ---------- | ------- | -------- | ------------ | ------------- |
| » success  | boolean | false    | none         | none          |
| » messages | array   | false    | none         | none          |
| » message  | string  | false    | none         | Error message |

Status Code **500**

| Name       | Type    | Required | Restrictions | Description   |
| ---------- | ------- | -------- | ------------ | ------------- |
| » success  | boolean | false    | none         | none          |
| » messages | array   | false    | none         | none          |
| » message  | string  | false    | none         | Error message |

To perform this operation, you must be authenticated by means of one of the following methods: BearerAuth


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flashback.tech/support-reference/platform-api-reference/conversation-api/get__conversation_-conversationid-_messages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
