Create a collection
Declare a collection of JSON documents addressed by key. This is the counterpart to facts: POST /v1/memory recalls by meaning, a collection recalls by key.
Create it explicitly when you need query. Writing to an unknown collection creates it implicitly, but with no indexes — and indexes cannot be added afterwards. If you will ever look items up by a field rather than by key, declare that field here, before the first write.
A collection is defined once for the project. Its ITEMS are per-scope, so the same collection holds a separate set of documents for the project, for each contact, and for each conversation.
curl --request POST \
--url https://api.zavu.dev/v1/memory/collections \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "orders",
"indexes": [
{
"field": "status"
}
]
}
'import requests
url = "https://api.zavu.dev/v1/memory/collections"
payload = {
"name": "orders",
"indexes": [{ "field": "status" }]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({name: 'orders', indexes: [{field: 'status'}]})
};
fetch('https://api.zavu.dev/v1/memory/collections', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.zavu.dev/v1/memory/collections",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'orders',
'indexes' => [
[
'field' => 'status'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.zavu.dev/v1/memory/collections"
payload := strings.NewReader("{\n \"name\": \"orders\",\n \"indexes\": [\n {\n \"field\": \"status\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.zavu.dev/v1/memory/collections")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"orders\",\n \"indexes\": [\n {\n \"field\": \"status\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.zavu.dev/v1/memory/collections")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"orders\",\n \"indexes\": [\n {\n \"field\": \"status\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"collection": {
"name": "orders",
"indexes": [
{
"field": "<string>"
}
],
"defaultTtlSeconds": 123,
"status": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
}
}{
"code": "invalid_request",
"message": "Phone number is invalid",
"details": {}
}{
"code": "invalid_request",
"message": "Phone number is invalid",
"details": {}
}{
"code": "invalid_request",
"message": "Phone number is invalid",
"details": {}
}{
"code": "invalid_request",
"message": "Phone number is invalid",
"details": {}
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
1-63 chars: lowercase letters, digits, - and _, starting with a letter or digit.
"orders"
Up to 2 fields to index for query. This is the only way to declare them — a collection created implicitly by its first write has none, and querying an unindexed field returns 400 field_not_indexed. Indexes cannot be added later, so declare them here before the first write.
2Show child attributes
Show child attributes
60 <= x <= 63072000Response
Collection created.
A namespace of JSON documents addressed by key.
Show child attributes
Show child attributes
curl --request POST \
--url https://api.zavu.dev/v1/memory/collections \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "orders",
"indexes": [
{
"field": "status"
}
]
}
'import requests
url = "https://api.zavu.dev/v1/memory/collections"
payload = {
"name": "orders",
"indexes": [{ "field": "status" }]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({name: 'orders', indexes: [{field: 'status'}]})
};
fetch('https://api.zavu.dev/v1/memory/collections', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.zavu.dev/v1/memory/collections",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'orders',
'indexes' => [
[
'field' => 'status'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.zavu.dev/v1/memory/collections"
payload := strings.NewReader("{\n \"name\": \"orders\",\n \"indexes\": [\n {\n \"field\": \"status\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.zavu.dev/v1/memory/collections")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"orders\",\n \"indexes\": [\n {\n \"field\": \"status\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.zavu.dev/v1/memory/collections")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"orders\",\n \"indexes\": [\n {\n \"field\": \"status\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"collection": {
"name": "orders",
"indexes": [
{
"field": "<string>"
}
],
"defaultTtlSeconds": 123,
"status": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
}
}{
"code": "invalid_request",
"message": "Phone number is invalid",
"details": {}
}{
"code": "invalid_request",
"message": "Phone number is invalid",
"details": {}
}{
"code": "invalid_request",
"message": "Phone number is invalid",
"details": {}
}{
"code": "invalid_request",
"message": "Phone number is invalid",
"details": {}
}