Retrieve Document¶
Retrieves the document with the specified ID.
Endpoint¶
Path parameter | Type | Details |
---|---|---|
{id} |
string | Unique ID of the document to be retrieved. |
API request¶
-
Parameters
No parameters.
-
GET /v20241104/documents/{id}
curl "https://api.gainly.ai/v20241104/documents/YOUR_DOCUMENT_ID_HERE" \ # (1)! -H "Content-Type: application/json" \ -H "X-API-Key: YOUR_API_KEY_HERE" # (2)!
- Replace
YOUR_DOCUMENT_ID_HERE
with the document ID you want to retrieve. - Replace
YOUR_API_KEY_HERE
with the value of your API key.
# Prompt for AI coding assistants/IDEs (e.g., ChatGPT, Claude, GitHub Copilot, Cursor, Windsurf) Using the Gainly API: 1. Write code to call the retrieve_document operation (see OpenAPI spec: https://api.gainly.ai/v20241104/openapi.json) 2. Implement authentication using the header "X-API-Key" as described in the docs: https://docs.gainly.ai/latest/api-reference/authentication/ 3. Implement rate limit handling as described in the docs: https://docs.gainly.ai/latest/api-reference/rate-limits/ 4. Implement error handling 5. Handle the response according to the DocumentRetrieveResponse schema in the OpenAPI spec
using System.Net.Http; var client = new HttpClient(); var id = "YOUR_DOCUMENT_ID_HERE"; // (1)! var url = $"https://api.gainly.ai/v20241104/documents/{id}"; client.DefaultRequestHeaders.Add("X-API-Key", "YOUR_API_KEY_HERE"); // (2)! var response = await client.GetAsync(url); var result = await response.Content.ReadAsStringAsync(); Console.WriteLine(result);
- Replace
YOUR_DOCUMENT_ID_HERE
with the document ID you want to retrieve. - Replace
YOUR_API_KEY_HERE
with the value of your API key.
package main import ( "fmt" "io/ioutil" "net/http" ) func main() { id := "YOUR_DOCUMENT_ID_HERE" // (1)! url := fmt.Sprintf("https://api.gainly.ai/v20241104/documents/%s", id) req, _ := http.NewRequest("GET", url, nil) req.Header.Set("Content-Type", "application/json") req.Header.Set("X-API-Key", "YOUR_API_KEY_HERE") // (2)! resp, _ := http.DefaultClient.Do(req) defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) fmt.Println(string(body)) }
- Replace
YOUR_DOCUMENT_ID_HERE
with the document ID you want to retrieve. - Replace
YOUR_API_KEY_HERE
with the value of your API key.
import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.URI; var client = HttpClient.newHttpClient(); var id = "YOUR_DOCUMENT_ID_HERE"; // (1)! var url = "https://api.gainly.ai/v20241104/documents/" + id; var request = HttpRequest.newBuilder() .uri(URI.create(url)) .header("Content-Type", "application/json") .header("X-API-Key", "YOUR_API_KEY_HERE") // (2)! .GET() .build(); var response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body());
- Replace
YOUR_DOCUMENT_ID_HERE
with the document ID you want to retrieve. - Replace
YOUR_API_KEY_HERE
with the value of your API key.
const axios = require('axios'); // or: import axios from 'axios'; const id = 'YOUR_DOCUMENT_ID_HERE'; // (1)! const url = `https://api.gainly.ai/v20241104/documents/${id}`; const headers = { 'Content-Type': 'application/json', 'X-API-Key': 'YOUR_API_KEY_HERE' // (2)! }; axios.get(url, { headers }) .then(response => console.log(response.data)) .catch(error => console.error('Error:', error.message));
- Replace
YOUR_DOCUMENT_ID_HERE
with the document ID you want to retrieve. - Replace
YOUR_API_KEY_HERE
with the value of your API key.
<?php $client = new \GuzzleHttp\Client(); $id = 'YOUR_DOCUMENT_ID_HERE'; # (1)! $url = "https://api.gainly.ai/v20241104/documents/{$id}"; $response = $client->request('GET', $url, [ 'headers' => [ 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'X-API-Key' => 'YOUR_API_KEY_HERE' # (2)! ], ]); echo $response->getBody();
- Replace
YOUR_DOCUMENT_ID_HERE
with the document ID you want to retrieve. - Replace
YOUR_API_KEY_HERE
with the value of your API key.
import requests id = "YOUR_DOCUMENT_ID_HERE" # (1)! url = f"https://api.gainly.ai/v20241104/documents/{id}" headers = { "Content-Type": "application/json", "X-API-Key": "YOUR_API_KEY_HERE" # (2)! } response = requests.get(url, headers=headers) data = response.json() print(data)
- Replace
YOUR_DOCUMENT_ID_HERE
with the document ID you want to retrieve. - Replace
YOUR_API_KEY_HERE
with the value of your API key.
require 'json' require 'uri' require 'net/http' require 'openssl' id = 'YOUR_DOCUMENT_ID_HERE' # (1)! url = URI("https://api.gainly.ai/v20241104/documents/#{id}") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request['Content-Type'] = 'application/json' request['X-API-Key'] = 'YOUR_API_KEY_HERE' # (2)! response = http.request(request) puts response.read_body
- Replace
YOUR_DOCUMENT_ID_HERE
with the document ID you want to retrieve. - Replace
YOUR_API_KEY_HERE
with the value of your API key.
- Replace
API Response¶
{
"id": "PbOrIZIBzlg4zQqVFxxE",
"object": "document",
"title": "My awesome document",
"content": "This document has great content. Can be really long, but is short here.",
"metadata": null,
"tenant_id": "tenant123",
"language": "en",
"source_uri": "/doc/7-my-awesome-document",
"created_at": "2023-10-05T14:48:02Z",
"updated_at": "2023-10-05T14:48:02Z",
"token_usage": {
"semantic_tokens": 0,
"llm_tokens": {
"llm_output_tokens": 0,
"llm_input_tokens": 0,
"model": null
}
},
"livemode": false
}
Returns the document object with the specified ID.