HubSpot enforces uniqueness constraints on certain properties. Attempting to create a duplicate record will result in a VALIDATION_ERROR that stops the sync process.
The script prevents duplicates by checking:
Event ID: Whether a deal already exists with the same evento_marketing_id
Deal Name: Whether a deal already exists with the same dealname
Both checks are performed sequentially in the main processing loop before creating any records.
events.js
for (const e of todayEvents) { try { const alreadyExistsById = await eventExists(e.id); if (alreadyExistsById) { skippedEvents.push({ name: e.eventName, reason: "exists_by_id" }); console.log(`⏭️ Evento ya existe por ID: ${e.eventName}`); continue; } // Evitar crear si ya existe un registro con el mismo nombre (previene VALIDATION_ERROR) const nameExists = await recordExistsByName(e.eventName); if (nameExists) { skippedEvents.push({ name: e.eventName, reason: "exists_by_name" }); console.log(`⏭️ Evento ya existe por nombre: ${e.eventName}`); continue; } const created = await createCustomRecord(e); createdEvents.push(created); console.log(`✅ Evento creado: ${created.dealname}`); } catch (eventErr) { failedEvents.push({ name: e.eventName, error: eventErr.message, }); console.error( `❌ Error creando evento "${e.eventName}":`, eventErr.message ); }}
Each duplicate check requires an API call to HubSpot’s search endpoint. For large batches of events, this can add latency. However, this is necessary to prevent validation errors.