curl --request POST \
--url https://api-dev.narrative.io/v2/queries \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "query1",
"display_name": "Query One",
"tags": [
"tag1",
"tag2"
],
"collaborators": {
"query": {
"type": "inclusion",
"company_ids": [
789
]
},
"view": {
"type": "all"
}
},
"ast": {
"type": "select",
"nql": "SELECT age FROM narrative.rosetta_stone",
"budget": null,
"columns": [
{
"type": "table",
"nql": "age",
"db": null,
"schema": null,
"table": "age"
}
],
"from": {
"type": "table",
"nql": "narrative.rosetta_stone",
"db": null,
"schema": "narrative",
"table": "rosetta_stone"
},
"group_by": [],
"having": null,
"is_distinct": false,
"limit": null,
"order_by": [],
"qualify": null,
"where": null,
"windows": [],
"with": []
}
}
'import requests
url = "https://api-dev.narrative.io/v2/queries"
payload = {
"name": "query1",
"display_name": "Query One",
"tags": ["tag1", "tag2"],
"collaborators": {
"query": {
"type": "inclusion",
"company_ids": [789]
},
"view": { "type": "all" }
},
"ast": {
"type": "select",
"nql": "SELECT age FROM narrative.rosetta_stone",
"budget": None,
"columns": [
{
"type": "table",
"nql": "age",
"db": None,
"schema": None,
"table": "age"
}
],
"from": {
"type": "table",
"nql": "narrative.rosetta_stone",
"db": None,
"schema": "narrative",
"table": "rosetta_stone"
},
"group_by": [],
"having": None,
"is_distinct": False,
"limit": None,
"order_by": [],
"qualify": None,
"where": None,
"windows": [],
"with": []
}
}
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: 'query1',
display_name: 'Query One',
tags: ['tag1', 'tag2'],
collaborators: {query: {type: 'inclusion', company_ids: [789]}, view: {type: 'all'}},
ast: {
type: 'select',
nql: 'SELECT age FROM narrative.rosetta_stone',
budget: null,
columns: [{type: 'table', nql: 'age', db: null, schema: null, table: 'age'}],
from: {
type: 'table',
nql: 'narrative.rosetta_stone',
db: null,
schema: 'narrative',
table: 'rosetta_stone'
},
group_by: [],
having: null,
is_distinct: false,
limit: null,
order_by: [],
qualify: null,
where: null,
windows: [],
with: []
}
})
};
fetch('https://api-dev.narrative.io/v2/queries', 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/queries",
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' => 'query1',
'display_name' => 'Query One',
'tags' => [
'tag1',
'tag2'
],
'collaborators' => [
'query' => [
'type' => 'inclusion',
'company_ids' => [
789
]
],
'view' => [
'type' => 'all'
]
],
'ast' => [
'type' => 'select',
'nql' => 'SELECT age FROM narrative.rosetta_stone',
'budget' => null,
'columns' => [
[
'type' => 'table',
'nql' => 'age',
'db' => null,
'schema' => null,
'table' => 'age'
]
],
'from' => [
'type' => 'table',
'nql' => 'narrative.rosetta_stone',
'db' => null,
'schema' => 'narrative',
'table' => 'rosetta_stone'
],
'group_by' => [
],
'having' => null,
'is_distinct' => false,
'limit' => null,
'order_by' => [
],
'qualify' => null,
'where' => null,
'windows' => [
],
'with' => [
]
]
]),
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/queries"
payload := strings.NewReader("{\n \"name\": \"query1\",\n \"display_name\": \"Query One\",\n \"tags\": [\n \"tag1\",\n \"tag2\"\n ],\n \"collaborators\": {\n \"query\": {\n \"type\": \"inclusion\",\n \"company_ids\": [\n 789\n ]\n },\n \"view\": {\n \"type\": \"all\"\n }\n },\n \"ast\": {\n \"type\": \"select\",\n \"nql\": \"SELECT age FROM narrative.rosetta_stone\",\n \"budget\": null,\n \"columns\": [\n {\n \"type\": \"table\",\n \"nql\": \"age\",\n \"db\": null,\n \"schema\": null,\n \"table\": \"age\"\n }\n ],\n \"from\": {\n \"type\": \"table\",\n \"nql\": \"narrative.rosetta_stone\",\n \"db\": null,\n \"schema\": \"narrative\",\n \"table\": \"rosetta_stone\"\n },\n \"group_by\": [],\n \"having\": null,\n \"is_distinct\": false,\n \"limit\": null,\n \"order_by\": [],\n \"qualify\": null,\n \"where\": null,\n \"windows\": [],\n \"with\": []\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-dev.narrative.io/v2/queries")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"query1\",\n \"display_name\": \"Query One\",\n \"tags\": [\n \"tag1\",\n \"tag2\"\n ],\n \"collaborators\": {\n \"query\": {\n \"type\": \"inclusion\",\n \"company_ids\": [\n 789\n ]\n },\n \"view\": {\n \"type\": \"all\"\n }\n },\n \"ast\": {\n \"type\": \"select\",\n \"nql\": \"SELECT age FROM narrative.rosetta_stone\",\n \"budget\": null,\n \"columns\": [\n {\n \"type\": \"table\",\n \"nql\": \"age\",\n \"db\": null,\n \"schema\": null,\n \"table\": \"age\"\n }\n ],\n \"from\": {\n \"type\": \"table\",\n \"nql\": \"narrative.rosetta_stone\",\n \"db\": null,\n \"schema\": \"narrative\",\n \"table\": \"rosetta_stone\"\n },\n \"group_by\": [],\n \"having\": null,\n \"is_distinct\": false,\n \"limit\": null,\n \"order_by\": [],\n \"qualify\": null,\n \"where\": null,\n \"windows\": [],\n \"with\": []\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-dev.narrative.io/v2/queries")
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\": \"query1\",\n \"display_name\": \"Query One\",\n \"tags\": [\n \"tag1\",\n \"tag2\"\n ],\n \"collaborators\": {\n \"query\": {\n \"type\": \"inclusion\",\n \"company_ids\": [\n 789\n ]\n },\n \"view\": {\n \"type\": \"all\"\n }\n },\n \"ast\": {\n \"type\": \"select\",\n \"nql\": \"SELECT age FROM narrative.rosetta_stone\",\n \"budget\": null,\n \"columns\": [\n {\n \"type\": \"table\",\n \"nql\": \"age\",\n \"db\": null,\n \"schema\": null,\n \"table\": \"age\"\n }\n ],\n \"from\": {\n \"type\": \"table\",\n \"nql\": \"narrative.rosetta_stone\",\n \"db\": null,\n \"schema\": \"narrative\",\n \"table\": \"rosetta_stone\"\n },\n \"group_by\": [],\n \"having\": null,\n \"is_distinct\": false,\n \"limit\": null,\n \"order_by\": [],\n \"qualify\": null,\n \"where\": null,\n \"windows\": [],\n \"with\": []\n }\n}"
response = http.request(request)
puts response.read_body{
"name": "query1",
"id": "7409b999-2a9a-40cd-89dc-8430d85e0391",
"display_name": "Query One",
"owner": {
"company_id": 456,
"company_name": "ExampleCorp",
"company_slug": "examplecorp"
},
"tags": [
"tag1",
"tag2"
],
"collaborators": {
"query": {
"type": "inclusion",
"company_ids": [
789
]
},
"view": {
"type": "all"
}
},
"is_owned": true,
"metadata": {
"created_at": "2024-04-12T19:57:05.012908",
"created_by_user_id": 321,
"updated_at": "2024-04-12T20:03:48.031825",
"updated_by_user_id": 321
},
"ast": {
"type": "select",
"nql": "SELECT age FROM narrative.rosetta_stone",
"budget": null,
"columns": [
{
"type": "table",
"nql": "age",
"db": null,
"schema": null,
"table": "age"
}
],
"from": {
"type": "table",
"nql": "narrative.rosetta_stone",
"db": null,
"schema": "narrative",
"table": "rosetta_stone"
},
"group_by": [],
"having": null,
"is_distinct": false,
"limit": null,
"order_by": [],
"qualify": null,
"where": null,
"windows": [],
"with": []
}
}Create a query
Any number of properties can be updated on the same request. If a property is not sent on the payload, the value won’t be updated.
curl --request POST \
--url https://api-dev.narrative.io/v2/queries \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "query1",
"display_name": "Query One",
"tags": [
"tag1",
"tag2"
],
"collaborators": {
"query": {
"type": "inclusion",
"company_ids": [
789
]
},
"view": {
"type": "all"
}
},
"ast": {
"type": "select",
"nql": "SELECT age FROM narrative.rosetta_stone",
"budget": null,
"columns": [
{
"type": "table",
"nql": "age",
"db": null,
"schema": null,
"table": "age"
}
],
"from": {
"type": "table",
"nql": "narrative.rosetta_stone",
"db": null,
"schema": "narrative",
"table": "rosetta_stone"
},
"group_by": [],
"having": null,
"is_distinct": false,
"limit": null,
"order_by": [],
"qualify": null,
"where": null,
"windows": [],
"with": []
}
}
'import requests
url = "https://api-dev.narrative.io/v2/queries"
payload = {
"name": "query1",
"display_name": "Query One",
"tags": ["tag1", "tag2"],
"collaborators": {
"query": {
"type": "inclusion",
"company_ids": [789]
},
"view": { "type": "all" }
},
"ast": {
"type": "select",
"nql": "SELECT age FROM narrative.rosetta_stone",
"budget": None,
"columns": [
{
"type": "table",
"nql": "age",
"db": None,
"schema": None,
"table": "age"
}
],
"from": {
"type": "table",
"nql": "narrative.rosetta_stone",
"db": None,
"schema": "narrative",
"table": "rosetta_stone"
},
"group_by": [],
"having": None,
"is_distinct": False,
"limit": None,
"order_by": [],
"qualify": None,
"where": None,
"windows": [],
"with": []
}
}
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: 'query1',
display_name: 'Query One',
tags: ['tag1', 'tag2'],
collaborators: {query: {type: 'inclusion', company_ids: [789]}, view: {type: 'all'}},
ast: {
type: 'select',
nql: 'SELECT age FROM narrative.rosetta_stone',
budget: null,
columns: [{type: 'table', nql: 'age', db: null, schema: null, table: 'age'}],
from: {
type: 'table',
nql: 'narrative.rosetta_stone',
db: null,
schema: 'narrative',
table: 'rosetta_stone'
},
group_by: [],
having: null,
is_distinct: false,
limit: null,
order_by: [],
qualify: null,
where: null,
windows: [],
with: []
}
})
};
fetch('https://api-dev.narrative.io/v2/queries', 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/queries",
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' => 'query1',
'display_name' => 'Query One',
'tags' => [
'tag1',
'tag2'
],
'collaborators' => [
'query' => [
'type' => 'inclusion',
'company_ids' => [
789
]
],
'view' => [
'type' => 'all'
]
],
'ast' => [
'type' => 'select',
'nql' => 'SELECT age FROM narrative.rosetta_stone',
'budget' => null,
'columns' => [
[
'type' => 'table',
'nql' => 'age',
'db' => null,
'schema' => null,
'table' => 'age'
]
],
'from' => [
'type' => 'table',
'nql' => 'narrative.rosetta_stone',
'db' => null,
'schema' => 'narrative',
'table' => 'rosetta_stone'
],
'group_by' => [
],
'having' => null,
'is_distinct' => false,
'limit' => null,
'order_by' => [
],
'qualify' => null,
'where' => null,
'windows' => [
],
'with' => [
]
]
]),
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/queries"
payload := strings.NewReader("{\n \"name\": \"query1\",\n \"display_name\": \"Query One\",\n \"tags\": [\n \"tag1\",\n \"tag2\"\n ],\n \"collaborators\": {\n \"query\": {\n \"type\": \"inclusion\",\n \"company_ids\": [\n 789\n ]\n },\n \"view\": {\n \"type\": \"all\"\n }\n },\n \"ast\": {\n \"type\": \"select\",\n \"nql\": \"SELECT age FROM narrative.rosetta_stone\",\n \"budget\": null,\n \"columns\": [\n {\n \"type\": \"table\",\n \"nql\": \"age\",\n \"db\": null,\n \"schema\": null,\n \"table\": \"age\"\n }\n ],\n \"from\": {\n \"type\": \"table\",\n \"nql\": \"narrative.rosetta_stone\",\n \"db\": null,\n \"schema\": \"narrative\",\n \"table\": \"rosetta_stone\"\n },\n \"group_by\": [],\n \"having\": null,\n \"is_distinct\": false,\n \"limit\": null,\n \"order_by\": [],\n \"qualify\": null,\n \"where\": null,\n \"windows\": [],\n \"with\": []\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-dev.narrative.io/v2/queries")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"query1\",\n \"display_name\": \"Query One\",\n \"tags\": [\n \"tag1\",\n \"tag2\"\n ],\n \"collaborators\": {\n \"query\": {\n \"type\": \"inclusion\",\n \"company_ids\": [\n 789\n ]\n },\n \"view\": {\n \"type\": \"all\"\n }\n },\n \"ast\": {\n \"type\": \"select\",\n \"nql\": \"SELECT age FROM narrative.rosetta_stone\",\n \"budget\": null,\n \"columns\": [\n {\n \"type\": \"table\",\n \"nql\": \"age\",\n \"db\": null,\n \"schema\": null,\n \"table\": \"age\"\n }\n ],\n \"from\": {\n \"type\": \"table\",\n \"nql\": \"narrative.rosetta_stone\",\n \"db\": null,\n \"schema\": \"narrative\",\n \"table\": \"rosetta_stone\"\n },\n \"group_by\": [],\n \"having\": null,\n \"is_distinct\": false,\n \"limit\": null,\n \"order_by\": [],\n \"qualify\": null,\n \"where\": null,\n \"windows\": [],\n \"with\": []\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-dev.narrative.io/v2/queries")
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\": \"query1\",\n \"display_name\": \"Query One\",\n \"tags\": [\n \"tag1\",\n \"tag2\"\n ],\n \"collaborators\": {\n \"query\": {\n \"type\": \"inclusion\",\n \"company_ids\": [\n 789\n ]\n },\n \"view\": {\n \"type\": \"all\"\n }\n },\n \"ast\": {\n \"type\": \"select\",\n \"nql\": \"SELECT age FROM narrative.rosetta_stone\",\n \"budget\": null,\n \"columns\": [\n {\n \"type\": \"table\",\n \"nql\": \"age\",\n \"db\": null,\n \"schema\": null,\n \"table\": \"age\"\n }\n ],\n \"from\": {\n \"type\": \"table\",\n \"nql\": \"narrative.rosetta_stone\",\n \"db\": null,\n \"schema\": \"narrative\",\n \"table\": \"rosetta_stone\"\n },\n \"group_by\": [],\n \"having\": null,\n \"is_distinct\": false,\n \"limit\": null,\n \"order_by\": [],\n \"qualify\": null,\n \"where\": null,\n \"windows\": [],\n \"with\": []\n }\n}"
response = http.request(request)
puts response.read_body{
"name": "query1",
"id": "7409b999-2a9a-40cd-89dc-8430d85e0391",
"display_name": "Query One",
"owner": {
"company_id": 456,
"company_name": "ExampleCorp",
"company_slug": "examplecorp"
},
"tags": [
"tag1",
"tag2"
],
"collaborators": {
"query": {
"type": "inclusion",
"company_ids": [
789
]
},
"view": {
"type": "all"
}
},
"is_owned": true,
"metadata": {
"created_at": "2024-04-12T19:57:05.012908",
"created_by_user_id": 321,
"updated_at": "2024-04-12T20:03:48.031825",
"updated_by_user_id": 321
},
"ast": {
"type": "select",
"nql": "SELECT age FROM narrative.rosetta_stone",
"budget": null,
"columns": [
{
"type": "table",
"nql": "age",
"db": null,
"schema": null,
"table": "age"
}
],
"from": {
"type": "table",
"nql": "narrative.rosetta_stone",
"db": null,
"schema": "narrative",
"table": "rosetta_stone"
},
"group_by": [],
"having": null,
"is_distinct": false,
"limit": null,
"order_by": [],
"qualify": null,
"where": null,
"windows": [],
"with": []
}
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
It should be unique. Must be <= 256 characters and consist of only alphanumeric characters and underscores.
Describes who can view or query a resource
Show child attributes
Show child attributes
The AST representing the query.
Optional. Display Name must be non-empty and less than 1000 chars.
A human-friendly description of the query.
Optional. Each tag must be less than 256 chars.
Response
OK
- Option 1
- Option 2
It should be unique. Must be <= 256 characters and consist of only alphanumeric characters and underscores.
Describes who can view or query a resource
Show child attributes
Show child attributes
Information about the owner of the query
Show child attributes
Show child attributes
Metadata about when and by whom a query was created/updated
Show child attributes
Show child attributes
The AST representing the query.
Optional. Display Name must be non-empty and less than 1000 chars.
A human-friendly description of the query.
Optional. Each tag must be less than 256 chars.
Whether the requestor owns the query.
Was this page helpful?

