Create Schemas
Create/Replace Multiple
POST
/
projects
/
{projectId}
/
schemas
Create/Replace Multiple
curl --request POST \
--url https://{regionAndDomain}.com/api/app/projects/{projectId}/schemas \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"entries": [
{
"name": "<string>",
"schemaJson": {
"description": "<string>",
"properties": {},
"metadata": {
"com.mixpanel": {
"$source": "<string>",
"displayName": "<string>",
"tags": [
"<string>"
],
"hidden": false,
"dropped": false,
"contacts": [
"<string>"
],
"teamContacts": [
"<string>"
]
}
}
}
}
],
"truncate": false
}
'import requests
url = "https://{regionAndDomain}.com/api/app/projects/{projectId}/schemas"
payload = {
"entries": [
{
"name": "<string>",
"schemaJson": {
"description": "<string>",
"properties": {},
"metadata": { "com.mixpanel": {
"$source": "<string>",
"displayName": "<string>",
"tags": ["<string>"],
"hidden": False,
"dropped": False,
"contacts": ["<string>"],
"teamContacts": ["<string>"]
} }
}
}
],
"truncate": False
}
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({
entries: [
{
name: '<string>',
schemaJson: {
description: '<string>',
properties: {},
metadata: {
'com.mixpanel': {
$source: '<string>',
displayName: '<string>',
tags: ['<string>'],
hidden: false,
dropped: false,
contacts: ['<string>'],
teamContacts: ['<string>']
}
}
}
}
],
truncate: false
})
};
fetch('https://{regionAndDomain}.com/api/app/projects/{projectId}/schemas', 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",
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([
'entries' => [
[
'name' => '<string>',
'schemaJson' => [
'description' => '<string>',
'properties' => [
],
'metadata' => [
'com.mixpanel' => [
'$source' => '<string>',
'displayName' => '<string>',
'tags' => [
'<string>'
],
'hidden' => false,
'dropped' => false,
'contacts' => [
'<string>'
],
'teamContacts' => [
'<string>'
]
]
]
]
]
],
'truncate' => false
]),
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"
payload := strings.NewReader("{\n \"entries\": [\n {\n \"name\": \"<string>\",\n \"schemaJson\": {\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 }\n }\n ],\n \"truncate\": false\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")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"entries\": [\n {\n \"name\": \"<string>\",\n \"schemaJson\": {\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 }\n }\n ],\n \"truncate\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{regionAndDomain}.com/api/app/projects/{projectId}/schemas")
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 \"entries\": [\n {\n \"name\": \"<string>\",\n \"schemaJson\": {\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 }\n }\n ],\n \"truncate\": false\n}"
response = http.request(request)
puts response.read_body{
"results": {
"added": 123,
"deleted": 123
},
"status": "ok"
}{
"error": "<string>",
"status": "error"
}{
"error": "<string>",
"status": "error"
}Upload schemas in bulk to the specified project. 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
{
"entries": [
{
"entityType": "event",
"name": "Added To Cart",
"schemaJson": {
"$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"
}
}
}
}
}
}
],
"truncate": false
}
Authorizations
Service Account
Path Parameters
Your project id (eg: 12345)
Body
application/json
Was this page helpful?
⌘I
Create/Replace Multiple
curl --request POST \
--url https://{regionAndDomain}.com/api/app/projects/{projectId}/schemas \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"entries": [
{
"name": "<string>",
"schemaJson": {
"description": "<string>",
"properties": {},
"metadata": {
"com.mixpanel": {
"$source": "<string>",
"displayName": "<string>",
"tags": [
"<string>"
],
"hidden": false,
"dropped": false,
"contacts": [
"<string>"
],
"teamContacts": [
"<string>"
]
}
}
}
}
],
"truncate": false
}
'import requests
url = "https://{regionAndDomain}.com/api/app/projects/{projectId}/schemas"
payload = {
"entries": [
{
"name": "<string>",
"schemaJson": {
"description": "<string>",
"properties": {},
"metadata": { "com.mixpanel": {
"$source": "<string>",
"displayName": "<string>",
"tags": ["<string>"],
"hidden": False,
"dropped": False,
"contacts": ["<string>"],
"teamContacts": ["<string>"]
} }
}
}
],
"truncate": False
}
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({
entries: [
{
name: '<string>',
schemaJson: {
description: '<string>',
properties: {},
metadata: {
'com.mixpanel': {
$source: '<string>',
displayName: '<string>',
tags: ['<string>'],
hidden: false,
dropped: false,
contacts: ['<string>'],
teamContacts: ['<string>']
}
}
}
}
],
truncate: false
})
};
fetch('https://{regionAndDomain}.com/api/app/projects/{projectId}/schemas', 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",
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([
'entries' => [
[
'name' => '<string>',
'schemaJson' => [
'description' => '<string>',
'properties' => [
],
'metadata' => [
'com.mixpanel' => [
'$source' => '<string>',
'displayName' => '<string>',
'tags' => [
'<string>'
],
'hidden' => false,
'dropped' => false,
'contacts' => [
'<string>'
],
'teamContacts' => [
'<string>'
]
]
]
]
]
],
'truncate' => false
]),
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"
payload := strings.NewReader("{\n \"entries\": [\n {\n \"name\": \"<string>\",\n \"schemaJson\": {\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 }\n }\n ],\n \"truncate\": false\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")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"entries\": [\n {\n \"name\": \"<string>\",\n \"schemaJson\": {\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 }\n }\n ],\n \"truncate\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{regionAndDomain}.com/api/app/projects/{projectId}/schemas")
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 \"entries\": [\n {\n \"name\": \"<string>\",\n \"schemaJson\": {\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 }\n }\n ],\n \"truncate\": false\n}"
response = http.request(request)
puts response.read_body{
"results": {
"added": 123,
"deleted": 123
},
"status": "ok"
}{
"error": "<string>",
"status": "error"
}{
"error": "<string>",
"status": "error"
}