Create Survey
curl --request POST \
--url https://dash.tinyanalytics.io/api/sites/{site}/surveys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"name": "Post-purchase NPS",
"type": "popover",
"questions": [
{
"type": "rating",
"question": "How likely are you to recommend us?",
"display": "number",
"scale": 10,
"isNps": true
},
{
"type": "open",
"question": "What's the main reason for your score?",
"optional": true
}
],
"conditions": {
"url": "/checkout/success",
"urlMatchType": "contains"
}
}
EOFimport requests
url = "https://dash.tinyanalytics.io/api/sites/{site}/surveys"
payload = {
"name": "Post-purchase NPS",
"type": "popover",
"questions": [
{
"type": "rating",
"question": "How likely are you to recommend us?",
"display": "number",
"scale": 10,
"isNps": True
},
{
"type": "open",
"question": "What's the main reason for your score?",
"optional": True
}
],
"conditions": {
"url": "/checkout/success",
"urlMatchType": "contains"
}
}
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: 'Post-purchase NPS',
type: 'popover',
questions: [
{
type: 'rating',
question: 'How likely are you to recommend us?',
display: 'number',
scale: 10,
isNps: true
},
{
type: 'open',
question: 'What\'s the main reason for your score?',
optional: true
}
],
conditions: {url: '/checkout/success', urlMatchType: 'contains'}
})
};
fetch('https://dash.tinyanalytics.io/api/sites/{site}/surveys', 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://dash.tinyanalytics.io/api/sites/{site}/surveys",
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' => 'Post-purchase NPS',
'type' => 'popover',
'questions' => [
[
'type' => 'rating',
'question' => 'How likely are you to recommend us?',
'display' => 'number',
'scale' => 10,
'isNps' => true
],
[
'type' => 'open',
'question' => 'What\'s the main reason for your score?',
'optional' => true
]
],
'conditions' => [
'url' => '/checkout/success',
'urlMatchType' => 'contains'
]
]),
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://dash.tinyanalytics.io/api/sites/{site}/surveys"
payload := strings.NewReader("{\n \"name\": \"Post-purchase NPS\",\n \"type\": \"popover\",\n \"questions\": [\n {\n \"type\": \"rating\",\n \"question\": \"How likely are you to recommend us?\",\n \"display\": \"number\",\n \"scale\": 10,\n \"isNps\": true\n },\n {\n \"type\": \"open\",\n \"question\": \"What's the main reason for your score?\",\n \"optional\": true\n }\n ],\n \"conditions\": {\n \"url\": \"/checkout/success\",\n \"urlMatchType\": \"contains\"\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://dash.tinyanalytics.io/api/sites/{site}/surveys")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Post-purchase NPS\",\n \"type\": \"popover\",\n \"questions\": [\n {\n \"type\": \"rating\",\n \"question\": \"How likely are you to recommend us?\",\n \"display\": \"number\",\n \"scale\": 10,\n \"isNps\": true\n },\n {\n \"type\": \"open\",\n \"question\": \"What's the main reason for your score?\",\n \"optional\": true\n }\n ],\n \"conditions\": {\n \"url\": \"/checkout/success\",\n \"urlMatchType\": \"contains\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://dash.tinyanalytics.io/api/sites/{site}/surveys")
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\": \"Post-purchase NPS\",\n \"type\": \"popover\",\n \"questions\": [\n {\n \"type\": \"rating\",\n \"question\": \"How likely are you to recommend us?\",\n \"display\": \"number\",\n \"scale\": 10,\n \"isNps\": true\n },\n {\n \"type\": \"open\",\n \"question\": \"What's the main reason for your score?\",\n \"optional\": true\n }\n ],\n \"conditions\": {\n \"url\": \"/checkout/success\",\n \"urlMatchType\": \"contains\"\n }\n}"
response = http.request(request)
puts response.read_bodyCreate Survey
Creates a survey definition. Requires manage role.
POST
/
sites
/
{site}
/
surveys
Create Survey
curl --request POST \
--url https://dash.tinyanalytics.io/api/sites/{site}/surveys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"name": "Post-purchase NPS",
"type": "popover",
"questions": [
{
"type": "rating",
"question": "How likely are you to recommend us?",
"display": "number",
"scale": 10,
"isNps": true
},
{
"type": "open",
"question": "What's the main reason for your score?",
"optional": true
}
],
"conditions": {
"url": "/checkout/success",
"urlMatchType": "contains"
}
}
EOFimport requests
url = "https://dash.tinyanalytics.io/api/sites/{site}/surveys"
payload = {
"name": "Post-purchase NPS",
"type": "popover",
"questions": [
{
"type": "rating",
"question": "How likely are you to recommend us?",
"display": "number",
"scale": 10,
"isNps": True
},
{
"type": "open",
"question": "What's the main reason for your score?",
"optional": True
}
],
"conditions": {
"url": "/checkout/success",
"urlMatchType": "contains"
}
}
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: 'Post-purchase NPS',
type: 'popover',
questions: [
{
type: 'rating',
question: 'How likely are you to recommend us?',
display: 'number',
scale: 10,
isNps: true
},
{
type: 'open',
question: 'What\'s the main reason for your score?',
optional: true
}
],
conditions: {url: '/checkout/success', urlMatchType: 'contains'}
})
};
fetch('https://dash.tinyanalytics.io/api/sites/{site}/surveys', 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://dash.tinyanalytics.io/api/sites/{site}/surveys",
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' => 'Post-purchase NPS',
'type' => 'popover',
'questions' => [
[
'type' => 'rating',
'question' => 'How likely are you to recommend us?',
'display' => 'number',
'scale' => 10,
'isNps' => true
],
[
'type' => 'open',
'question' => 'What\'s the main reason for your score?',
'optional' => true
]
],
'conditions' => [
'url' => '/checkout/success',
'urlMatchType' => 'contains'
]
]),
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://dash.tinyanalytics.io/api/sites/{site}/surveys"
payload := strings.NewReader("{\n \"name\": \"Post-purchase NPS\",\n \"type\": \"popover\",\n \"questions\": [\n {\n \"type\": \"rating\",\n \"question\": \"How likely are you to recommend us?\",\n \"display\": \"number\",\n \"scale\": 10,\n \"isNps\": true\n },\n {\n \"type\": \"open\",\n \"question\": \"What's the main reason for your score?\",\n \"optional\": true\n }\n ],\n \"conditions\": {\n \"url\": \"/checkout/success\",\n \"urlMatchType\": \"contains\"\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://dash.tinyanalytics.io/api/sites/{site}/surveys")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Post-purchase NPS\",\n \"type\": \"popover\",\n \"questions\": [\n {\n \"type\": \"rating\",\n \"question\": \"How likely are you to recommend us?\",\n \"display\": \"number\",\n \"scale\": 10,\n \"isNps\": true\n },\n {\n \"type\": \"open\",\n \"question\": \"What's the main reason for your score?\",\n \"optional\": true\n }\n ],\n \"conditions\": {\n \"url\": \"/checkout/success\",\n \"urlMatchType\": \"contains\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://dash.tinyanalytics.io/api/sites/{site}/surveys")
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\": \"Post-purchase NPS\",\n \"type\": \"popover\",\n \"questions\": [\n {\n \"type\": \"rating\",\n \"question\": \"How likely are you to recommend us?\",\n \"display\": \"number\",\n \"scale\": 10,\n \"isNps\": true\n },\n {\n \"type\": \"open\",\n \"question\": \"What's the main reason for your score?\",\n \"optional\": true\n }\n ],\n \"conditions\": {\n \"url\": \"/checkout/success\",\n \"urlMatchType\": \"contains\"\n }\n}"
response = http.request(request)
puts response.read_bodyAuthorizations
An API key created in your account settings, sent as Authorization: Bearer <key>.
Path Parameters
Site ID.
Body
application/json
Response
Success.
Related topics
How tinyanalytics Handles Analytics DataPrivacy-Friendly Web and Product AnalyticsProduct Feedback and NPS Surveys⌘I