Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.
This repository was archived by the owner on Jan 2, 2024. It is now read-only.

Issues encountered doing a migration #16

Description

@nick-lironi-irvine

I've just completed a migration of dev/test/prod environments to new projects to take advantage of simplified Id merge.
This tool was really helpful in giving us the confidence to attempt to do so and the project was successful over all but I did encounter a range of problems during this migration and I'll note them here for your info

Failure to migrate events

I encountered 2 issues with migrating events

  1. Failure to authenticate when using a service account; the export API hardcoded the secret based auth and was missing the project Id query param
  2. Failure to call the EU data export API; the EU/US region switch does not correctly account for the change from data.mixpanel.com to data-eu.mixpanel.com

Failure to migrate dashboards using template

I'm afraid I no longer have the log to share, but trying to migrate a Dashboard with "template_type": "Marketing KPI", failed; we instead used the UI to move it between the projects

I was unable to use the npx based approach because of these issues and instead cloned the project and applied some local patches; see below

diff --git a/endpoints.js b/endpoints.js
index 6884e72..34a9b09 100644
--- a/endpoints.js
+++ b/endpoints.js
@@ -105,8 +105,8 @@ exports.getInsightsReport = function (projectId, region = `US`) {
 	return `https://${getRegion(region)}mixpanel.com/api/2.0/insights?project_id=${projectId}`;
 };
 
-exports.dataExport = function (start, end, region = `US`) {
-	return `https://data.${region?.toLowerCase() === 'eu' ? "eu." : ""}mixpanel.com/api/2.0/export?from_date=${start}&to_date=${end}`;
+exports.dataExport = function (start, end, region = `US`, projectId) {
+	return `https://${region?.toLowerCase() === 'eu' ? "data-eu" : "data"}.mixpanel.com/api/2.0/export?project_id=${projectId}&from_date=${start}&to_date=${end}`;
 };
 
 exports.profileExport = function (projectId, region = `US`) {
diff --git a/utils.js b/utils.js
index 3a2eb30..cd02758 100644
--- a/utils.js
+++ b/utils.js
@@ -726,19 +726,17 @@ DATA EXPORT
 exports.exportAllEvents = async function (source) {
 	const startDate = dayjs(source.start).format(dateFormat);
 	const endDate = dayjs(source.end).format(dateFormat);
-	const url = URLs.dataExport(startDate, endDate, source?.region);
+	const url = URLs.dataExport(startDate, endDate, source?.region, source.project);
 	const file = path.resolve(`${source.localPath}/exports/events.ndjson`);
 	const writer = createWriteStream(file);
-	const auth = Buffer.from(source.secret + '::').toString('base64');
 	const response = await fetch({
 		method: 'GET',
 		url,
 		headers: {
-			Authorization: `Basic ${auth}`
+			Authorization: `${source.auth}`
 		},
 		responseType: 'stream'
 	});
-
 	response.data.pipe(writer);
 
 	//why can't i pass the fileName to resolve()
@@ -750,16 +748,15 @@ exports.exportAllEvents = async function (source) {
 };
 
 exports.exportAllProfiles = async function (source, target) {
-	const auth = Buffer.from(source.secret + '::').toString('base64');
 	let iterations = 0;
 	let fileName = `people-${iterations}.json`;
 	let folder = path.resolve(`${source.localPath}/exports/profiles/`);
 	let file = path.resolve(`${folder}/${fileName}`);
 	let response = (await fetch({
 		method: 'POST',
-		url: URLs.profileExport(source.projId, source?.region),
+		url: URLs.profileExport(source.project, source?.region),
 		headers: {
-			Authorization: `Basic ${auth}`
+			Authorization: `${source.auth}`
 		},
 	})).data;
 
@@ -796,7 +793,7 @@ exports.exportAllProfiles = async function (source, target) {
 
 		response = (await fetch({
 			method: 'POST',
-			url: URLs.profileExport(source.projId, source?.region),
+			url: URLs.profileExport(source.project, source?.region),
 			headers: {
 				Authorization: `Basic ${auth}`
 			},
@@ -1395,8 +1392,8 @@ const matchCustomEntities = async function (sourceCreds, sourceEntities, targetE
 	let sourceCohortList = [];
 
 	if (sourceCreds) {
-		const { projId, workspace, auth, region } = sourceCreds;
-		sourceCohortList = (await fetch(URLs.listCohorts(projId, workspace, region), {
+		const { project, workspace, auth, region } = sourceCreds;
+		sourceCohortList = (await fetch(URLs.listCohorts(project, workspace, region), {
 			method: `POST`,
 			headers: {
 				Authorization: auth

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions