Patch metadata of a user
curl --request PATCH \
--url https://{tenant_id}.hanko.io/admin/users/{id}/metadata \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"public_metadata": {
"role": "admin"
},
"private_metadata": {
"internal_id": "e6c19cfb-09a2-41e5-a908-e33193b7ca0a"
},
"unsafe_metadata": {
"birthday": "2025-05-12"
}
}
'import requests
url = "https://{tenant_id}.hanko.io/admin/users/{id}/metadata"
payload = {
"public_metadata": { "role": "admin" },
"private_metadata": { "internal_id": "e6c19cfb-09a2-41e5-a908-e33193b7ca0a" },
"unsafe_metadata": { "birthday": "2025-05-12" }
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
public_metadata: {role: 'admin'},
private_metadata: {internal_id: 'e6c19cfb-09a2-41e5-a908-e33193b7ca0a'},
unsafe_metadata: {birthday: '2025-05-12'}
})
};
fetch('https://{tenant_id}.hanko.io/admin/users/{id}/metadata', 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://{tenant_id}.hanko.io/admin/users/{id}/metadata",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'public_metadata' => [
'role' => 'admin'
],
'private_metadata' => [
'internal_id' => 'e6c19cfb-09a2-41e5-a908-e33193b7ca0a'
],
'unsafe_metadata' => [
'birthday' => '2025-05-12'
]
]),
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://{tenant_id}.hanko.io/admin/users/{id}/metadata"
payload := strings.NewReader("{\n \"public_metadata\": {\n \"role\": \"admin\"\n },\n \"private_metadata\": {\n \"internal_id\": \"e6c19cfb-09a2-41e5-a908-e33193b7ca0a\"\n },\n \"unsafe_metadata\": {\n \"birthday\": \"2025-05-12\"\n }\n}")
req, _ := http.NewRequest("PATCH", 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.patch("https://{tenant_id}.hanko.io/admin/users/{id}/metadata")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"public_metadata\": {\n \"role\": \"admin\"\n },\n \"private_metadata\": {\n \"internal_id\": \"e6c19cfb-09a2-41e5-a908-e33193b7ca0a\"\n },\n \"unsafe_metadata\": {\n \"birthday\": \"2025-05-12\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant_id}.hanko.io/admin/users/{id}/metadata")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"public_metadata\": {\n \"role\": \"admin\"\n },\n \"private_metadata\": {\n \"internal_id\": \"e6c19cfb-09a2-41e5-a908-e33193b7ca0a\"\n },\n \"unsafe_metadata\": {\n \"birthday\": \"2025-05-12\"\n }\n}"
response = http.request(request)
puts response.read_body{
"public_metadata": {
"role": "admin"
},
"private_metadata": {
"internal_id": "e6c19cfb-09a2-41e5-a908-e33193b7ca0a"
},
"unsafe_metadata": {
"birthday": "2025-05-12"
}
}{
"code": 400,
"message": "Bad Request"
}{
"code": 404,
"message": "Not found"
}{
"code": 500,
"message": "Internal Server Error"
}User Metadata Management
Patch metadata of a user
Patch metadata of a user
PATCH
/
users
/
{id}
/
metadata
Patch metadata of a user
curl --request PATCH \
--url https://{tenant_id}.hanko.io/admin/users/{id}/metadata \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"public_metadata": {
"role": "admin"
},
"private_metadata": {
"internal_id": "e6c19cfb-09a2-41e5-a908-e33193b7ca0a"
},
"unsafe_metadata": {
"birthday": "2025-05-12"
}
}
'import requests
url = "https://{tenant_id}.hanko.io/admin/users/{id}/metadata"
payload = {
"public_metadata": { "role": "admin" },
"private_metadata": { "internal_id": "e6c19cfb-09a2-41e5-a908-e33193b7ca0a" },
"unsafe_metadata": { "birthday": "2025-05-12" }
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
public_metadata: {role: 'admin'},
private_metadata: {internal_id: 'e6c19cfb-09a2-41e5-a908-e33193b7ca0a'},
unsafe_metadata: {birthday: '2025-05-12'}
})
};
fetch('https://{tenant_id}.hanko.io/admin/users/{id}/metadata', 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://{tenant_id}.hanko.io/admin/users/{id}/metadata",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'public_metadata' => [
'role' => 'admin'
],
'private_metadata' => [
'internal_id' => 'e6c19cfb-09a2-41e5-a908-e33193b7ca0a'
],
'unsafe_metadata' => [
'birthday' => '2025-05-12'
]
]),
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://{tenant_id}.hanko.io/admin/users/{id}/metadata"
payload := strings.NewReader("{\n \"public_metadata\": {\n \"role\": \"admin\"\n },\n \"private_metadata\": {\n \"internal_id\": \"e6c19cfb-09a2-41e5-a908-e33193b7ca0a\"\n },\n \"unsafe_metadata\": {\n \"birthday\": \"2025-05-12\"\n }\n}")
req, _ := http.NewRequest("PATCH", 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.patch("https://{tenant_id}.hanko.io/admin/users/{id}/metadata")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"public_metadata\": {\n \"role\": \"admin\"\n },\n \"private_metadata\": {\n \"internal_id\": \"e6c19cfb-09a2-41e5-a908-e33193b7ca0a\"\n },\n \"unsafe_metadata\": {\n \"birthday\": \"2025-05-12\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant_id}.hanko.io/admin/users/{id}/metadata")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"public_metadata\": {\n \"role\": \"admin\"\n },\n \"private_metadata\": {\n \"internal_id\": \"e6c19cfb-09a2-41e5-a908-e33193b7ca0a\"\n },\n \"unsafe_metadata\": {\n \"birthday\": \"2025-05-12\"\n }\n}"
response = http.request(request)
puts response.read_body{
"public_metadata": {
"role": "admin"
},
"private_metadata": {
"internal_id": "e6c19cfb-09a2-41e5-a908-e33193b7ca0a"
},
"unsafe_metadata": {
"birthday": "2025-05-12"
}
}{
"code": 400,
"message": "Bad Request"
}{
"code": 404,
"message": "Not found"
}{
"code": 500,
"message": "Internal Server Error"
}Updates a users metadata by deep merging the metadata patch from
the request with existing metadata.
Set the entire request to
null to clear all metadata:
Set any of public_metadata, private_metadata, unsafe_metadata to null to
clear metadata for that category.
An empty object ({}) for the top level request object or an empty object for
public_metadata, private_metadata or the unsafe_metadata property represent
a noop patch.
Unknown top level keys besides public_metadata, private_metadata or unsafe_metadata
are ignored.
All other top level request values (e.g. an empty string, a non-empty string, an array) result in a bad request.Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your API key. Must only be used when using Hanko Cloud.
Path Parameters
UUID of the requested object
Body
application/json
Was this page helpful?
⌘I