Create Schemas
Create/Replace One
POST
/
projects
/
{projectId}
/
schemas
/
{entityType}
/
{name}
Create/Replace One
curl --request POST \
--url https://{regionAndDomain}.com/api/app/projects/{projectId}/schemas/{entityType}/{name} \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"description": "<string>",
"properties": {},
"metadata": {
"com.mixpanel": {
"$source": "<string>",
"displayName": "<string>",
"tags": [
"<string>"
],
"hidden": false,
"dropped": false,
"contacts": [
"<string>"
],
"teamContacts": [
"<string>"
]
}
}
}
'import requests
url = "https://{regionAndDomain}.com/api/app/projects/{projectId}/schemas/{entityType}/{name}"
payload = {
"description": "<string>",
"properties": {},
"metadata": { "com.mixpanel": {
"$source": "<string>",
"displayName": "<string>",
"tags": ["<string>"],
"hidden": False,
"dropped": False,
"contacts": ["<string>"],
"teamContacts": ["<string>"]
} }
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({
description: '<string>',
properties: {},
metadata: {
'com.mixpanel': {
$source: '<string>',
displayName: '<string>',
tags: ['<string>'],
hidden: false,
dropped: false,
contacts: ['<string>'],
teamContacts: ['<string>']
}
}
})
};
fetch('https://{regionAndDomain}.com/api/app/projects/{projectId}/schemas/{entityType}/{name}', 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://{regionAndDomain}.com/api/app/projects/{projectId}/schemas/{entityType}/{name}",
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([
'description' => '<string>',
'properties' => [
],
'metadata' => [
'com.mixpanel' => [
'$source' => '<string>',
'displayName' => '<string>',
'tags' => [
'<string>'
],
'hidden' => false,
'dropped' => false,
'contacts' => [
'<string>'
],
'teamContacts' => [
'<string>'
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"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://{regionAndDomain}.com/api/app/projects/{projectId}/schemas/{entityType}/{name}"
payload := strings.NewReader("{\n \"description\": \"<string>\",\n \"properties\": {},\n \"metadata\": {\n \"com.mixpanel\": {\n \"$source\": \"<string>\",\n \"displayName\": \"<string>\",\n \"tags\": [\n \"<string>\"\n ],\n \"hidden\": false,\n \"dropped\": false,\n \"contacts\": [\n \"<string>\"\n ],\n \"teamContacts\": [\n \"<string>\"\n ]\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
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://{regionAndDomain}.com/api/app/projects/{projectId}/schemas/{entityType}/{name}")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"description\": \"<string>\",\n \"properties\": {},\n \"metadata\": {\n \"com.mixpanel\": {\n \"$source\": \"<string>\",\n \"displayName\": \"<string>\",\n \"tags\": [\n \"<string>\"\n ],\n \"hidden\": false,\n \"dropped\": false,\n \"contacts\": [\n \"<string>\"\n ],\n \"teamContacts\": [\n \"<string>\"\n ]\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{regionAndDomain}.com/api/app/projects/{projectId}/schemas/{entityType}/{name}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"description\": \"<string>\",\n \"properties\": {},\n \"metadata\": {\n \"com.mixpanel\": {\n \"$source\": \"<string>\",\n \"displayName\": \"<string>\",\n \"tags\": [\n \"<string>\"\n ],\n \"hidden\": false,\n \"dropped\": false,\n \"contacts\": [\n \"<string>\"\n ],\n \"teamContacts\": [\n \"<string>\"\n ]\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"status": "ok"
}{
"error": "<string>",
"status": "error"
}{
"error": "<string>",
"status": "error"
}{
"error": "<string>",
"status": "error"
}Upload a schema for a single entity. If a schema already exists for a specified entity, it will be replaced by the one you upload.
Metadata merging behaviorIf the new schema is missing
metadata properties that are currently set in the existing schema for that entity, those properties will be merged into the new schema. For example, if your current schema has {"metadata": {"com.mixpanel": {"hidden": true}}} and you upload a new schema without “hidden”, we will merge "hidden": true to your uploaded schema’s metadata. If you want to remove that property, set the value to null.Adding a schema for User ProfilesTo add a schema for your User Profiles, specify the
entityType as profile and the name as $user.Example POST Body
{
"$schema": "http://json-schema.org/draft-07/schema",
"description": "Tracked when a user adds an item to their cart.",
"required": [
"item_name",
"item_id",
"item_price"
],
"additionalProperties": true,
"metadata": {
"com.mixpanel": {
"tags": [
"Shopping",
"KPIs"
],
"displayName": "Item Purchased",
"hidden": false,
"dropped": false,
"contacts": [
"first.last@mixpanel.com"
],
"teamContacts": [
"Analytics Team"
]
}
},
"properties": {
"item_name": {
"type": "string",
"description": "The name of the item",
"examples": [
"Blue Widget"
],
"metadata": {
"com.mixpanel": {
"displayName": "Item Name"
}
}
},
"item_id": {
"type": "integer",
"description": "The internal id of the item",
"examples": [
12345
],
"metadata": {
"com.mixpanel": {
"displayName": "Item ID"
}
}
},
"item_price": {
"type": "number",
"description": "The current price of the item",
"examples": [
25.35
],
"metadata": {
"com.mixpanel": {
"displayName": "Price"
}
}
},
"promo_id": {
"type": "integer",
"description": "The id of any promo in progress for this item",
"examples": [
82523,
18382
],
"metadata": {
"com.mixpanel": {
"displayName": "Promo ID"
}
}
},
"date_added_to_catalog": {
"type": "string",
"format": "date-time",
"description": "The date this item was added to the store catalog",
"examples": [
"2015-03-05T15:25:23"
],
"metadata": {
"com.mixpanel": {
"displayName": "Date Added"
}
}
}
}
}
Authorizations
Service Account
Path Parameters
Your project id (eg: 12345)
The entity type (eg: event)
Available options:
event, profile The entity name (eg: Added To Cart)
Body
application/json
Response
Success
Available options:
ok Was this page helpful?
⌘I
Create/Replace One
curl --request POST \
--url https://{regionAndDomain}.com/api/app/projects/{projectId}/schemas/{entityType}/{name} \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"description": "<string>",
"properties": {},
"metadata": {
"com.mixpanel": {
"$source": "<string>",
"displayName": "<string>",
"tags": [
"<string>"
],
"hidden": false,
"dropped": false,
"contacts": [
"<string>"
],
"teamContacts": [
"<string>"
]
}
}
}
'import requests
url = "https://{regionAndDomain}.com/api/app/projects/{projectId}/schemas/{entityType}/{name}"
payload = {
"description": "<string>",
"properties": {},
"metadata": { "com.mixpanel": {
"$source": "<string>",
"displayName": "<string>",
"tags": ["<string>"],
"hidden": False,
"dropped": False,
"contacts": ["<string>"],
"teamContacts": ["<string>"]
} }
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({
description: '<string>',
properties: {},
metadata: {
'com.mixpanel': {
$source: '<string>',
displayName: '<string>',
tags: ['<string>'],
hidden: false,
dropped: false,
contacts: ['<string>'],
teamContacts: ['<string>']
}
}
})
};
fetch('https://{regionAndDomain}.com/api/app/projects/{projectId}/schemas/{entityType}/{name}', 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://{regionAndDomain}.com/api/app/projects/{projectId}/schemas/{entityType}/{name}",
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([
'description' => '<string>',
'properties' => [
],
'metadata' => [
'com.mixpanel' => [
'$source' => '<string>',
'displayName' => '<string>',
'tags' => [
'<string>'
],
'hidden' => false,
'dropped' => false,
'contacts' => [
'<string>'
],
'teamContacts' => [
'<string>'
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"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://{regionAndDomain}.com/api/app/projects/{projectId}/schemas/{entityType}/{name}"
payload := strings.NewReader("{\n \"description\": \"<string>\",\n \"properties\": {},\n \"metadata\": {\n \"com.mixpanel\": {\n \"$source\": \"<string>\",\n \"displayName\": \"<string>\",\n \"tags\": [\n \"<string>\"\n ],\n \"hidden\": false,\n \"dropped\": false,\n \"contacts\": [\n \"<string>\"\n ],\n \"teamContacts\": [\n \"<string>\"\n ]\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
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://{regionAndDomain}.com/api/app/projects/{projectId}/schemas/{entityType}/{name}")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"description\": \"<string>\",\n \"properties\": {},\n \"metadata\": {\n \"com.mixpanel\": {\n \"$source\": \"<string>\",\n \"displayName\": \"<string>\",\n \"tags\": [\n \"<string>\"\n ],\n \"hidden\": false,\n \"dropped\": false,\n \"contacts\": [\n \"<string>\"\n ],\n \"teamContacts\": [\n \"<string>\"\n ]\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{regionAndDomain}.com/api/app/projects/{projectId}/schemas/{entityType}/{name}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"description\": \"<string>\",\n \"properties\": {},\n \"metadata\": {\n \"com.mixpanel\": {\n \"$source\": \"<string>\",\n \"displayName\": \"<string>\",\n \"tags\": [\n \"<string>\"\n ],\n \"hidden\": false,\n \"dropped\": false,\n \"contacts\": [\n \"<string>\"\n ],\n \"teamContacts\": [\n \"<string>\"\n ]\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"status": "ok"
}{
"error": "<string>",
"status": "error"
}{
"error": "<string>",
"status": "error"
}{
"error": "<string>",
"status": "error"
}