/// <summary>
        /// Relate this email result (presumed to represent me) in CRM to these related records.
        /// </summary>
        /// <param name="relatedRecords">The records which should be related to my email result.</param>
        /// <param name="emailResult">An email result (presumed to represent me).</param>
        private void LinkRelatedRecords(IEnumerable <CrmEntity> relatedRecords, RESTObjects.SetEntryResult emailResult)
        {
            var restServer = SuiteCRMUserSession.RestServer;

            foreach (CrmEntity record in relatedRecords)
            {
                try
                {
                    var success = RestAPIWrapper.TrySetRelationship(
                        new SetRelationshipParams
                    {
                        module2    = "emails",
                        module2_id = emailResult.id,
                        module1    = ModuleToTableResolver.GetTableName(record.ModuleName),
                        module1_id = record.EntityId,
                    }, Objective.Email);

                    if (success)
                    {
                        log.Debug($"Successfully bound {record.ModuleName} '{record.EntityId}' to email '{emailResult.id}' in CRM");
                    }
                    else
                    {
                        log.Warn($"Failed to bind {record.ModuleName} '{record.EntityId}' to email '{emailResult.id}' in CRM");
                    }
                }
                catch (Exception any)
                {
                    log.Error($"Failed to bind {record.ModuleName} '{record.EntityId}' to email '{emailResult.id}' in CRM", any);
                }
            }
        }
        private object ConstructGetContactIdByAddressPacket(string address, string moduleKey)
        {
            string tableName = ModuleToTableResolver.GetTableName(moduleKey);

            return(new
            {
                session = SuiteCRMUserSession.id,
                module_name = tableName,
                query = GetContactIDQuery(address, tableName),
                order_by = "",
                offset = 0,
                select_fields = new string[] { "id" },
                max_results = 1,
                deleted = false,
                favorites = false
            });
        }