Write an item
Store a JSON document under a key. Creates the collection if it does not exist — with no indexes, which query then cannot use. Declare indexes with POST /v1/memory/collections first if you need them.
This replaces the whole document; it does not merge. Pass If-Match with the revision from a previous read to make the write conditional.
curl --request PUT \
--url https://api.zavu.dev/v1/memory/collections/{collection}/items/{key} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"value": {
"status": "shipped",
"total": 42.5
}
}
'import requests
url = "https://api.zavu.dev/v1/memory/collections/{collection}/items/{key}"
payload = { "value": {
"status": "shipped",
"total": 42.5
} }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({value: {status: 'shipped', total: 42.5}})
};
fetch('https://api.zavu.dev/v1/memory/collections/{collection}/items/{key}', 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/{collection}/items/{key}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'value' => [
'status' => 'shipped',
'total' => 42.5
]
]),
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/{collection}/items/{key}"
payload := strings.NewReader("{\n \"value\": {\n \"status\": \"shipped\",\n \"total\": 42.5\n }\n}")
req, _ := http.NewRequest("PUT", 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.put("https://api.zavu.dev/v1/memory/collections/{collection}/items/{key}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"value\": {\n \"status\": \"shipped\",\n \"total\": 42.5\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.zavu.dev/v1/memory/collections/{collection}/items/{key}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"value\": {\n \"status\": \"shipped\",\n \"total\": 42.5\n }\n}"
response = http.request(request)
puts response.read_body{
"item": {
"key": "ORD-12345",
"rev": 3,
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z",
"value": {
"status": "shipped",
"total": 42.5
},
"expiresAt": "2023-11-07T05:31:56Z"
}
}{
"item": {
"key": "ORD-12345",
"rev": 3,
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z",
"value": {
"status": "shipped",
"total": 42.5
},
"expiresAt": "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": {}
}{
"code": "invalid_request",
"message": "Phone number is invalid",
"details": {}
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
Make the write conditional on the item's current revision, as returned by a previous read or write (plain 3 or ETag-quoted "3"). The write is refused with 409 revision_conflict if the item moved on in between. Without it, the write always wins and silently overwrites a concurrent one.
"3"
Path Parameters
Collection name.
Item key. 1-255 chars from A-Z a-z 0-9 . _ : @ -
Query Parameters
Which scope to address: contact:<contactId>, conversation:<conversationId>, or omitted for the project scope.
Note the asymmetry with POST /v1/memory and POST /v1/memory/search, which take the scope in the request BODY as scope plus contactId/conversationId. Every other Memory endpoint takes it here.
Scope as a query-string value: contact:<contactId>, conversation:<conversationId>, the literal project, or omitted for project scope.
Only the SHAPE of the id is validated, never its existence — the partition already carries your project, so an id that matches nothing simply addresses an empty scope rather than returning 404.
"contact:jd7x2k3m4n5p6q7r8s9t0abc"
Body
Response
Existing item replaced.
One JSON document in a collection.
Show child attributes
Show child attributes
curl --request PUT \
--url https://api.zavu.dev/v1/memory/collections/{collection}/items/{key} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"value": {
"status": "shipped",
"total": 42.5
}
}
'import requests
url = "https://api.zavu.dev/v1/memory/collections/{collection}/items/{key}"
payload = { "value": {
"status": "shipped",
"total": 42.5
} }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({value: {status: 'shipped', total: 42.5}})
};
fetch('https://api.zavu.dev/v1/memory/collections/{collection}/items/{key}', 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/{collection}/items/{key}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'value' => [
'status' => 'shipped',
'total' => 42.5
]
]),
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/{collection}/items/{key}"
payload := strings.NewReader("{\n \"value\": {\n \"status\": \"shipped\",\n \"total\": 42.5\n }\n}")
req, _ := http.NewRequest("PUT", 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.put("https://api.zavu.dev/v1/memory/collections/{collection}/items/{key}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"value\": {\n \"status\": \"shipped\",\n \"total\": 42.5\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.zavu.dev/v1/memory/collections/{collection}/items/{key}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"value\": {\n \"status\": \"shipped\",\n \"total\": 42.5\n }\n}"
response = http.request(request)
puts response.read_body{
"item": {
"key": "ORD-12345",
"rev": 3,
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z",
"value": {
"status": "shipped",
"total": 42.5
},
"expiresAt": "2023-11-07T05:31:56Z"
}
}{
"item": {
"key": "ORD-12345",
"rev": 3,
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z",
"value": {
"status": "shipped",
"total": 42.5
},
"expiresAt": "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": {}
}{
"code": "invalid_request",
"message": "Phone number is invalid",
"details": {}
}