curl --request POST \
--url https://api-dev.narrative.io/v2/datasets/{dataset_id}/request-sample \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"compute_pool_id": "a81e1460-fbdc-4204-bd76-a9e496bf760d"
}
'import requests
url = "https://api-dev.narrative.io/v2/datasets/{dataset_id}/request-sample"
payload = { "compute_pool_id": "a81e1460-fbdc-4204-bd76-a9e496bf760d" }
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({compute_pool_id: 'a81e1460-fbdc-4204-bd76-a9e496bf760d'})
};
fetch('https://api-dev.narrative.io/v2/datasets/{dataset_id}/request-sample', 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-dev.narrative.io/v2/datasets/{dataset_id}/request-sample",
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([
'compute_pool_id' => 'a81e1460-fbdc-4204-bd76-a9e496bf760d'
]),
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-dev.narrative.io/v2/datasets/{dataset_id}/request-sample"
payload := strings.NewReader("{\n \"compute_pool_id\": \"a81e1460-fbdc-4204-bd76-a9e496bf760d\"\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-dev.narrative.io/v2/datasets/{dataset_id}/request-sample")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"compute_pool_id\": \"a81e1460-fbdc-4204-bd76-a9e496bf760d\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-dev.narrative.io/v2/datasets/{dataset_id}/request-sample")
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 \"compute_pool_id\": \"a81e1460-fbdc-4204-bd76-a9e496bf760d\"\n}"
response = http.request(request)
puts response.read_body{
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"name": "my-etl-workflow",
"specification": "document:\n dsl: '1.0.0'\n namespace: test\n name: test-workflow\n version: '1.0.0'\ndo:\n - createView:\n call: CreateMaterializedViewIfNotExists\n with:\n nql: \"CREATE MATERIALIZED VIEW workflow_output AS SELECT track_id FROM company_data.workflow_input\"\n - refreshView:\n call: RefreshMaterializedView\n with:\n datasetName: workflow_output\n - insertData:\n call: ExecuteDml\n with:\n nql: \"INSERT INTO company_data.workflow_input (track_id) VALUES ('test')\"\n",
"data_plane_id": "d1e2f3a4-b5c6-7890-abcd-ef1234567890",
"company_id": 100,
"created_at": "2025-01-15T10:30:00Z",
"created_by": 20,
"updated_at": "2025-01-15T10:30:00Z",
"status": "active",
"tags": [
"<string>"
],
"archived_at": null,
"run_id": "b7e3f1a2-4c5d-6e7f-8a9b-0c1d2e3f4a5b"
}{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}Sample a dataset and redact the sample
Samples the dataset, then has Narrative’s privacy model mark which columns of that sample hold personal data and how each should be masked. Both steps run as one workflow.
The response is that workflow and the id of its run. Check the run with
GET /workflows/{workflow_id}/runs; when it completes, read the model’s decisions with
GET /datasets/{dataset_id}/redaction and the masked rows with
GET /datasets/{dataset_id}/sample/redacted. If the run fails, no redaction is stored and
GET /datasets/{dataset_id}/redaction answers 404, as it does for any dataset without one. A run
that samples successfully and then fails to redact keeps the sample.
Each call creates its own workflow.
A body that cannot be decoded as RequestSampleRequest is treated as an empty body rather than
refused: a compute_pool_id that is not a UUID is ignored and the dataset’s default compute pool is
used.
POST /datasets/{dataset_id}/request-sample samples without redacting and returns a job instead.
Two differences beyond the redaction step: this endpoint refuses a company over its credit limit
with a 403, and an invalid sample query fails the run rather than this request.
curl --request POST \
--url https://api-dev.narrative.io/v2/datasets/{dataset_id}/request-sample \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"compute_pool_id": "a81e1460-fbdc-4204-bd76-a9e496bf760d"
}
'import requests
url = "https://api-dev.narrative.io/v2/datasets/{dataset_id}/request-sample"
payload = { "compute_pool_id": "a81e1460-fbdc-4204-bd76-a9e496bf760d" }
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({compute_pool_id: 'a81e1460-fbdc-4204-bd76-a9e496bf760d'})
};
fetch('https://api-dev.narrative.io/v2/datasets/{dataset_id}/request-sample', 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-dev.narrative.io/v2/datasets/{dataset_id}/request-sample",
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([
'compute_pool_id' => 'a81e1460-fbdc-4204-bd76-a9e496bf760d'
]),
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-dev.narrative.io/v2/datasets/{dataset_id}/request-sample"
payload := strings.NewReader("{\n \"compute_pool_id\": \"a81e1460-fbdc-4204-bd76-a9e496bf760d\"\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-dev.narrative.io/v2/datasets/{dataset_id}/request-sample")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"compute_pool_id\": \"a81e1460-fbdc-4204-bd76-a9e496bf760d\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-dev.narrative.io/v2/datasets/{dataset_id}/request-sample")
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 \"compute_pool_id\": \"a81e1460-fbdc-4204-bd76-a9e496bf760d\"\n}"
response = http.request(request)
puts response.read_body{
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"name": "my-etl-workflow",
"specification": "document:\n dsl: '1.0.0'\n namespace: test\n name: test-workflow\n version: '1.0.0'\ndo:\n - createView:\n call: CreateMaterializedViewIfNotExists\n with:\n nql: \"CREATE MATERIALIZED VIEW workflow_output AS SELECT track_id FROM company_data.workflow_input\"\n - refreshView:\n call: RefreshMaterializedView\n with:\n datasetName: workflow_output\n - insertData:\n call: ExecuteDml\n with:\n nql: \"INSERT INTO company_data.workflow_input (track_id) VALUES ('test')\"\n",
"data_plane_id": "d1e2f3a4-b5c6-7890-abcd-ef1234567890",
"company_id": 100,
"created_at": "2025-01-15T10:30:00Z",
"created_by": 20,
"updated_at": "2025-01-15T10:30:00Z",
"status": "active",
"tags": [
"<string>"
],
"archived_at": null,
"run_id": "b7e3f1a2-4c5d-6e7f-8a9b-0c1d2e3f4a5b"
}{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}Authorizations
Body
Optional settings for the sample step
Response
The created workflow, and the id of the run started for it.
The workflow specification in YAML format.
"document:\n dsl: '1.0.0'\n namespace: test\n name: test-workflow\n version: '1.0.0'\ndo:\n - createView:\n call: CreateMaterializedViewIfNotExists\n with:\n nql: \"CREATE MATERIALIZED VIEW workflow_output AS SELECT track_id FROM company_data.workflow_input\"\n - refreshView:\n call: RefreshMaterializedView\n with:\n datasetName: workflow_output\n - insertData:\n call: ExecuteDml\n with:\n nql: \"INSERT INTO company_data.workflow_input (track_id) VALUES ('test')\"\n"

