Identities
Merge Identities
POST
/
import
Merge Identities
curl --request POST \
--url https://{region}.mixpanel.com/import \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
[
{
"event": "$merge",
"properties": {
"$distinct_ids": [
"<string>"
]
}
}
]
'import requests
url = "https://{region}.mixpanel.com/import"
payload = [
{
"event": "$merge",
"properties": { "$distinct_ids": ["<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([{event: '$merge', properties: {$distinct_ids: ['<string>']}}])
};
fetch('https://{region}.mixpanel.com/import', 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://{region}.mixpanel.com/import",
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([
[
'event' => '$merge',
'properties' => [
'$distinct_ids' => [
'<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://{region}.mixpanel.com/import"
payload := strings.NewReader("[\n {\n \"event\": \"$merge\",\n \"properties\": {\n \"$distinct_ids\": [\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://{region}.mixpanel.com/import")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("[\n {\n \"event\": \"$merge\",\n \"properties\": {\n \"$distinct_ids\": [\n \"<string>\"\n ]\n }\n }\n]")
.asString();require 'uri'
require 'net/http'
url = URI("https://{region}.mixpanel.com/import")
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 {\n \"event\": \"$merge\",\n \"properties\": {\n \"$distinct_ids\": [\n \"<string>\"\n ]\n }\n }\n]"
response = http.request(request)
puts response.read_body{
"code": 200,
"num_records_imported": 2000,
"status": "OK"
}{
"code": 400,
"num_records_imported": 999,
"status": "Bad Request",
"failed_records": [
{
"index": 0,
"insert_id": "13c0b661-f48b-51cd-ba54-97c5999169c0",
"field": "properties.time",
"message": "'properties.time' is invalid: must be specified as seconds since epoch"
}
]
}{
"code": 401,
"error": "Invalid service account credentials",
"status": "Unauthorized"
}The
$merge event payload is only useful for projects using the Original ID Merge system; it has no functionality in other ID management systems. Please review this section of our documentation for more information.Merging identities is irreversible
$merge is a very powerful tool, so we will only accept $merge events that are sent via https://api.mixpanel.com/import, which is protected by the project api secret. You cannot unmerge distinct_id.
Authorizations
ServiceAccountProjectSecretOAuthToken
Service Account
Query Parameters
When set to 1 (recommended), Mixpanel will validate the batch and return errors per event that failed.
Available options:
0, 1 The Mixpanel project_id, used to authenticate service account credentials (do not provide if using secret auth).
Body
application/json
Was this page helpful?
⌘I
Merge Identities
curl --request POST \
--url https://{region}.mixpanel.com/import \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
[
{
"event": "$merge",
"properties": {
"$distinct_ids": [
"<string>"
]
}
}
]
'import requests
url = "https://{region}.mixpanel.com/import"
payload = [
{
"event": "$merge",
"properties": { "$distinct_ids": ["<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([{event: '$merge', properties: {$distinct_ids: ['<string>']}}])
};
fetch('https://{region}.mixpanel.com/import', 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://{region}.mixpanel.com/import",
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([
[
'event' => '$merge',
'properties' => [
'$distinct_ids' => [
'<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://{region}.mixpanel.com/import"
payload := strings.NewReader("[\n {\n \"event\": \"$merge\",\n \"properties\": {\n \"$distinct_ids\": [\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://{region}.mixpanel.com/import")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("[\n {\n \"event\": \"$merge\",\n \"properties\": {\n \"$distinct_ids\": [\n \"<string>\"\n ]\n }\n }\n]")
.asString();require 'uri'
require 'net/http'
url = URI("https://{region}.mixpanel.com/import")
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 {\n \"event\": \"$merge\",\n \"properties\": {\n \"$distinct_ids\": [\n \"<string>\"\n ]\n }\n }\n]"
response = http.request(request)
puts response.read_body{
"code": 200,
"num_records_imported": 2000,
"status": "OK"
}{
"code": 400,
"num_records_imported": 999,
"status": "Bad Request",
"failed_records": [
{
"index": 0,
"insert_id": "13c0b661-f48b-51cd-ba54-97c5999169c0",
"field": "properties.time",
"message": "'properties.time' is invalid: must be specified as seconds since epoch"
}
]
}{
"code": 401,
"error": "Invalid service account credentials",
"status": "Unauthorized"
}