From 81cd0fb355f005a965e2b2195a926393a33557c6 Mon Sep 17 00:00:00 2001 From: Vladimir Klimontovich Date: Wed, 13 Dec 2023 15:31:20 -0500 Subject: [PATCH] fix: intercom export fix --- .../api/marketing-automation/intercom/export.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/webapps/ee-api/pages/api/marketing-automation/intercom/export.ts b/webapps/ee-api/pages/api/marketing-automation/intercom/export.ts index 5046b8d06..9cce94bea 100644 --- a/webapps/ee-api/pages/api/marketing-automation/intercom/export.ts +++ b/webapps/ee-api/pages/api/marketing-automation/intercom/export.ts @@ -54,25 +54,26 @@ const handler = async function handler(req: NextApiRequest, res: NextApiResponse } else if (searchResult.data.length > 1) { getLog().atInfo().log(`Contact ${email} has ${searchResult.data.length} in Intercom, taking the first one`); } - const userId = searchResult.data.map(d => d.external_id).find(id => id !== undefined); - if (!userId) { - getLog() - .atInfo() - .log(`Non of ${searchResult.data.length} contacts attached to ${email} doesn't have external_id`); + const intercomUserId = searchResult.data.map(d => d.id).find(id => id !== undefined); + if (!intercomUserId) { + getLog().atInfo().log(`Non of ${searchResult.data.length} contacts attached to ${email} doesn't have id`); invalidEvents++; continue; } await client.events.create({ eventName: eventName as string, createdAt: Math.round((timestamp as Date).getTime() / 1000), - userId: userId, - id: messageId as string, + id: intercomUserId, }); sentEvents.eventIds.push(messageId); await sentEventsTable.put(email as string, sentEvents); } } - return { ok: true, alreadySent, newEvents, invalidEvents }; + const apiResponse = { ok: true, alreadySent, newEvents, invalidEvents }; + getLog() + .atInfo() + .log(`Result: ${JSON.stringify(apiResponse, null, 2)}`); + return apiResponse; }; export default withErrorHandler(handler);