Skip to main content
POST
/
jobs
/
{job_id}
/
request-cancellation
Request cancellation of a job
curl --request POST \
  --url https://api-dev.narrative.io/jobs/{job_id}/request-cancellation \
  --header 'Authorization: Bearer <token>'
import requests

url = "https://api-dev.narrative.io/jobs/{job_id}/request-cancellation"

headers = {"Authorization": "Bearer <token>"}

response = requests.post(url, headers=headers)

print(response.text)
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};

fetch('https://api-dev.narrative.io/jobs/{job_id}/request-cancellation', 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/jobs/{job_id}/request-cancellation",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"net/http"
"io"
)

func main() {

url := "https://api-dev.narrative.io/jobs/{job_id}/request-cancellation"

req, _ := http.NewRequest("POST", url, nil)

req.Header.Add("Authorization", "Bearer <token>")

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/jobs/{job_id}/request-cancellation")
.header("Authorization", "Bearer <token>")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api-dev.narrative.io/jobs/{job_id}/request-cancellation")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'

response = http.request(request)
puts response.read_body
{
  "job_id": "2a5b9ad7-dc8f-47bb-8e62-843a38f8054c",
  "data_plane_id": "f79cbdae-4848-47ca-95e8-69588364d185",
  "request_source": {
    "type": "api_user",
    "company_id": 1,
    "user_id": 407
  },
  "state": "completed",
  "type": "materialize-view",
  "input": {
    "nql": "CREATE MATERIALIZED VIEW \"test_stats\" AS SELECT \"value\" FROM \"company_data\".\"10674\"",
    "dataset_id": 10736,
    "stats_enabled": true,
    "compiled_select": "SELECT\n  `ds_10674`.`value`\nFROM\n  narrative.datasets.ds_10674 `ds_10674`"
  },
  "executor": "job-executor-98e1f48e-bf54-4f11-bbd1-73c445120266",
  "idempotency_key": "10736:29329c64e7b8a4eda86aaabe04872b832ab456b5543d0c259c812525391f158c:669a5f8e4f373c2f907700decde47511aac6470f5698e2b856fb07f09160e5f2",
  "result": {
    "dataset_id": 10736,
    "snapshot_id": 1724919539450264600,
    "recalculation_id": "abf9a2ec-426b-4751-bd16-fcb435061925"
  },
  "created_at": "2023-10-31T11:19:13.400498",
  "updated_at": "2023-10-31T11:25:08.327209",
  "ended_at": "2023-10-31T11:25:08.327194"
}
{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

job_id
string<uuid>
required

Unique identifier for a job.

Response

OK

job_id
string<uuid>
required

Unique identifier for the job.

data_plane_id
string<uuid>
required

The data plane the job runs on.

request_source
object
required
Example:
{
"type": "api_user",
"company_id": 1,
"user_id": 1248
}
state
enum<string>
default:pending
required
Available options:
failed,
cancelled,
completed,
pending,
pending_cancellation,
running
type
string
required

The type associated with the job. Jobs can have a type of nql-forecast or materialize-view.

input
object
required
Example:
{
"nql": "CREATE MATERIALIZED VIEW \"sampleNQL\" as WITH OrderedData AS (\n SELECT\n \"mobile_id_unique_identifier\".\"value\" AS mobile_id,\n \"timestamp_object\".\"day\",\n \"timestamp_object\".\"hour\",\n \"geographic_location\".\"latitude\",\n \"geographic_location\".\"longitude\",\n \"event_timestamp\",\n LAG(\"event_timestamp\", 1) OVER (PARTITION BY \"mobile_id_unique_identifier\".\"value\", \"geographic_location\".\"latitude\", \"geographic_location\".\"longitude\" ORDER BY \"event_timestamp\") AS prev_timestamp\n FROM\n \"company_data\".\"6402\"\n WHERE\n \"mobile_id_unique_identifier\".\"value\" IS NOT NULL \n), \nContinuousPresence AS (\n SELECT\n mobile_id,\n \"day\",\n \"hour\",\n latitude,\n longitude,\n event_timestamp,\n prev_timestamp,\n CASE\n WHEN extract(minute FROM event_timestamp) - extract(minute FROM prev_timestamp) BETWEEN 40 AND 120 THEN 1\n ELSE 0\n END AS is_continuous\n FROM\n OrderedData\n)\nSELECT\n mobile_id,\n \"day\",\n \"hour\",\n latitude,\n longitude\nFROM\n ContinuousPresence\nWHERE\n is_continuous = 1\nGROUP BY\n mobile_id,\n \"day\",\n \"hour\",\n latitude,\n longitude\n",
"dataset_id": 6404,
"stats_enabled": true,
"compiled_sql": "SELECT\n `t`.`mobile_id`,\n `t`.`day`,\n `t`.`hour`,\n `t`.`latitude`,\n `t`.`longitude`\nFROM\n (SELECT\n `ds_6402`.`mobile_id_unique_identifier`['value'] `mobile_id`,\n `ds_6402`.`timestamp_object`['day'] `day`,\n `ds_6402`.`timestamp_object`['hour'] `hour`,\n `ds_6402`.`geographic_location`['latitude'] `latitude`,\n `ds_6402`.`geographic_location`['longitude'] `longitude`,\n CASE\n WHEN EXTRACT(MINUTE FROM `ds_6402`.`event_timestamp`) - EXTRACT(MINUTE FROM LAG(`ds_6402`.`event_timestamp`, 1) OVER (\n PARTITION BY `ds_6402`.`mobile_id_unique_identifier`.`value`, `ds_6402`.`geographic_location`.`latitude`, `ds_6402`.`geographic_location`.`longitude`\n ORDER BY `ds_6402`.`event_timestamp` NULLS LAST)) >= 40 AND EXTRACT(MINUTE FROM `ds_6402`.`event_timestamp`) - EXTRACT(MINUTE FROM LAG(`ds_6402`.`event_timestamp`, 1) OVER (\n PARTITION BY `ds_6402`.`mobile_id_unique_identifier`.`value`, `ds_6402`.`geographic_location`.`latitude`, `ds_6402`.`geographic_location`.`longitude`\n ORDER BY `ds_6402`.`event_timestamp` NULLS LAST)) <= 120\n THEN 1\n ELSE 0\n END `is_continuous`\n FROM\n narrative.datasets.ds_6402 `ds_6402`) `t`\nWHERE\n `t`.`is_continuous` = 1\nGROUP BY\n `t`.`mobile_id`,\n `t`.`day`,\n `t`.`hour`,\n `t`.`latitude`,\n `t`.`longitude`"
}
executor
string
required

The internal job executor tied to the job.

failures
object[]
required

causes of job failure

idempotency_key
string
required

The unique ID associated with the job.

result
object
required

The output of a materialized view.

Example:
{
"dataset_id": 6404,
"snapshot_id": 739881302291276700,
"recalculation_id": "abf9a2ec-426b-4751-bd16-fcb435061925"
}
created_at
string<date-time>
required

The timestamp representing when the job was created.

updated_at
string<date-time>
required

The timestamp representing when the job was updated.

ended_at
string<date-time>
required

The timestamp representing when the job finished.

compute_pool_id
string<uuid>

The compute pool associated with the job, if any.

execution_cluster
enum<string>

The type of the execution cluster to run the job on.

  • dedicated runs job on a dedicated cluster.
  • shared runs job on a shared cluster.
Available options:
dedicated,
shared