C# SDK Samples - Module Operations
Meta Data
Get List of Module Fields
/** get list of module Fields */
public void GetAllModuleFields()
{
/** Fields */
ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //module api name
BulkAPIResponse<ZCRMField> response = moduleIns.GetAllFields();
Console.WriteLine(response.HttpStatusCode);
List<ZCRMField> fields = response.BulkData; //fields - list of ZCRMField instance
foreach (ZCRMField field in fields)
{
Console.WriteLine(field.DisplayName);
Console.WriteLine(field.DataType);
Console.WriteLine(field.Id);
Console.WriteLine(field.ApiName);
Console.WriteLine(field.CreatedSource);
Console.WriteLine(field.FormulaReturnType);
Console.WriteLine(field.JsonType);
Console.WriteLine(field.ToolTip);
Console.WriteLine(field.CustomField);
Console.WriteLine(field.DefaultValue);
Dictionary<string, object> LookupDetails = field.LookupDetails;
foreach(KeyValuePair<string, object> LookupDetail in LookupDetails)
{
Console.WriteLine(LookupDetail.Key +":"+ LookupDetail.Value);
}
Console.WriteLine(field.Mandatory );
Console.WriteLine(field.MaxLength );
Dictionary<string, object> MultiselectLookup = field.MultiselectLookup;
foreach (KeyValuePair<string, object> Lookup in MultiselectLookup)
{
Console.WriteLine(Lookup.Key + ":" + Lookup.Value );
}
List<ZCRMPickListValue> pickListValues = field.PickListValues;
foreach (ZCRMPickListValue pickListValue in pickListValues)
{
Console.WriteLine(pickListValue.ActualName);
Console.WriteLine(pickListValue.DisplayName);
}
Console.WriteLine(field.Precision );
Console.WriteLine(field.ReadOnly );
Console.WriteLine(field.SequenceNo );
Dictionary<string, object> SubformDetails = field.SubformDetails;
foreach (KeyValuePair<string, object> SubformDetail in SubformDetails)
{
Console.WriteLine(SubformDetail.Key + ":" + SubformDetail.Value );
}
Console.WriteLine(field.SubFormTabId );
Console.WriteLine(field.Visible );
Console.WriteLine(field.Webhook );
}
}
/** get list of module Related Lists */
public void GetAllModuleRelatedLists()
{
/** Related Lists */
ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //module api name
BulkAPIResponse<ZCRMModuleRelation> response = moduleIns.GetRelatedLists();
Console.WriteLine(response.HttpStatusCode);
List<ZCRMModuleRelation> relatedLists = response.BulkData; //relatedLists - list of ZCRMModuleRelation instance
foreach (ZCRMModuleRelation relation in relatedLists)
{
Console.WriteLine(relation.ApiName);
Console.WriteLine(relation.Id);
Console.WriteLine(relation.Label);
Console.WriteLine(relation.Module);
Console.WriteLine(relation.Name);
Console.WriteLine(relation.ParentModuleAPIName);
Console.WriteLine(relation.Type);
Console.WriteLine(relation.Visible);
}
}
Get List of Layouts of a Module
/** get list of module Layouts*/
public void GetAllModuleLayouts()
{
/** Layouts */
ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //module api name
BulkAPIResponse<ZCRMLayout> response = moduleIns.GetAllLayouts();
Console.WriteLine(response.HttpStatusCode);
List<ZCRMLayout> layouts = response.BulkData; //layouts - list of ZCRMLayout instance
foreach (ZCRMLayout layout in layouts)
{
Console.WriteLine(layout.Name);
Console.WriteLine(layout.Id);
Console.WriteLine(layout.CreatedTime);
Console.WriteLine(layout.ModifiedTime);
Console.WriteLine(layout.Status);
Console.WriteLine(layout.Visible);
List<ZCRMProfile> profiles = layout.AccessibleProfies;
foreach (ZCRMProfile profile in profiles)
{
Console.WriteLine(profile.Id);
Console.WriteLine(profile.Name);
Console.WriteLine(profile.IsDefault);
}
ZCRMUser CreatedBy = layout.CreatedBy;
if (CreatedBy != null)
{
Console.WriteLine(CreatedBy.Id);
Console.WriteLine(CreatedBy.FullName);
}
ZCRMUser ModifiedBy = layout.ModifiedBy;
if (ModifiedBy != null)
{
Console.WriteLine(ModifiedBy.Id);
Console.WriteLine(ModifiedBy.FullName);
}
List<ZCRMSection> sections = layout.Sections;
foreach (ZCRMSection section in sections)
{
Console.WriteLine(section.Name);
Console.WriteLine(section.DisplayName);
Console.WriteLine(section.ColumnCount);
Console.WriteLine(section.Sequence);
Console.WriteLine(section.IsSubformSection);
Console.WriteLine(section.ApiName);
Console.WriteLine(section.TabTraversal);
List<ZCRMField> fields = section.Fields;
foreach (ZCRMField field in fields)
{
Console.WriteLine(field.ApiName);
Console.WriteLine(field.Id);
}
if(section.Properties != null)
{
Console.WriteLine(JsonConvert.SerializeObject(section.Properties));
}
}
if(layout.ConvertMapping != null && layout.ConvertMapping.Count>0)
{
foreach(KeyValuePair<string,ZCRMLeadConvertMapping> convertMappingdict in layout.ConvertMapping)
{
Console.WriteLine(convertMappingdict.Key);
ZCRMLeadConvertMapping convertMappingData = convertMappingdict.Value;
Console.WriteLine(convertMappingData.Name);
Console.WriteLine(convertMappingData.Id);
if(convertMappingData.Fields != null && convertMappingData.Fields.Count>0)
{
List<ZCRMLeadConvertMappingField> fields = convertMappingData.Fields;
foreach (ZCRMLeadConvertMappingField field in fields)
{
Console.WriteLine(field.ApiName);
Console.WriteLine(field.FieldLabel);
Console.WriteLine(field.Id);
Console.WriteLine(field.Required);
}
}
}
}
}
}
Get List of Custom Views of a Module
/** get list of module CustomViews */
public void GetAllModuleCustomViews()
{
/** Custom Views */
ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //module api name
BulkAPIResponse<ZCRMCustomView> response = moduleIns.GetAllCustomViews();
Console.WriteLine(response.HttpStatusCode);
List<ZCRMCustomView> customViews = response.BulkData; //customViews - list of ZCRMCustomView instance
foreach (ZCRMCustomView customView in customViews)
{
Console.WriteLine(customView.DisplayName);
Console.WriteLine(customView.IsOffline);
Console.WriteLine(customView.Isdefault);
Console.WriteLine(customView.SystemName);
Console.WriteLine(customView.IsSystemDefined);
Console.WriteLine(customView.Name);
Console.WriteLine(customView.Id);
Console.WriteLine(customView.Category);
Console.WriteLine(customView.Favourite);
if (customView.CategoriesList != null && customView.CategoriesList.Count > 0)
{
foreach (ZCRMCustomViewCategory categoryList in customView.CategoriesList)
{
Console.WriteLine(categoryList.ActualValue);
Console.WriteLine(categoryList.DisplayValue);
}
}
}
}
Get a Layout of a Module
/** get single module layout */
public void GetLayout()
{
/** Single Layout */
ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //module api name
APIResponse response = moduleIns.GetLayoutDetails(53851800000); // 53851800000 layout id
Console.WriteLine(response.HttpStatusCode);
ZCRMLayout layout = (ZCRMLayout)response.Data;
Console.WriteLine(layout.Name);
Console.WriteLine(layout.Id);
Console.WriteLine(layout.CreatedTime);
Console.WriteLine(layout.ModifiedTime);
Console.WriteLine(layout.Status);
Console.WriteLine(layout.Visible);
List<ZCRMProfile> profiles = layout.AccessibleProfies;
foreach (ZCRMProfile profile in profiles)
{
Console.WriteLine(profile.Id);
Console.WriteLine(profile.Name);
Console.WriteLine(profile.IsDefault);
}
ZCRMUser CreatedBy = layout.CreatedBy;
if (CreatedBy != null)
{
Console.WriteLine(CreatedBy.Id);
Console.WriteLine(CreatedBy.FullName);
}
ZCRMUser ModifiedBy = layout.ModifiedBy;
if (ModifiedBy != null)
{
Console.WriteLine(ModifiedBy.Id);
Console.WriteLine(ModifiedBy.FullName);
}
List<ZCRMSection> sections = layout.Sections;
foreach (ZCRMSection section in sections)
{
Console.WriteLine(section.Name);
Console.WriteLine(section.DisplayName);
Console.WriteLine(section.ColumnCount);
Console.WriteLine(section.Sequence);
Console.WriteLine(section.IsSubformSection);
Console.WriteLine(section.ApiName);
Console.WriteLine(section.TabTraversal);
List<ZCRMField> fields = section.Fields;
foreach (ZCRMField field in fields)
{
Console.WriteLine(field.ApiName);
Console.WriteLine(field.Id);
}
if (section.Properties != null)
{
Console.WriteLine(JsonConvert.SerializeObject(section.Properties));
}
}
if (layout.ConvertMapping != null && layout.ConvertMapping.Count > 0)
{
foreach (KeyValuePair<string, ZCRMLeadConvertMapping> convertMappingdict in layout.ConvertMapping)
{
Console.WriteLine(convertMappingdict.Key);
ZCRMLeadConvertMapping convertMappingData = convertMappingdict.Value;
Console.WriteLine(convertMappingData.Name);
Console.WriteLine(convertMappingData.Id);
if (convertMappingData.Fields != null && convertMappingData.Fields.Count > 0)
{
List<ZCRMLeadConvertMappingField> fields = convertMappingData.Fields;
foreach (ZCRMLeadConvertMappingField field in fields)
{
Console.WriteLine(field.ApiName);
Console.WriteLine(field.FieldLabel);
Console.WriteLine(field.Id);
Console.WriteLine(field.Required);
}
}
}
}
}
Get a Custom View of a Module
/** get single module Custom View */
public void GetCustomView()
{
/** Single Custom View */
ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //module api name
APIResponse response = moduleIns.GetCustomView(538518000000); //538518000000 is customView id
Console.WriteLine(response.HttpStatusCode);
ZCRMCustomView customView = (ZCRMCustomView)response.Data;
Console.WriteLine(customView.DisplayName);
Console.WriteLine(customView.SharedType);
Console.WriteLine(customView.CriteriaPattern);
Console.WriteLine(customView.CriteriaCondition);
if(customView.Criteria != null)
{
ZCRMCriteria criteria = customView.Criteria;
Console.WriteLine(criteria.Comparator);
Console.WriteLine(criteria.GroupOperator);
Console.WriteLine(criteria.Field);
Console.WriteLine(criteria.Value);
Console.WriteLine(criteria.Index);
Console.WriteLine(criteria.Pattern);
Console.WriteLine(criteria.Criteria);
if (criteria.Group != null && criteria.Group.Count>0)
{
foreach(ZCRMCriteria group in criteria.Group)
{
Console.WriteLine(group.Comparator);
Console.WriteLine(group.GroupOperator);
Console.WriteLine(group.Field);
Console.WriteLine(group.Value);
Console.WriteLine(JsonConvert.SerializeObject(group.Group));
}
}
}
Console.WriteLine(customView.SystemName);
Console.WriteLine(customView.SharedDetails);
Console.WriteLine(customView.SortBy);
Console.WriteLine(customView.IsOffline);
Console.WriteLine(customView.Isdefault);
Console.WriteLine(customView.IsSystemDefined);
Console.WriteLine(customView.Name);
Console.WriteLine(customView.Id);
Console.WriteLine(customView.Category);
if (customView.Fields.Count > 0)
{
foreach (string field in customView.Fields)
{
Console.WriteLine(field);
}
}
Console.WriteLine(customView.Favourite);
Console.WriteLine(customView.SortOrder);
if(customView.CategoriesList != null && customView.CategoriesList.Count>0)
{
foreach(ZCRMCustomViewCategory categoryList in customView.CategoriesList)
{
Console.WriteLine(categoryList.ActualValue);
Console.WriteLine(categoryList.DisplayValue);
}
}
}
Records
Get List of Records
/** Get list of records */
public void GetALLRecords()
{
Console.Clear();
try
{
ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //To get module instance
List<string> fields = new List<string>() { "Last_Name", "Company" };
BulkAPIResponse<ZCRMRecord> response = moduleIns.GetRecords(); //To get module records
//BulkAPIResponse<ZCRMRecord> response = moduleIns.GetRecords(538518000000091501); //Custom view Id of the module.
//BulkAPIResponse<ZCRMRecord> response = moduleIns.GetRecords(fields); //List of field API names
//BulkAPIResponse<ZCRMRecord> response = moduleIns.GetRecords(538518000000091501, fields); //Custom view Id with List of field API names.
//BulkAPIResponse<ZCRMRecord> response = moduleIns.GetRecords(538518000000091501,1,10, fields); //Custom view Id, page, perPage and List of field API names.
//BulkAPIResponse<ZCRMRecord> response = moduleIns.GetRecords(538518000000091501, "Last_Name", CommonUtil.SortOrder.asc,fields); //Custom view Id, sortByField, sortOrder and List of field API names.
//BulkAPIResponse<ZCRMRecord> response = moduleIns.GetRecords(538518000000091501, "Last_Name", CommonUtil.SortOrder.asc,1,10, fields); //Custom view Id, sortByField, sortOrder, page, perPage and List of field API names.
//BulkAPIResponse<ZCRMRecord> response = moduleIns.GetRecords(538518000000091501, "Last_Name", CommonUtil.SortOrder.asc,1,10, "2019-12-25T04:00:00+02:00", fields); //Custom view Id, sortByField, sortOrder, page, perPage, modifiedSince(Header) and List of field API names.
List<ZCRMRecord> records = response.BulkData; //To get response List of ZCRMRecord.
foreach (ZCRMRecord record in records)
{
Console.WriteLine(record.EntityId); //To get record id
Console.WriteLine(record.ModuleAPIName); //To get module api name
Console.WriteLine(record.LookupLabel); //To get lookup object name
ZCRMUser createdBy = record.CreatedBy;
Console.WriteLine(createdBy.Id); //To get UserId who created the record
Console.WriteLine(createdBy.FullName); //To get User name who created the record
ZCRMUser modifiedBy = record.ModifiedBy;
Console.WriteLine(modifiedBy.Id); //To get UserId who modified the record
Console.WriteLine(modifiedBy.FullName); //To get User name who modified the record
ZCRMUser owner = record.Owner;
Console.WriteLine(owner.Id); //To get record OwnerId
Console.WriteLine(owner.FullName);//To get record Owner name
Console.WriteLine(record.CreatedTime); //To get record created time
Console.WriteLine(record.ModifiedTime); //To get record modified time
//Console.WriteLine(record.GetFieldValue("Last_Name")); //To get particular field value
if (record.Tags.Count > 0)
{
foreach (ZCRMTag tagnames in record.Tags)
{
Console.WriteLine(tagnames.Id);
Console.WriteLine(tagnames.Name);
}
Console.WriteLine("\n\n");
}
Dictionary<string, object> recordData = record.Data; //Returns record as Dictionary
//Console.WriteLine(record.PriceDetails);
foreach (KeyValuePair<string, object> data in record.Data)
{
if (data.Value is ZCRMRecord recordValue) //If data.Value is ZCRMRecord instance
{
Console.WriteLine(recordValue.EntityId); //To get record id
Console.WriteLine(recordValue.ModuleAPIName); //To get module api name
Console.WriteLine(recordValue.LookupLabel); //To get lookup object name
}
else if (data.Value is List<ZCRMFiles>)
{
foreach (ZCRMFiles files in (List <ZCRMFile>)data.Value)
{
Console.WriteLine(files.FileId);
Console.WriteLine(files.FileName);
Console.WriteLine(files.AttachmentId);
Console.WriteLine(files.EntityId);
}
Console.WriteLine("\n\n");
}
else if(data.Value is List<string>)
{
Console.WriteLine(data.Key);
foreach (string tag in (List<string>)data.Value)
{
Console.WriteLine(tag);
}
Console.WriteLine("\n\n");
}
else //data.Value is not ZCRMRecord instance
{
Console.WriteLine(data.Key + "\t" + data.Value);
}
}
Console.WriteLine("\n\n");
/** Fields which start with "$" are considered to be property fields */
//Console.WriteLine(record.GetProperty("$fieldName")); //To get a particular property value
Dictionary<string, object> properties = record.Properties; //To get record properties as Dictionary
foreach (KeyValuePair<string, object> property in properties)
{
if (property.Value is List<string>) //If value is an array
{
Console.WriteLine("\n\n" + property.Key);
foreach (string data in (List<string>)property.Value)
{
Console.WriteLine(data + "\t");
}
}
else if (property.Value is Dictionary<string, object>)
{
Console.WriteLine("\n\n" + property.Key);
foreach (KeyValuePair<string, object> data in (Dictionary<string, object>)property.Value)
{
if (property.Value is Dictionary<string, object>)
{
foreach (KeyValuePair<string, object> data1 in (Dictionary<string, object>)data.Value)
{
Console.WriteLine(data1.Key + "\t" + data1.Value);
}
}
else
{
Console.WriteLine(data.Key + "\t" + data.Value);
}
}
}
else
{
Console.WriteLine(property.Key + "\t" + property.Value);
}
}
BulkAPIResponse<ZCRMRecord> relatedlist = record.GetRelatedListRecords("Products"); //To get Related records of a record
/** Related records is of type ZCRMRecord **/
List<ZCRMRecord> lists = relatedlist.BulkData; //To get related list data
foreach (ZCRMRecord rec in lists)
{
Console.WriteLine(rec.EntityId); //To get record id
Console.WriteLine(rec.ModuleAPIName); //To get module api name
}
BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes(); //To get record notes
//BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes(1,10); //page, perPage.
//BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes("title", CommonUtil.SortOrder.asc); //sortByField, sortOrder
//BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes("title", CommonUtil.SortOrder.asc,1,10, "2019-12-25T04:00:00+02:00"); //sortByField, sortOrder, page, perPage and modifiedSince(Header)
List<ZCRMNote> notes = noteResponse.BulkData;
foreach (ZCRMNote note in notes)
{
Console.WriteLine(note.Id); //To get note id
Console.WriteLine(note.Title); //To get note title
Console.WriteLine(note.Content); //To get note content
ZCRMRecord parentRecord = note.ParentRecord; //To get note's parent record
Console.WriteLine(parentRecord.EntityId); //To get note's parent record id
Console.WriteLine(parentRecord.ModuleAPIName); // To get note's parent record Module API name
ZCRMUser noteCreatedBy = note.CreatedBy;
Console.WriteLine(noteCreatedBy.Id); //To get UserId who created the notes
Console.WriteLine(noteCreatedBy.FullName); //To get User name who created the notes
ZCRMUser noteModifiedBy = note.ModifiedBy;
Console.WriteLine(noteModifiedBy.Id); //To get UserId who modified the notes
Console.WriteLine(noteModifiedBy.FullName); //To get User name who modified the notes
ZCRMUser noteOwner = note.NotesOwner;
Console.WriteLine(noteOwner.Id); //To get notes OwnerId
Console.WriteLine(noteOwner.FullName); //To get notes Owner name
Console.WriteLine(note.CreatedTime); //To get created time of the note
Console.WriteLine(note.ModifiedTime); //To get modified time of the note
List<ZCRMAttachment> noteAttachment = note.Attachments; //To get attachments of the note record
if (noteAttachment != null) //check If attachments is empty/not
{
foreach (ZCRMAttachment attachment in noteAttachment)
{
Console.WriteLine(attachment.Id); //To get the note's attachment id
Console.WriteLine(attachment.FileName); //To get the note's attachment file name
Console.WriteLine(attachment.FileType); //To get the note's attachment file type
Console.WriteLine(attachment.Size); //To get the note's attachment file size
ZCRMRecord attachmentRecord = attachment.ParentRecord;
Console.WriteLine(attachmentRecord.EntityId); //To get the note's parent record id
Console.WriteLine(attachmentRecord.ModuleAPIName); //To get the record name
ZCRMUser noteAttachmentCreatedBy = note.CreatedBy;
Console.WriteLine(noteAttachmentCreatedBy.Id); // To get user_id who created the note's attachment
Console.WriteLine(noteAttachmentCreatedBy.FullName); //To get user name who created the note's attachment
ZCRMUser noteAttachmentModifiedBy = note.ModifiedBy;
Console.WriteLine(noteAttachmentModifiedBy.Id); //To get user_id who modified the note's attachment
Console.WriteLine(noteAttachmentModifiedBy.FullName); //To get user name who modified the note's attachment
ZCRMUser noteAttachmentOwner = note.NotesOwner;
Console.WriteLine(noteAttachmentOwner.Id); //To get the note's attachment owner id
Console.WriteLine(noteAttachmentOwner.FullName); //To get the note's attachment owner name
Console.WriteLine(attachment.CreatedTime); //To get attachment created time
Console.WriteLine(attachment.ModifiedTime); //To get attachment modified time
}
}
}
BulkAPIResponse<ZCRMAttachment> attachmentResponse = record.GetAttachments(); //To get record's attachments
//BulkAPIResponse<ZCRMAttachment> attachmentResponse = record.GetAttachments(0,10, "019-12-25T04:00:00+02:00"); //page, perPage and modifiedSince(Header)
List<ZCRMAttachment> attachments = attachmentResponse.BulkData; // To get list of attachments
foreach (ZCRMAttachment attachment in attachments)
{
Console.WriteLine(attachment.Id); //To get the attachment id
Console.WriteLine(attachment.FileName); //To get attachment file name
Console.WriteLine(attachment.FileType); // To get attachment file type
Console.WriteLine(attachment.Size); //To get attachment file size
ZCRMRecord attachmentRecord = attachment.ParentRecord;
Console.WriteLine(attachmentRecord.EntityId); //To get the parent record id
Console.WriteLine(attachmentRecord.ModuleAPIName); //To get the parent record name
ZCRMUser attachmentCreatedBy = attachment.CreatedBy;
Console.WriteLine(attachmentCreatedBy.Id); // To get user_id who created the attachment
Console.WriteLine(attachmentCreatedBy.FullName); //To get user name who created the attachment
ZCRMUser attachmentModifiedBy = attachment.ModifiedBy;
Console.WriteLine(attachmentModifiedBy.Id); //To get user_id who modified the attachment
Console.WriteLine(attachmentModifiedBy.FullName); //To get user name who modified the attachment
ZCRMUser noteAttachmentOwner = attachment.Owner;
Console.WriteLine(noteAttachmentOwner.Id); //To get the attachment owner id
Console.WriteLine(noteAttachmentOwner.FullName); //To get the attachment owner name
Console.WriteLine(attachment.CreatedTime); //To get attachment created time
Console.WriteLine(attachment.ModifiedTime); //To get attachment modified time
//FileAPIResponse fResponse = attachment.DownloadFile(); //To download the attachment file
//Console.WriteLine("File Name:" + fResponse.GetFileName()); // To get attachment file name
//Console.WriteLine("HTTP Status Code:" + fResponse.HttpStatusCode); //To get HTTP status code
//Stream file = fResponse.GetFileAsStream(); //To get attachment file content
//CommonUtil.SaveStreamAsFile("/Users/Desktop/photo", file, fResponse.GetFileName()); //To write a new file using the same attachment name
}
ZCRMLayout layout = record.Layout; //To get record layout
if(layout != null)
{
Console.WriteLine(layout.Id); //To get layout_id
Console.WriteLine(layout.Name); //To get layout name
}
/** Following methods are being used only by Inventory modules */
List<ZCRMTax> taxlists = record.TaxList; //To get the tax list
foreach (ZCRMTax tax in taxlists)
{
Console.WriteLine(tax.TaxName); //To get tax name
Console.WriteLine(tax.Percentage); //To get tax percentage
Console.WriteLine(tax.Value); //To get tax value
}
List<ZCRMInventoryLineItem> lineItems = record.LineItems; //To get list of line_items
foreach (ZCRMInventoryLineItem lineItem in lineItems)
{
Console.WriteLine(lineItem.Id); //To get lineItem id
Console.WriteLine(lineItem.ListPrice); //To get lineItem list price
Console.WriteLine(lineItem.Quantity); //To get lineItem quantity
Console.WriteLine(lineItem.Description); //To get lineItem description
Console.WriteLine(lineItem.Total); //To get lineItem total amount
Console.WriteLine(lineItem.Discount); //To get lineItem discount
Console.WriteLine(lineItem.DiscountPercentage); //To get lineItem discount percentage
Console.WriteLine(lineItem.TotalAfterDiscount); //To get lineItem amount after discount
Console.WriteLine(lineItem.TaxAmount); //To get lineItem tax amount
Console.WriteLine(lineItem.NetTotal); //To get lineItem net total amount
Console.WriteLine(lineItem.UnitPrice); //To get lineItem unit price
Console.WriteLine(lineItem.Product.EntityId); //To get line_item product's entity id
Console.WriteLine(lineItem.Product.LookupLabel); //To get line_item product's lookup label
List<ZCRMTax> linetaxs = lineItem.LineTax; //To get list of line_tax in lineItem
foreach (ZCRMTax tax in linetaxs)
{
Console.WriteLine(tax.TaxName); //To get line tax name
Console.WriteLine(tax.Percentage); //To get line tax percentage
Console.WriteLine(tax.Value); //To get line tax value
}
}
List<ZCRMPriceBookPricing> pricedetails = record.PriceDetails; //To get the price details array
foreach (ZCRMPriceBookPricing pricedetail in pricedetails)
{
Console.WriteLine(pricedetail.Id); //To get the record's priceId
Console.WriteLine(pricedetail.ToRange); //To get the price detail record's to_range
Console.WriteLine(pricedetail.FromRange); //To get the price detail record's from_range
Console.WriteLine(pricedetail.Discount); //To get the price detail record's discount
}
/** End Inventory **/
/** Following method is used only by 'Events' module */
List<ZCRMEventParticipant> participants = record.Participants; //To get Event record's participants
foreach (ZCRMEventParticipant participant in participants)
{
Console.WriteLine(participant.Id); //To get the record's participant id
Console.WriteLine(participant.Name); //To get the record's participant name
Console.WriteLine(participant.Email);//To get the record's participant email
Console.WriteLine(participant.Type); //To get the record's participant type
Console.WriteLine(participant.IsInvited); //To check if the record's participant(s) are invited or not
Console.WriteLine(participant.Status); //To get the record's participants' status
}
/* End Event */
}
//Console.WriteLine("Headers"+response.GetResponseHeaders());
BulkAPIResponse<ZCRMRecord>.ResponseInfo info = response.Info;
Console.WriteLine(info.AllowedCount);
Console.WriteLine(info.MoreRecords);
Console.WriteLine(info.PageNo);
Console.WriteLine(info.PerPage);
Console.WriteLine(info.RecordCount);
Console.WriteLine("RemainingAPICountForThisDay " + response.GetResponseHeaders().AllowedAPICallsPerMinute);
Console.WriteLine("RemainingAPICountForThisWindow " + response.GetResponseHeaders().RemainingAPICountForThisWindow);
Console.WriteLine("RemainingTimeForThisWindowReset " + response.GetResponseHeaders().RemainingTimeForThisWindowReset);
}
catch (ZCRMException ex)
{
Console.WriteLine(ex.Message); //To get ZCRMException error message
Console.WriteLine(ex.Source); //To get ZCRMException error source
Console.WriteLine(ex.StackTrace);//To get ZCRMException stack trace
}
}
Insert Records
/** Insert records */
public void CreateRecords()
{
List<ZCRMRecord> listRecord = new List<ZCRMRecord>();
ZCRMRecord record;
record = ZCRMRecord.GetInstance("Invoices", null); //To get ZCRMRecord instance
record.SetFieldValue("Subject", "Invoice4"); //This method use to set FieldApiName and value similar to all other FieldApis and Custom field
record.SetFieldValue("Account_Name", 3372164000001855101);
record.SetFieldValue("Company", "KK");
record.SetFieldValue("Last_Name", "User");
record.SetFieldValue("Customfield", "CustomFieldValue");
record.SetFieldValue("Price_Book_Name", "Price_Book_Name");
//Following methods are used to upload a file to a field
List<ZCRMFiles> fileObjects = new List<ZCRMFiles>();
ZCRMFiles file = ZCRMFiles.GetInstance("aexxxxxxxxxx732e26505e22e", null);
fileObjects.Add(file);
file = ZCRMFiles.GetInstance("aexxxxxxxxxx732e26505e22e", null);
fileObjects.Add(file);
record.SetFieldValue("File_Upload", fileObjects);
/** Following methods are being used only by Inventory modules */
ZCRMPriceBookPricing pricing;
pricing = new ZCRMPriceBookPricing
{
ToRange = 5,
FromRange = 1,
Discount = 0
};
record.AddPriceDetail(pricing);
pricing = new ZCRMPriceBookPricing
{
ToRange = 11,
FromRange = 6,
Discount = 1
};
record.AddPriceDetail(pricing);
pricing = new ZCRMPriceBookPricing
{
ToRange = 17,
FromRange = 12,
Discount = 2
};
record.AddPriceDetail(pricing);
pricing = new ZCRMPriceBookPricing
{
ToRange = 23,
FromRange = 18,
Discount = 3
};
record.AddPriceDetail(pricing);
record.SetFieldValue("Pricing_Model", "Flat");
ZCRMTax linetax;
linetax = ZCRMTax.GetInstance("Sales Tax");
linetax.Percentage = 12.5;
record.AddTax(linetax);
ZCRMRecord product = ZCRMRecord.GetInstance("Products", 3372164000000190001); // product instance
ZCRMInventoryLineItem lineItem = new ZCRMInventoryLineItem(product); //To get ZCRMInventoryLineItem instance
lineItem.Description = "Product_description"; //To set line item description
lineItem.Discount = 5; //To set line item discount
lineItem.ListPrice = 100; //To set line item list price
ZCRMTax taxInstance1 = ZCRMTax.GetInstance("Sales Tax"); //To get ZCRMTax instance
taxInstance1.Percentage = 2; //To set tax percentage
taxInstance1.Value = 50; //To set tax value
lineItem.AddLineTax(taxInstance1); //To set line tax to line item
taxInstance1 = ZCRMTax.GetInstance("Vat");
taxInstance1.Percentage = 12;
taxInstance1.Value = 50;
lineItem.AddLineTax(taxInstance1);
lineItem.Quantity = 100; //To set product quantity to this line item
record.AddLineItem(lineItem); //The line item set to the record object
/** End Inventory **/
listRecord.Add(record);
record = ZCRMRecord.GetInstance("Invoices", null); //To get ZCRMRecord instance
record.SetFieldValue("Subject", "Invoice4"); //This method use to set FieldApiName and value similar to all other FieldApis and Custom field
record.SetFieldValue("Account_Name", 3372164000001855101);
record.SetFieldValue("Company", "KK");
record.SetFieldValue("Last_Name", "User");
record.SetFieldValue("Customfield", "CustomFieldValue");
record.SetFieldValue("Price_Book_Name", "Price_Book_Name1");
/** Following methods are being used only by Inventory modules */
ZCRMPriceBookPricing pricing1;
pricing1 = new ZCRMPriceBookPricing
{
ToRange = 5,
FromRange = 1,
Discount = 0
};
record.AddPriceDetail(pricing1);
pricing1 = new ZCRMPriceBookPricing
{
ToRange = 11,
FromRange = 6,
Discount = 1
};
record.AddPriceDetail(pricing1);
pricing1 = new ZCRMPriceBookPricing
{
ToRange = 17,
FromRange = 12,
Discount = 2
};
record.AddPriceDetail(pricing1);
pricing1 = new ZCRMPriceBookPricing
{
ToRange = 23,
FromRange = 18,
Discount = 3
};
record.AddPriceDetail(pricing1);
record.SetFieldValue("Pricing_Model", "Flat");
linetax = ZCRMTax.GetInstance("Sales Tax");
linetax.Percentage = 12.5;
record.AddTax(linetax);
ZCRMRecord product1 = ZCRMRecord.GetInstance("Products", 3372164000000190001); // product instance
ZCRMInventoryLineItem lineItem1 = new ZCRMInventoryLineItem(product1)
{
Description = "Product_description", //To set line item description
Discount = 5, //To set line item discount
ListPrice = 100 //To set line item list price
}; //To get ZCRMInventoryLineItem instance
lineItem1.DiscountPercentage = 10;
ZCRMTax taxInstance11 = ZCRMTax.GetInstance("Sales Tax"); //To get ZCRMTax instance
taxInstance11.Percentage = 2; //To set tax percentage
taxInstance11.Value = 50; //To set tax value
lineItem1.AddLineTax(taxInstance11); //To set line tax to line item
taxInstance11 = ZCRMTax.GetInstance("Vat");
taxInstance11.Percentage = 12;
taxInstance11.Value = 50;
lineItem1.AddLineTax(taxInstance11);
lineItem1.Quantity = 100; //To set product quantity to this line item
record.AddLineItem(lineItem1); //The line item set to the record object
/** End Inventory **/
listRecord.Add(record);
ZCRMModule moduleIns = ZCRMModule.GetInstance("Invoices");
List<string> trigger = new List<string>() { "workflow", "approval", "blueprint" };
string larID = "3477053013";
BulkAPIResponse<ZCRMRecord> responseIns = moduleIns.CreateRecords(listRecord, trigger, larID); //To call the create record method
Console.WriteLine("HTTP Status Code:"+responseIns.HttpStatusCode); //To get create record http response code
foreach (EntityResponse response in responseIns.BulkEntitiesResponse)
{
Console.WriteLine("Status:" + response.Status); //To get create record response status
Console.WriteLine("Message:" + response.Message); //To get create record response message
Console.WriteLine("Details:" + response.ResponseJSON); //To get create record response details
ZCRMRecord record1 = (ZCRMRecord)response.Data;
Console.WriteLine(record1.EntityId); //To get inserted record id
Console.WriteLine(record1.CreatedTime);
Console.WriteLine(record1.ModifiedTime);
ZCRMUser CreatedBy = record1.CreatedBy;
if(CreatedBy != null)
{
Console.WriteLine(CreatedBy.Id);
Console.WriteLine(CreatedBy.FullName);
}
ZCRMUser ModifiedBy = record1.ModifiedBy;
if (ModifiedBy != null)
{
Console.WriteLine(ModifiedBy.Id);
Console.WriteLine(ModifiedBy.FullName);
}
}
}
Update Records
/** Update records*/
public void UpdateRecords()
{
List<ZCRMRecord> listRecord = new List<ZCRMRecord>();
ZCRMRecord record;
record = new ZCRMRecord("Invoices"); //To get ZCRMRecord instance
record.SetFieldValue("id", 3372164000001904002);
record.SetFieldValue("Subject", "UpdateInvoice4"); //This method use to set FieldApiName and value similar to all other FieldApis and Custom field
record.SetFieldValue("Account_Name", 3372164000001855101);
record.SetFieldValue("Company", "KK");
record.SetFieldValue("Last_Name", "User");
record.SetFieldValue("Customfield", "CustomFieldValue");
record.SetFieldValue("Price_Book_Name", "Price_Book_Name");
//Following methods are used to update or delete a file uploaded to a field
List<ZCRMFiles> fileObjects = new List<ZCRMFiles>();
ZCRMFiles file = ZCRMFiles.GetInstance(null, null);
file.AttachmentId = "3477xxxxxx4016";
file.Delete = true;
fileObjects.Add(file);
file = ZCRMFiles.GetInstance(null, null);
file.AttachmentId = "34770xxxxx4017";
file.Delete = true;
fileObjects.Add(file);
file = ZCRMFiles.GetInstance("ae9xxxxxxxxxx1ce94b962", null);
fileObjects.Add(file);
record.SetFieldValue("File_Upload", fileObjects);
/** Following methods are being used only by Inventory modules */
ZCRMPriceBookPricing pricing;
pricing = new ZCRMPriceBookPricing
{
ToRange = 5,
FromRange = 1,
Discount = 0
};
record.AddPriceDetail(pricing);
pricing = new ZCRMPriceBookPricing
{
ToRange = 11,
FromRange = 6,
Discount = 1
};
record.AddPriceDetail(pricing);
pricing = new ZCRMPriceBookPricing
{
ToRange = 17,
FromRange = 12,
Discount = 2
};
record.AddPriceDetail(pricing);
pricing = new ZCRMPriceBookPricing
{
ToRange = 23,
FromRange = 18,
Discount = 3
};
record.AddPriceDetail(pricing);
record.SetFieldValue("Pricing_Model", "Flat");
ZCRMTax linetax;
linetax = ZCRMTax.GetInstance("Sales Tax");
linetax.Percentage = 12.5;
record.AddTax(linetax);
ZCRMRecord product = ZCRMRecord.GetInstance("Products", 3372164000000190001); // product instance
ZCRMInventoryLineItem lineItem = new ZCRMInventoryLineItem(product)
{
Description = "Product_description", //To set line item description
Discount = 5, //To set line item discount
ListPrice = 100 //To set line item list price
}; //To get ZCRMInventoryLineItem instance
lineItem.DiscountPercentage = 10;
ZCRMTax taxInstance = ZCRMTax.GetInstance("Sales Tax"); //To get ZCRMTax instance
taxInstance.Percentage = 2; //To set tax percentage
taxInstance.Value = 50; //To set tax value
lineItem.AddLineTax(taxInstance); //To set line tax to line item
taxInstance = ZCRMTax.GetInstance("Vat");
taxInstance.Percentage = 12;
taxInstance.Value = 50;
lineItem.AddLineTax(taxInstance);
lineItem.Quantity = 200; //To set product quantity to this line item
record.AddLineItem(lineItem); //The line item set to the record object
/** End Inventory **/
listRecord.Add(record);
record = new ZCRMRecord("Invoices"); //To get ZCRMRecord instance
record.SetFieldValue("id", 3372164000001904001);
record.SetFieldValue("Subject", "UpdateInvoice4"); //This method use to set FieldApiName and value similar to all other FieldApis and Custom field
record.SetFieldValue("Account_Name", 3372164000001855101);
record.SetFieldValue("Company", "KK");
record.SetFieldValue("Last_Name", "User");
record.SetFieldValue("Customfield", "CustomFieldValue");
record.SetFieldValue("Price_Book_Name", "Price_Book_Name");
/** Following methods are being used only by Inventory modules */
ZCRMPriceBookPricing pricing1;
pricing1 = new ZCRMPriceBookPricing
{
ToRange = 5,
FromRange = 1,
Discount = 0
};
record.AddPriceDetail(pricing1);
pricing1 = new ZCRMPriceBookPricing
{
ToRange = 11,
FromRange = 6,
Discount = 1
};
record.AddPriceDetail(pricing1);
pricing1 = new ZCRMPriceBookPricing
{
ToRange = 17,
FromRange = 12,
Discount = 2
};
record.AddPriceDetail(pricing1);
pricing1 = new ZCRMPriceBookPricing
{
ToRange = 23,
FromRange = 18,
Discount = 3
};
record.AddPriceDetail(pricing1);
record.SetFieldValue("Pricing_Model", "Flat");
linetax = ZCRMTax.GetInstance("Sales Tax");
linetax.Percentage = 12.5;
record.AddTax(linetax);
ZCRMRecord product1 = ZCRMRecord.GetInstance("Products", 3372164000000190001); // product instance
ZCRMInventoryLineItem lineItem1 = new ZCRMInventoryLineItem(product1)
{
Description = "Product_description", //To set line item description
Discount = 5, //To set line item discount
ListPrice = 100 //To set line item list price
}; //To get ZCRMInventoryLineItem instance
lineItem1.DiscountPercentage = 10;
ZCRMTax taxInstance11 = ZCRMTax.GetInstance("Sales Tax"); //To get ZCRMTax instance
taxInstance11.Percentage = 2; //To set tax percentage
taxInstance11.Value = 50; //To set tax value
lineItem1.AddLineTax(taxInstance11); //To set line tax to line item
taxInstance11 = ZCRMTax.GetInstance("Vat");
taxInstance11.Percentage = 12;
taxInstance11.Value = 50;
lineItem1.AddLineTax(taxInstance11);
lineItem1.Quantity = 500; //To set product quantity to this line item
record.AddLineItem(lineItem1); //The line item set to the record object
/** End Inventory **/
listRecord.Add(record);
ZCRMModule moduleIns = ZCRMModule.GetInstance("Invoices"); //To get the Module instance
List<String> trigger = new List<String>() { "workflow", "approval", "blueprint" };
BulkAPIResponse<ZCRMRecord< responseIns = moduleIns.UpdateRecords(listRecord, trigger); //To call the Update record method
Console.WriteLine("HTTP Status Code:" + responseIns.HttpStatusCode); //To get Update record http response code
foreach (EntityResponse response in responseIns.BulkEntitiesResponse)
{
Console.WriteLine("Status:" + response.Status); //To get Update record response status
Console.WriteLine("Message:" + response.Message); //To get Update record response message
Console.WriteLine("Details:" + response.ResponseJSON); //To get Update record response details
ZCRMRecord record1 = (ZCRMRecord)response.Data;
Console.WriteLine(record1.EntityId); //To get inserted record id
Console.WriteLine(record1.CreatedTime);
Console.WriteLine(record1.ModifiedTime);
ZCRMUser CreatedBy = record1.CreatedBy;
if(CreatedBy != null)
{
Console.WriteLine(CreatedBy.Id);
Console.WriteLine(CreatedBy.FullName);
}
ZCRMUser ModifiedBy = record1.ModifiedBy;
if (ModifiedBy != null)
{
Console.WriteLine(ModifiedBy.Id);
Console.WriteLine(ModifiedBy.FullName);
}
}
}
Upsert Records (Insert/Update)
/** Insert or Update (upsert) */
public void UpsertRecords()
{
/** Insert or Update (upsert) */
List<ZCRMRecord> recordslist = new List<ZCRMRecord>();
ZCRMRecord record1 = new ZCRMRecord("Leads"); //module api name
record1.SetFieldValue("Company", "Zylker");
record1.SetFieldValue("First_name", "Boyle");
record1.SetFieldValue("Last_Name", "Patricia");
record1.SetFieldValue("Email", "p.boyle@zylker.com");
record1.SetFieldValue("State", "Texas");
recordslist.Add(record1);
ZCRMRecord record2 = new ZCRMRecord("Leads"); //module api name
record2.SetFieldValue("Company", "Grumman Corp");
record2.SetFieldValue("First_name", "Deborah");
record2.SetFieldValue("Last_Name", "Johnson");
record2.SetFieldValue("Email", "d.johnson@grumman.com");
record2.SetFieldValue("State", "Texas");
recordslist.Add(record2);
List<string> duplicate_check_fields = new List<string>() { "Email"};// unique fields
ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //module api name
List<string> trigger = new List<string>() { "workflow", "approval", "blueprint" };
string larID = "3477061000004353013";
BulkAPIResponse<ZCRMRecord> response = moduleIns.UpsertRecords(recordslist, duplicate_check_fields, trigger, larID); //records - list of ZCRMRecord instances filled with required data for upsert.
List<ZCRMRecord> records = response.BulkData; //To get response List of ZCRMRecord.
Console.WriteLine(response.HttpStatusCode);
foreach (EntityResponse eResponse in response.BulkEntitiesResponse)
{
Console.WriteLine("Status:" + eResponse.Status); //To get create record response status
Console.WriteLine("Message:" + eResponse.Message); //To get create record response message
Console.WriteLine("Details:" + eResponse.ResponseJSON); //To get create record response details
ZCRMRecord record = (ZCRMRecord)eResponse.Data;
Console.WriteLine(record.EntityId); //To get record id
Console.WriteLine(record.ModuleAPIName); //To get module api name
Console.WriteLine(record.LookupLabel); //To get lookup object name
ZCRMUser createdBy = record.CreatedBy;
Console.WriteLine(createdBy.Id); //To get UserId who created the record
Console.WriteLine(createdBy.FullName); //To get User name who created the record
ZCRMUser modifiedBy = record.ModifiedBy;
Console.WriteLine(modifiedBy.Id); //To get UserId who modified the record
Console.WriteLine(modifiedBy.FullName); //To get User name who modified the record
Console.WriteLine(record.CreatedTime); //To get record created time
Console.WriteLine(record.ModifiedTime); //To get record modified time
Console.WriteLine(record.GetFieldValue("Last_Name")); //To get particular field value
}
}
Delete Records
/** Delete records */
public void DeleteRecords()
{
List<long> listRecord = new List<long>() { 538518000000449016, 538518000000449003};
ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //To get the Module instance
BulkAPIResponse<ZCRMEntity> responseIns = moduleIns.DeleteRecords(listRecord); //To call the delete record method
Console.WriteLine("HTTP Status Code:" + responseIns.HttpStatusCode); //To get delete record http response code
foreach (EntityResponse response in responseIns.BulkEntitiesResponse)
{
Console.WriteLine("Status:" + response.Status); //To get delete record response status
Console.WriteLine("Message:" + response.Message); //To get delete record response message
Console.WriteLine("Details:" + response.ResponseJSON); //To get delete record response details
ZCRMRecord record = (ZCRMRecord)response.Data;
Console.WriteLine(record.EntityId); //To get inserted record id
Console.WriteLine(record.ModuleAPIName);
}
}
Mass Update Records
/** MassUpdate records */
public void MassUpdateRecords()
{
List<long> listRecord = new List<long>() { 3372164000001891150, 3372164000001891136, 3372164000001891122 };
ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //To get the Module instance
BulkAPIResponse<ZCRMRecord> responseIns = moduleIns.MassUpdateRecords(listRecord, "Street", "UpdateStreet"); //To call the update record method
Console.WriteLine("HTTP Status Code:" + responseIns.HttpStatusCode); //To get update record http response code
foreach (EntityResponse response in responseIns.BulkEntitiesResponse)
{
Console.WriteLine("Status:" + response.Status); //To get Update record response status
Console.WriteLine("Message:" + response.Message); //To get Update record response message
Console.WriteLine("Details:" + response.ResponseJSON); //To get Update record response details
/*ZCRMRecord record = (ZCRMRecord)response.Data;
Console.WriteLine(record.EntityId); //To get inserted record id
Console.WriteLine(record.ModuleAPIName);*/
}
}
Get List of Deleted Records
/** Get list of deleted records */
public void GetAllDeletedRecords()
{
ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //To get the Module instance
BulkAPIResponse<ZCRMTrashRecord> responseIns = moduleIns.GetAllDeletedRecords(); //To call the delete record method
foreach (ZCRMTrashRecord record in responseIns.BulkData)
{
Console.WriteLine("EntityId:" + record.EntityId); //To get all deleted record id
Console.WriteLine("DisplayName:" + record.DisplayName); //To get all deleted record DisplayName
Console.WriteLine("Type:" + record.Type); //To get all deleted record Type
Console.WriteLine("DeletedTime:" + record.DeletedTime); //To get all deleted record DeletedTime
ZCRMUser CreatedBy = record.CreatedBy;
if (CreatedBy != null)
{
Console.WriteLine(CreatedBy.Id);
Console.WriteLine(CreatedBy.FullName);
}
ZCRMUser DeletedBy = record.DeletedBy;
if (DeletedBy != null)
{
Console.WriteLine(DeletedBy.Id);
Console.WriteLine(DeletedBy.FullName);
}
}
}
Get List of Recycle Bin Records
/** Get list of recycle bin records */
public void GetRecycleBinRecords()
{
ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //To get the Module instance
BulkAPIResponse<ZCRMTrashRecord> responseIns = moduleIns.GetRecycleBinRecords(); //To call the delete record method
foreach (ZCRMTrashRecord record in responseIns.BulkData)
{
Console.WriteLine("EntityId:" + record.EntityId); //To get all deleted record id
Console.WriteLine("DisplayName:" + record.DisplayName); //To get all deleted record DisplayName
Console.WriteLine("Type:" + record.Type); //To get all deleted record Type
Console.WriteLine("DeletedTime:" + record.DeletedTime); //To get all deleted record DeletedTime
ZCRMUser CreatedBy = record.CreatedBy;
if (CreatedBy != null)
{
Console.WriteLine(CreatedBy.Id);
Console.WriteLine(CreatedBy.FullName);
}
ZCRMUser DeletedBy = record.DeletedBy;
if (DeletedBy != null)
{
Console.WriteLine(DeletedBy.Id);
Console.WriteLine(DeletedBy.FullName);
}
}
}
Get List of Permanently Deleted Records
/** Get list of permanently deleted records */
public void GetPermanentlyDeletedRecords()
{
ZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); //To get the Module instance
BulkAPIResponse<ZCRMTrashRecord> responseIns = moduleIns.GetPermanentlyDeletedRecords(); //To call the delete record method
foreach (ZCRMTrashRecord record in responseIns.BulkData)
{
Console.WriteLine("EntityId:" + record.EntityId); //To get all deleted record id
Console.WriteLine("DisplayName:" + record.DisplayName); //To get all deleted record DisplayName
Console.WriteLine("Type:" + record.Type); //To get all deleted record Type
Console.WriteLine("DeletedTime:" + record.DeletedTime); //To get all deleted record DeletedTime
}
}
Search Records
Search Records by Word
//Search by Word:
public void SearchByWord()
{
ZCRMModule module = ZCRMModule.GetInstance("Leads");
Dictionary<string, string> methodsParams = new Dictionary<string, string>()
{
{"converted", "true" }
};
BulkAPIResponse<ZCRMRecord> response = module.SearchByWord("(SearchWord)",methodsParams);/** key value */
List<ZCRMRecord> records = response.BulkData; //To get response List of ZCRMRecord.
foreach (ZCRMRecord record in records)
{
Console.WriteLine(record.EntityId); //To get record id
Console.WriteLine(record.ModuleAPIName); //To get module api name
Console.WriteLine(record.LookupLabel); //To get lookup object name
ZCRMUser createdBy = record.CreatedBy;
Console.WriteLine(createdBy.Id); //To get UserId who created the record
Console.WriteLine(createdBy.FullName); //To get User name who created the record
ZCRMUser modifiedBy = record.ModifiedBy;
Console.WriteLine(modifiedBy.Id); //To get UserId who modified the record
Console.WriteLine(modifiedBy.FullName); //To get User name who modified the record
ZCRMUser owner = record.Owner;
Console.WriteLine(owner.Id); //To get record OwnerId
Console.WriteLine(owner.FullName);//To get record Owner name
Console.WriteLine(record.CreatedTime); //To get record created time
Console.WriteLine(record.ModifiedTime); //To get record modified time
Console.WriteLine(record.GetFieldValue("Last_Name")); //To get particular field value
if (record.Tags.Count > 0)
{
foreach (ZCRMTag tagnames in record.Tags)
{
Console.WriteLine(tagnames.Id);
Console.WriteLine(tagnames.Name);
}
Console.WriteLine("\n\n");
}
Dictionary<string, object> recordData = record.Data; //Returns record as Dictionary
//Console.WriteLine(record.PriceDetails);
foreach (KeyValuePair<string, object> data in record.Data)
{
if (data.Value is ZCRMRecord recordValue) //If data.Value is ZCRMRecord instance
{
Console.WriteLine(recordValue.EntityId); //To get record id
Console.WriteLine(recordValue.ModuleAPIName); //To get module api name
Console.WriteLine(recordValue.LookupLabel); //To get lookup object name
}
else if (data.Value is List<string> )
{
foreach (string tagnames in (List<string>)data.Value)
{
Console.WriteLine(tagnames);
}
Console.WriteLine("\n\n");
}
else //data.Value is not ZCRMRecord instance
{
Console.WriteLine(data.Key + "\t" + data.Value);
}
}
Console.WriteLine("\n\n");
/** Fields which start with "$" are considered to be property fields */
//Console.WriteLine(record.GetProperty("$fieldName")); //To get a particular property value
Dictionary<string, object> properties = record.Properties; //To get record properties as Dictionary
foreach (KeyValuePair<string, object> property in properties)
{
if (property.Value is List<string>) //If value is an array
{
Console.WriteLine("\n\n" + property.Key);
foreach (string data in (List<string>)property.Value)
{
Console.WriteLine(data + "\t");
}
}
else if (property.Value is Dictionary<string, object>)
{
Console.WriteLine("\n\n" + property.Key);
foreach (KeyValuePair<string, object> data in (Dictionary<string, object>)property.Value)
{
if (property.Value is Dictionary<string, object>)
{
foreach (KeyValuePair<string, object> data1 in (Dictionary<string, object>)data.Value)
{
Console.WriteLine(data1.Key + "\t" + data1.Value);
}
}
else
{
Console.WriteLine(data.Key + "\t" + data.Value);
}
}
}
else
{
Console.WriteLine(property.Key + "\t" + property.Value);
}
}
BulkAPIResponse<ZCRMRecord> relatedlist = record.GetRelatedListRecords("Products"); //To get Related records of a record
/** Related records is of type ZCRMRecord **/
List<ZCRMRecord> lists = relatedlist.BulkData; //To get related list data
foreach (ZCRMRecord rec in lists)
{
Console.WriteLine(rec.EntityId); //To get record id
Console.WriteLine(rec.ModuleAPIName); //To get module api name
}
BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes(); //To get record notes
//BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes(1,10); //page, perPage.
//BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes("title", CommonUtil.SortOrder.asc); //sortByField, sortOrder
//BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes("title", CommonUtil.SortOrder.asc,1,10, "2019-12-25T04:00:00+02:00"); //sortByField, sortOrder, page, perPage and modifiedSince(Header)
List<ZCRMNote> notes = noteResponse.BulkData;
foreach (ZCRMNote note in notes)
{
Console.WriteLine(note.Id); //To get note id
Console.WriteLine(note.Title); //To get note title
Console.WriteLine(note.Content); //To get note content
ZCRMRecord parentRecord = note.ParentRecord; //To get note's parent record
Console.WriteLine(parentRecord.EntityId); //To get note's parent record id
Console.WriteLine(parentRecord.ModuleAPIName); // To get note's parent record Module API name
ZCRMUser noteCreatedBy = note.CreatedBy;
Console.WriteLine(noteCreatedBy.Id); //To get UserId who created the notes
Console.WriteLine(noteCreatedBy.FullName); //To get User name who created the notes
ZCRMUser noteModifiedBy = note.ModifiedBy;
Console.WriteLine(noteModifiedBy.Id); //To get UserId who modified the notes
Console.WriteLine(noteModifiedBy.FullName); //To get User name who modified the notes
ZCRMUser noteOwner = note.NotesOwner;
Console.WriteLine(noteOwner.Id); //To get notes OwnerId
Console.WriteLine(noteOwner.FullName); //To get notes Owner name
Console.WriteLine(note.CreatedTime); //To get created time of the note
Console.WriteLine(note.ModifiedTime); //To get modified time of the note
List<ZCRMAttachment> noteAttachment = note.Attachments; //To get attachments of the note record
if (noteAttachment != null) //check If attachments is empty/not
{
foreach (ZCRMAttachment attachment in noteAttachment)
{
Console.WriteLine(attachment.Id); //To get the note's attachment id
Console.WriteLine(attachment.FileName); //To get the note's attachment file name
Console.WriteLine(attachment.FileType); //To get the note's attachment file type
Console.WriteLine(attachment.Size); //To get the note's attachment file size
ZCRMRecord attachmentRecord = attachment.ParentRecord;
Console.WriteLine(attachmentRecord.EntityId); //To get the note's parent record id
Console.WriteLine(attachmentRecord.ModuleAPIName); //To get the record name
ZCRMUser noteAttachmentCreatedBy = note.CreatedBy;
Console.WriteLine(noteAttachmentCreatedBy.Id); // To get user_id who created the note's attachment
Console.WriteLine(noteAttachmentCreatedBy.FullName); //To get user name who created the note's attachment
ZCRMUser noteAttachmentModifiedBy = note.ModifiedBy;
Console.WriteLine(noteAttachmentModifiedBy.Id); //To get user_id who modified the note's attachment
Console.WriteLine(noteAttachmentModifiedBy.FullName); //To get user name who modified the note's attachment
ZCRMUser noteAttachmentOwner = note.NotesOwner;
Console.WriteLine(noteAttachmentOwner.Id); //To get the note's attachment owner id
Console.WriteLine(noteAttachmentOwner.FullName); //To get the note's attachment owner name
Console.WriteLine(attachment.CreatedTime); //To get attachment created time
Console.WriteLine(attachment.ModifiedTime); //To get attachment modified time
}
}
}
BulkAPIResponse<ZCRMAttachment> attachmentResponse = record.GetAttachments(); //To get record's attachments
//BulkAPIResponse<ZCRMAttachment> attachmentResponse = record.GetAttachments(0,10, "019-12-25T04:00:00+02:00"); //page, perPage and modifiedSince(Header)
List<ZCRMAttachment> attachments = attachmentResponse.BulkData; // To get list of attachments
foreach (ZCRMAttachment attachment in attachments)
{
Console.WriteLine(attachment.Id); //To get the attachment id
Console.WriteLine(attachment.FileName); //To get attachment file name
Console.WriteLine(attachment.FileType); // To get attachment file type
Console.WriteLine(attachment.Size); //To get attachment file size
ZCRMRecord attachmentRecord = attachment.ParentRecord;
Console.WriteLine(attachmentRecord.EntityId); //To get the parent record id
Console.WriteLine(attachmentRecord.ModuleAPIName); //To get the parent record name
ZCRMUser attachmentCreatedBy = attachment.CreatedBy;
Console.WriteLine(attachmentCreatedBy.Id); // To get user_id who created the attachment
Console.WriteLine(attachmentCreatedBy.FullName); //To get user name who created the attachment
ZCRMUser attachmentModifiedBy = attachment.ModifiedBy;
Console.WriteLine(attachmentModifiedBy.Id); //To get user_id who modified the attachment
Console.WriteLine(attachmentModifiedBy.FullName); //To get user name who modified the attachment
ZCRMUser noteAttachmentOwner = attachment.Owner;
Console.WriteLine(noteAttachmentOwner.Id); //To get the attachment owner id
Console.WriteLine(noteAttachmentOwner.FullName); //To get the attachment owner name
Console.WriteLine(attachment.CreatedTime); //To get attachment created time
Console.WriteLine(attachment.ModifiedTime); //To get attachment modified time
FileAPIResponse fResponse = attachment.DownloadFile(); //To download the attachment file
Console.WriteLine("File Name:" + fResponse.GetFileName()); // To get attachment file name
Console.WriteLine("HTTP Status Code:" + fResponse.HttpStatusCode); //To get HTTP status code
Stream file = fResponse.GetFileAsStream(); //To get attachment file content
CommonUtil.SaveStreamAsFile("/Users/Desktop/photo", file, fResponse.GetFileName()); //To write a new file using the same attachment name
}
ZCRMLayout layout = record.Layout; //To get record layout
if (layout != null)
{
Console.WriteLine(layout.Id); //To get layout_id
Console.WriteLine(layout.Name); //To get layout name
}
/** Following methods are being used only by Inventory modules */
List<ZCRMTax> taxlists = record.TaxList; //To get the tax list
foreach (ZCRMTax tax in taxlists)
{
Console.WriteLine(tax.TaxName); //To get tax name
Console.WriteLine(tax.Percentage); //To get tax percentage
Console.WriteLine(tax.Value); //To get tax value
}
List<ZCRMInventoryLineItem> lineItems = record.LineItems; //To get list of line_items
foreach (ZCRMInventoryLineItem lineItem in lineItems)
{
Console.WriteLine(lineItem.Id); //To get lineItem id
Console.WriteLine(lineItem.ListPrice); //To get lineItem list price
Console.WriteLine(lineItem.Quantity); //To get lineItem quantity
Console.WriteLine(lineItem.Description); //To get lineItem description
Console.WriteLine(lineItem.Total); //To get lineItem total amount
Console.WriteLine(lineItem.Discount); //To get lineItem discount
Console.WriteLine(lineItem.DiscountPercentage); //To get lineItem discount percentage
Console.WriteLine(lineItem.TotalAfterDiscount); //To get lineItem amount after discount
Console.WriteLine(lineItem.TaxAmount); //To get lineItem tax amount
Console.WriteLine(lineItem.NetTotal); //To get lineItem net total amount
Console.WriteLine(lineItem.UnitPrice); //To get lineItem unit price
Console.WriteLine(lineItem.Product.EntityId); //To get line_item product's entity id
Console.WriteLine(lineItem.Product.LookupLabel); //To get line_item product's lookup label
List<ZCRMTax> linetaxs = lineItem.LineTax; //To get list of line_tax in lineItem
foreach (ZCRMTax tax in linetaxs)
{
Console.WriteLine(tax.TaxName); //To get line tax name
Console.WriteLine(tax.Percentage); //To get line tax percentage
Console.WriteLine(tax.Value); //To get line tax value
}
}
List<ZCRMPriceBookPricing> pricedetails = record.PriceDetails; //To get the price details array
foreach (ZCRMPriceBookPricing pricedetail in pricedetails)
{
Console.WriteLine(pricedetail.Id); //To get the record's priceId
Console.WriteLine(pricedetail.ToRange); //To get the price detail record's to_range
Console.WriteLine(pricedetail.FromRange); //To get the price detail record's from_range
Console.WriteLine(pricedetail.Discount); //To get the price detail record's discount
}
/** End Inventory **/
/** Following method is used only by 'Events' module */
List<ZCRMEventParticipant> participants = record.Participants; //To get Event record's participants
foreach (ZCRMEventParticipant participant in participants)
{
Console.WriteLine(participant.Id); //To get the record's participant id
Console.WriteLine(participant.Name); //To get the record's participant name
Console.WriteLine(participant.Email);//To get the record's participant email
Console.WriteLine(participant.Type); //To get the record's participant type
Console.WriteLine(participant.IsInvited); //To check if the record's participant(s) are invited or not
Console.WriteLine(participant.Status); //To get the record's participants' status
}
/* End Event */
}
//Console.WriteLine("Headers"+response.GetResponseHeaders());
BulkAPIResponse<ZCRMRecord>.ResponseInfo info = response.Info;
Console.WriteLine(info.AllowedCount);
Console.WriteLine(info.MoreRecords);
Console.WriteLine(info.PageNo);
Console.WriteLine(info.PerPage);
Console.WriteLine(info.RecordCount);
Console.WriteLine("RemainingAPICountForThisDay " + response.GetResponseHeaders().AllowedAPICallsPerMinute);
Console.WriteLine("RemainingAPICountForThisWindow " + response.GetResponseHeaders().RemainingAPICountForThisWindow);
Console.WriteLine("RemainingTimeForThisWindowReset " + response.GetResponseHeaders().RemainingTimeForThisWindowReset);
}
Search Records by Phone
//Search by Phone:
public void SearchByPhone()
{
ZCRMModule module = ZCRMModule.GetInstance("Leads");
Dictionary<string, string> methodsParams = new Dictionary<string, string>()
{
{"converted", "true" }
};
BulkAPIResponse<ZCRMRecord> response = module.SearchByPhone("{phone_number}",methodsParams);
List<ZCRMRecord> records = response.BulkData; //To get response List of ZCRMRecord.
foreach (ZCRMRecord record in records)
{
Console.WriteLine(record.EntityId); //To get record id
Console.WriteLine(record.ModuleAPIName); //To get module api name
Console.WriteLine(record.LookupLabel); //To get lookup object name
ZCRMUser createdBy = record.CreatedBy;
Console.WriteLine(createdBy.Id); //To get UserId who created the record
Console.WriteLine(createdBy.FullName); //To get User name who created the record
ZCRMUser modifiedBy = record.ModifiedBy;
Console.WriteLine(modifiedBy.Id); //To get UserId who modified the record
Console.WriteLine(modifiedBy.FullName); //To get User name who modified the record
ZCRMUser owner = record.Owner;
Console.WriteLine(owner.Id); //To get record OwnerId
Console.WriteLine(owner.FullName);//To get record Owner name
Console.WriteLine(record.CreatedTime); //To get record created time
Console.WriteLine(record.ModifiedTime); //To get record modified time
Console.WriteLine(record.GetFieldValue("Last_Name")); //To get particular field value
if (record.Tags.Count > 0)
{
foreach (ZCRMTag tagnames in record.Tags)
{
Console.WriteLine(tagnames.Id);
Console.WriteLine(tagnames.Name);
}
Console.WriteLine("\n\n");
}
Dictionary<string, object> recordData = record.Data; //Returns record as Dictionary
//Console.WriteLine(record.PriceDetails);
foreach (KeyValuePair<string, object> data in record.Data)
{
if (data.Value is ZCRMRecord recordValue) //If data.Value is ZCRMRecord instance
{
Console.WriteLine(recordValue.EntityId); //To get record id
Console.WriteLine(recordValue.ModuleAPIName); //To get module api name
Console.WriteLine(recordValue.LookupLabel); //To get lookup object name
}
else if (data.Value is List<string>)
{
foreach (string tagnames in (List<string>)data.Value)
{
Console.WriteLine(tagnames);
}
Console.WriteLine("\n\n");
}
else //data.Value is not ZCRMRecord instance
{
Console.WriteLine(data.Key + "\t" + data.Value);
}
}
Console.WriteLine("\n\n");
/** Fields which start with "$" are considered to be property fields */
//Console.WriteLine(record.GetProperty("$fieldName")); //To get a particular property value
Dictionary<string, object> properties = record.Properties; //To get record properties as Dictionary
foreach (KeyValuePair<string, object> property in properties)
{
if (property.Value is List<string>) //If value is an array
{
Console.WriteLine("\n\n" + property.Key);
foreach (string data in (List<string>)property.Value)
{
Console.WriteLine(data + "\t");
}
}
else if (property.Value is Dictionary<string, object>)
{
Console.WriteLine("\n\n" + property.Key);
foreach (KeyValuePair<string, object> data in (Dictionary<string, object>)property.Value)
{
if (property.Value is Dictionary<string, object>)
{
foreach (KeyValuePair<string, object> data1 in (Dictionary<string, object>)data.Value)
{
Console.WriteLine(data1.Key + "\t" + data1.Value);
}
}
else
{
Console.WriteLine(data.Key + "\t" + data.Value);
}
}
}
else
{
Console.WriteLine(property.Key + "\t" + property.Value);
}
}
BulkAPIResponse<ZCRMRecord> relatedlist = record.GetRelatedListRecords("Products"); //To get Related records of a record
/** Related records is of type ZCRMRecord **/
List<ZCRMRecord> lists = relatedlist.BulkData; //To get related list data
foreach (ZCRMRecord rec in lists)
{
Console.WriteLine(rec.EntityId); //To get record id
Console.WriteLine(rec.ModuleAPIName); //To get module api name
}
BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes(); //To get record notes
//BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes(1,10); //page, perPage.
//BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes("title", CommonUtil.SortOrder.asc); //sortByField, sortOrder
//BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes("title", CommonUtil.SortOrder.asc,1,10, "2019-12-25T04:00:00+02:00"); //sortByField, sortOrder, page, perPage and modifiedSince(Header)
List<ZCRMNote> notes = noteResponse.BulkData;
foreach (ZCRMNote note in notes)
{
Console.WriteLine(note.Id); //To get note id
Console.WriteLine(note.Title); //To get note title
Console.WriteLine(note.Content); //To get note content
ZCRMRecord parentRecord = note.ParentRecord; //To get note's parent record
Console.WriteLine(parentRecord.EntityId); //To get note's parent record id
Console.WriteLine(parentRecord.ModuleAPIName); // To get note's parent record Module API name
ZCRMUser noteCreatedBy = note.CreatedBy;
Console.WriteLine(noteCreatedBy.Id); //To get UserId who created the notes
Console.WriteLine(noteCreatedBy.FullName); //To get User name who created the notes
ZCRMUser noteModifiedBy = note.ModifiedBy;
Console.WriteLine(noteModifiedBy.Id); //To get UserId who modified the notes
Console.WriteLine(noteModifiedBy.FullName); //To get User name who modified the notes
ZCRMUser noteOwner = note.NotesOwner;
Console.WriteLine(noteOwner.Id); //To get notes OwnerId
Console.WriteLine(noteOwner.FullName); //To get notes Owner name
Console.WriteLine(note.CreatedTime); //To get created time of the note
Console.WriteLine(note.ModifiedTime); //To get modified time of the note
List<ZCRMAttachment> noteAttachment = note.Attachments; //To get attachments of the note record
if (noteAttachment != null) //check If attachments is empty/not
{
foreach (ZCRMAttachment attachment in noteAttachment)
{
Console.WriteLine(attachment.Id); //To get the note's attachment id
Console.WriteLine(attachment.FileName); //To get the note's attachment file name
Console.WriteLine(attachment.FileType); //To get the note's attachment file type
Console.WriteLine(attachment.Size); //To get the note's attachment file size
ZCRMRecord attachmentRecord = attachment.ParentRecord;
Console.WriteLine(attachmentRecord.EntityId); //To get the note's parent record id
Console.WriteLine(attachmentRecord.ModuleAPIName); //To get the record name
ZCRMUser noteAttachmentCreatedBy = note.CreatedBy;
Console.WriteLine(noteAttachmentCreatedBy.Id); // To get user_id who created the note's attachment
Console.WriteLine(noteAttachmentCreatedBy.FullName); //To get user name who created the note's attachment
ZCRMUser noteAttachmentModifiedBy = note.ModifiedBy;
Console.WriteLine(noteAttachmentModifiedBy.Id); //To get user_id who modified the note's attachment
Console.WriteLine(noteAttachmentModifiedBy.FullName); //To get user name who modified the note's attachment
ZCRMUser noteAttachmentOwner = note.NotesOwner;
Console.WriteLine(noteAttachmentOwner.Id); //To get the note's attachment owner id
Console.WriteLine(noteAttachmentOwner.FullName); //To get the note's attachment owner name
Console.WriteLine(attachment.CreatedTime); //To get attachment created time
Console.WriteLine(attachment.ModifiedTime); //To get attachment modified time
}
}
}
BulkAPIResponse<ZCRMAttachment> attachmentResponse = record.GetAttachments(); //To get record's attachments
//BulkAPIResponse<ZCRMAttachment> attachmentResponse = record.GetAttachments(0,10, "019-12-25T04:00:00+02:00"); //page, perPage and modifiedSince(Header)
List<ZCRMAttachment> attachments = attachmentResponse.BulkData; // To get list of attachments
foreach (ZCRMAttachment attachment in attachments)
{
Console.WriteLine(attachment.Id); //To get the attachment id
Console.WriteLine(attachment.FileName); //To get attachment file name
Console.WriteLine(attachment.FileType); // To get attachment file type
Console.WriteLine(attachment.Size); //To get attachment file size
ZCRMRecord attachmentRecord = attachment.ParentRecord;
Console.WriteLine(attachmentRecord.EntityId); //To get the parent record id
Console.WriteLine(attachmentRecord.ModuleAPIName); //To get the parent record name
ZCRMUser attachmentCreatedBy = attachment.CreatedBy;
Console.WriteLine(attachmentCreatedBy.Id); // To get user_id who created the attachment
Console.WriteLine(attachmentCreatedBy.FullName); //To get user name who created the attachment
ZCRMUser attachmentModifiedBy = attachment.ModifiedBy;
Console.WriteLine(attachmentModifiedBy.Id); //To get user_id who modified the attachment
Console.WriteLine(attachmentModifiedBy.FullName); //To get user name who modified the attachment
ZCRMUser noteAttachmentOwner = attachment.Owner;
Console.WriteLine(noteAttachmentOwner.Id); //To get the attachment owner id
Console.WriteLine(noteAttachmentOwner.FullName); //To get the attachment owner name
Console.WriteLine(attachment.CreatedTime); //To get attachment created time
Console.WriteLine(attachment.ModifiedTime); //To get attachment modified time
FileAPIResponse fResponse = attachment.DownloadFile(); //To download the attachment file
Console.WriteLine("File Name:" + fResponse.GetFileName()); // To get attachment file name
Console.WriteLine("HTTP Status Code:" + fResponse.HttpStatusCode); //To get HTTP status code
Stream file = fResponse.GetFileAsStream(); //To get attachment file content
CommonUtil.SaveStreamAsFile("/Users/Desktop/photo", file, fResponse.GetFileName()); //To write a new file using the same attachment name
}
ZCRMLayout layout = record.Layout; //To get record layout
if (layout != null)
{
Console.WriteLine(layout.Id); //To get layout_id
Console.WriteLine(layout.Name); //To get layout name
}
/** Following methods are being used only by Inventory modules */
List<ZCRMTax> taxlists = record.TaxList; //To get the tax list
foreach (ZCRMTax tax in taxlists)
{
Console.WriteLine(tax.TaxName); //To get tax name
Console.WriteLine(tax.Percentage); //To get tax percentage
Console.WriteLine(tax.Value); //To get tax value
}
List<ZCRMInventoryLineItem> lineItems = record.LineItems; //To get list of line_items
foreach (ZCRMInventoryLineItem lineItem in lineItems)
{
Console.WriteLine(lineItem.Id); //To get lineItem id
Console.WriteLine(lineItem.ListPrice); //To get lineItem list price
Console.WriteLine(lineItem.Quantity); //To get lineItem quantity
Console.WriteLine(lineItem.Description); //To get lineItem description
Console.WriteLine(lineItem.Total); //To get lineItem total amount
Console.WriteLine(lineItem.Discount); //To get lineItem discount
Console.WriteLine(lineItem.DiscountPercentage); //To get lineItem discount percentage
Console.WriteLine(lineItem.TotalAfterDiscount); //To get lineItem amount after discount
Console.WriteLine(lineItem.TaxAmount); //To get lineItem tax amount
Console.WriteLine(lineItem.NetTotal); //To get lineItem net total amount
Console.WriteLine(lineItem.UnitPrice); //To get lineItem unit price
Console.WriteLine(lineItem.Product.EntityId); //To get line_item product's entity id
Console.WriteLine(lineItem.Product.LookupLabel); //To get line_item product's lookup label
List<ZCRMTax> linetaxs = lineItem.LineTax; //To get list of line_tax in lineItem
foreach (ZCRMTax tax in linetaxs)
{
Console.WriteLine(tax.TaxName); //To get line tax name
Console.WriteLine(tax.Percentage); //To get line tax percentage
Console.WriteLine(tax.Value); //To get line tax value
}
}
List<ZCRMPriceBookPricing> pricedetails = record.PriceDetails; //To get the price details array
foreach (ZCRMPriceBookPricing pricedetail in pricedetails)
{
Console.WriteLine(pricedetail.Id); //To get the record's priceId
Console.WriteLine(pricedetail.ToRange); //To get the price detail record's to_range
Console.WriteLine(pricedetail.FromRange); //To get the price detail record's from_range
Console.WriteLine(pricedetail.Discount); //To get the price detail record's discount
}
/** End Inventory **/
/** Following method is used only by 'Events' module */
List<ZCRMEventParticipant> participants = record.Participants; //To get Event record's participants
foreach (ZCRMEventParticipant participant in participants)
{
Console.WriteLine(participant.Id); //To get the record's participant id
Console.WriteLine(participant.Name); //To get the record's participant name
Console.WriteLine(participant.Email);//To get the record's participant email
Console.WriteLine(participant.Type); //To get the record's participant type
Console.WriteLine(participant.IsInvited); //To check if the record's participant(s) are invited or not
Console.WriteLine(participant.Status); //To get the record's participants' status
}
/* End Event */
}
//Console.WriteLine("Headers"+response.GetResponseHeaders());
BulkAPIResponse<ZCRMRecord>.ResponseInfo info = response.Info;
Console.WriteLine(info.AllowedCount);
Console.WriteLine(info.MoreRecords);
Console.WriteLine(info.PageNo);
Console.WriteLine(info.PerPage);
Console.WriteLine(info.RecordCount);
Console.WriteLine("RemainingAPICountForThisDay " + response.GetResponseHeaders().AllowedAPICallsPerMinute);
Console.WriteLine("RemainingAPICountForThisWindow " + response.GetResponseHeaders().RemainingAPICountForThisWindow);
Console.WriteLine("RemainingTimeForThisWindowReset " + response.GetResponseHeaders().RemainingTimeForThisWindowReset);
}
Search Records by Email
//Search by Email:
public void SearchByEmail()
{
ZCRMModule module = ZCRMModule.GetInstance("Leads");
Dictionary<string, string> methodsParams = new Dictionary<string, string>()
{
{"converted", "true" }
};
BulkAPIResponse<ZCRMRecord> response = module.SearchByEmail("newcrmapi@zoho.com",methodsParams);
List<ZCRMRecord> records = response.BulkData; //To get response List of ZCRMRecord.
foreach (ZCRMRecord record in records)
{
Console.WriteLine(record.EntityId); //To get record id
Console.WriteLine(record.ModuleAPIName); //To get module api name
Console.WriteLine(record.LookupLabel); //To get lookup object name
ZCRMUser createdBy = record.CreatedBy;
Console.WriteLine(createdBy.Id); //To get UserId who created the record
Console.WriteLine(createdBy.FullName); //To get User name who created the record
ZCRMUser modifiedBy = record.ModifiedBy;
Console.WriteLine(modifiedBy.Id); //To get UserId who modified the record
Console.WriteLine(modifiedBy.FullName); //To get User name who modified the record
ZCRMUser owner = record.Owner;
Console.WriteLine(owner.Id); //To get record OwnerId
Console.WriteLine(owner.FullName);//To get record Owner name
Console.WriteLine(record.CreatedTime); //To get record created time
Console.WriteLine(record.ModifiedTime); //To get record modified time
Console.WriteLine(record.GetFieldValue("Last_Name")); //To get particular field value
if (record.Tags.Count > 0)
{
foreach (ZCRMTag tagnames in record.Tags)
{
Console.WriteLine(tagnames.Id);
Console.WriteLine(tagnames.Name);
}
Console.WriteLine("\n\n");
}
Dictionary<string, object> recordData = record.Data; //Returns record as Dictionary
//Console.WriteLine(record.PriceDetails);
foreach (KeyValuePair<string, object> data in record.Data)
{
if (data.Value is ZCRMRecord recordValue) //If data.Value is ZCRMRecord instance
{
Console.WriteLine(recordValue.EntityId); //To get record id
Console.WriteLine(recordValue.ModuleAPIName); //To get module api name
Console.WriteLine(recordValue.LookupLabel); //To get lookup object name
}
else if (data.Value is List<string>)
{
foreach (string tagnames in (List<string>)data.Value)
{
Console.WriteLine(tagnames);
}
Console.WriteLine("\n\n");
}
else //data.Value is not ZCRMRecord instance
{
Console.WriteLine(data.Key + "\t" + data.Value);
}
}
Console.WriteLine("\n\n");
/** Fields which start with "$" are considered to be property fields */
//Console.WriteLine(record.GetProperty("$fieldName")); //To get a particular property value
Dictionary<string, object> properties = record.Properties; //To get record properties as Dictionary
foreach (KeyValuePair<string, object> property in properties)
{
if (property.Value is List<string>) //If value is an array
{
Console.WriteLine("\n\n" + property.Key);
foreach (string data in (List<string>)property.Value)
{
Console.WriteLine(data + "\t");
}
}
else if (property.Value is Dictionary<string, object>)
{
Console.WriteLine("\n\n" + property.Key);
foreach (KeyValuePair<string, object> data in (Dictionary<string, object>)property.Value)
{
if (property.Value is Dictionary<string, object>)
{
foreach (KeyValuePair<string, object> data1 in (Dictionary<string, object>)data.Value)
{
Console.WriteLine(data1.Key + "\t" + data1.Value);
}
}
else
{
Console.WriteLine(data.Key + "\t" + data.Value);
}
}
}
else
{
Console.WriteLine(property.Key + "\t" + property.Value);
}
}
BulkAPIResponse<ZCRMRecord> relatedlist = record.GetRelatedListRecords("Products"); //To get Related records of a record
/** Related records is of type ZCRMRecord **/
List<ZCRMRecord> lists = relatedlist.BulkData; //To get related list data
foreach (ZCRMRecord rec in lists)
{
Console.WriteLine(rec.EntityId); //To get record id
Console.WriteLine(rec.ModuleAPIName); //To get module api name
}
BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes(); //To get record notes
//BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes(1,10); //page, perPage.
//BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes("title", CommonUtil.SortOrder.asc); //sortByField, sortOrder
//BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes("title", CommonUtil.SortOrder.asc,1,10, "2019-12-25T04:00:00+02:00"); //sortByField, sortOrder, page, perPage and modifiedSince(Header)
List<ZCRMNote> notes = noteResponse.BulkData;
foreach (ZCRMNote note in notes)
{
Console.WriteLine(note.Id); //To get note id
Console.WriteLine(note.Title); //To get note title
Console.WriteLine(note.Content); //To get note content
ZCRMRecord parentRecord = note.ParentRecord; //To get note's parent record
Console.WriteLine(parentRecord.EntityId); //To get note's parent record id
Console.WriteLine(parentRecord.ModuleAPIName); // To get note's parent record Module API name
ZCRMUser noteCreatedBy = note.CreatedBy;
Console.WriteLine(noteCreatedBy.Id); //To get UserId who created the notes
Console.WriteLine(noteCreatedBy.FullName); //To get User name who created the notes
ZCRMUser noteModifiedBy = note.ModifiedBy;
Console.WriteLine(noteModifiedBy.Id); //To get UserId who modified the notes
Console.WriteLine(noteModifiedBy.FullName); //To get User name who modified the notes
ZCRMUser noteOwner = note.NotesOwner;
Console.WriteLine(noteOwner.Id); //To get notes OwnerId
Console.WriteLine(noteOwner.FullName); //To get notes Owner name
Console.WriteLine(note.CreatedTime); //To get created time of the note
Console.WriteLine(note.ModifiedTime); //To get modified time of the note
List<ZCRMAttachment> noteAttachment = note.Attachments; //To get attachments of the note record
if (noteAttachment != null) //check If attachments is empty/not
{
foreach (ZCRMAttachment attachment in noteAttachment)
{
Console.WriteLine(attachment.Id); //To get the note's attachment id
Console.WriteLine(attachment.FileName); //To get the note's attachment file name
Console.WriteLine(attachment.FileType); //To get the note's attachment file type
Console.WriteLine(attachment.Size); //To get the note's attachment file size
ZCRMRecord attachmentRecord = attachment.ParentRecord;
Console.WriteLine(attachmentRecord.EntityId); //To get the note's parent record id
Console.WriteLine(attachmentRecord.ModuleAPIName); //To get the record name
ZCRMUser noteAttachmentCreatedBy = note.CreatedBy;
Console.WriteLine(noteAttachmentCreatedBy.Id); // To get user_id who created the note's attachment
Console.WriteLine(noteAttachmentCreatedBy.FullName); //To get user name who created the note's attachment
ZCRMUser noteAttachmentModifiedBy = note.ModifiedBy;
Console.WriteLine(noteAttachmentModifiedBy.Id); //To get user_id who modified the note's attachment
Console.WriteLine(noteAttachmentModifiedBy.FullName); //To get user name who modified the note's attachment
ZCRMUser noteAttachmentOwner = note.NotesOwner;
Console.WriteLine(noteAttachmentOwner.Id); //To get the note's attachment owner id
Console.WriteLine(noteAttachmentOwner.FullName); //To get the note's attachment owner name
Console.WriteLine(attachment.CreatedTime); //To get attachment created time
Console.WriteLine(attachment.ModifiedTime); //To get attachment modified time
}
}
}
BulkAPIResponse<ZCRMAttachment> attachmentResponse = record.GetAttachments(); //To get record's attachments
//BulkAPIResponse<ZCRMAttachment> attachmentResponse = record.GetAttachments(0,10, "019-12-25T04:00:00+02:00"); //page, perPage and modifiedSince(Header)
List<ZCRMAttachment> attachments = attachmentResponse.BulkData; // To get list of attachments
foreach (ZCRMAttachment attachment in attachments)
{
Console.WriteLine(attachment.Id); //To get the attachment id
Console.WriteLine(attachment.FileName); //To get attachment file name
Console.WriteLine(attachment.FileType); // To get attachment file type
Console.WriteLine(attachment.Size); //To get attachment file size
ZCRMRecord attachmentRecord = attachment.ParentRecord;
Console.WriteLine(attachmentRecord.EntityId); //To get the parent record id
Console.WriteLine(attachmentRecord.ModuleAPIName); //To get the parent record name
ZCRMUser attachmentCreatedBy = attachment.CreatedBy;
Console.WriteLine(attachmentCreatedBy.Id); // To get user_id who created the attachment
Console.WriteLine(attachmentCreatedBy.FullName); //To get user name who created the attachment
ZCRMUser attachmentModifiedBy = attachment.ModifiedBy;
Console.WriteLine(attachmentModifiedBy.Id); //To get user_id who modified the attachment
Console.WriteLine(attachmentModifiedBy.FullName); //To get user name who modified the attachment
ZCRMUser noteAttachmentOwner = attachment.Owner;
Console.WriteLine(noteAttachmentOwner.Id); //To get the attachment owner id
Console.WriteLine(noteAttachmentOwner.FullName); //To get the attachment owner name
Console.WriteLine(attachment.CreatedTime); //To get attachment created time
Console.WriteLine(attachment.ModifiedTime); //To get attachment modified time
FileAPIResponse fResponse = attachment.DownloadFile(); //To download the attachment file
Console.WriteLine("File Name:" + fResponse.GetFileName()); // To get attachment file name
Console.WriteLine("HTTP Status Code:" + fResponse.HttpStatusCode); //To get HTTP status code
Stream file = fResponse.GetFileAsStream(); //To get attachment file content
CommonUtil.SaveStreamAsFile("/Users/Desktop/photo", file, fResponse.GetFileName()); //To write a new file using the same attachment name
}
ZCRMLayout layout = record.Layout; //To get record layout
if (layout != null)
{
Console.WriteLine(layout.Id); //To get layout_id
Console.WriteLine(layout.Name); //To get layout name
}
/** Following methods are being used only by Inventory modules */
List<ZCRMTax> taxlists = record.TaxList; //To get the tax list
foreach (ZCRMTax tax in taxlists)
{
Console.WriteLine(tax.TaxName); //To get tax name
Console.WriteLine(tax.Percentage); //To get tax percentage
Console.WriteLine(tax.Value); //To get tax value
}
List<ZCRMInventoryLineItem> lineItems = record.LineItems; //To get list of line_items
foreach (ZCRMInventoryLineItem lineItem in lineItems)
{
Console.WriteLine(lineItem.Id); //To get lineItem id
Console.WriteLine(lineItem.ListPrice); //To get lineItem list price
Console.WriteLine(lineItem.Quantity); //To get lineItem quantity
Console.WriteLine(lineItem.Description); //To get lineItem description
Console.WriteLine(lineItem.Total); //To get lineItem total amount
Console.WriteLine(lineItem.Discount); //To get lineItem discount
Console.WriteLine(lineItem.DiscountPercentage); //To get lineItem discount percentage
Console.WriteLine(lineItem.TotalAfterDiscount); //To get lineItem amount after discount
Console.WriteLine(lineItem.TaxAmount); //To get lineItem tax amount
Console.WriteLine(lineItem.NetTotal); //To get lineItem net total amount
Console.WriteLine(lineItem.UnitPrice); //To get lineItem unit price
Console.WriteLine(lineItem.Product.EntityId); //To get line_item product's entity id
Console.WriteLine(lineItem.Product.LookupLabel); //To get line_item product's lookup label
List<ZCRMTax> linetaxs = lineItem.LineTax; //To get list of line_tax in lineItem
foreach (ZCRMTax tax in linetaxs)
{
Console.WriteLine(tax.TaxName); //To get line tax name
Console.WriteLine(tax.Percentage); //To get line tax percentage
Console.WriteLine(tax.Value); //To get line tax value
}
}
List<ZCRMPriceBookPricing> pricedetails = record.PriceDetails; //To get the price details array
foreach (ZCRMPriceBookPricing pricedetail in pricedetails)
{
Console.WriteLine(pricedetail.Id); //To get the record's priceId
Console.WriteLine(pricedetail.ToRange); //To get the price detail record's to_range
Console.WriteLine(pricedetail.FromRange); //To get the price detail record's from_range
Console.WriteLine(pricedetail.Discount); //To get the price detail record's discount
}
/** End Inventory **/
/** Following method is used only by 'Events' module */
List<ZCRMEventParticipant> participants = record.Participants; //To get Event record's participants
foreach (ZCRMEventParticipant participant in participants)
{
Console.WriteLine(participant.Id); //To get the record's participant id
Console.WriteLine(participant.Name); //To get the record's participant name
Console.WriteLine(participant.Email);//To get the record's participant email
Console.WriteLine(participant.Type); //To get the record's participant type
Console.WriteLine(participant.IsInvited); //To check if the record's participant(s) are invited or not
Console.WriteLine(participant.Status); //To get the record's participants' status
}
/* End Event */
}
//Console.WriteLine("Headers"+response.GetResponseHeaders());
BulkAPIResponse<ZCRMRecord>.ResponseInfo info = response.Info;
Console.WriteLine(info.AllowedCount);
Console.WriteLine(info.MoreRecords);
Console.WriteLine(info.PageNo);
Console.WriteLine(info.PerPage);
Console.WriteLine(info.RecordCount);
Console.WriteLine("RemainingAPICountForThisDay " + response.GetResponseHeaders().AllowedAPICallsPerMinute);
Console.WriteLine("RemainingAPICountForThisWindow " + response.GetResponseHeaders().RemainingAPICountForThisWindow);
Console.WriteLine("RemainingTimeForThisWindowReset " + response.GetResponseHeaders().RemainingTimeForThisWindowReset);
}
Search Records by Criteria
//Search by Criteria:
public void SearchByCriteria()
{
ZCRMModule module = ZCRMModule.GetInstance("Leads");
Dictionary<string, string> methodsParams = new Dictionary<string, string>()
{
{"converted", "true" }
};
BulkAPIResponse<ZCRMRecord> response = module.SearchByCriteria("((Last_Name:starts_with:{last_name}) or (Email:starts_with:email@zoho.com))",methodsParams);
List<ZCRMRecord> records = response.BulkData; //To get response List of ZCRMRecord.
foreach (ZCRMRecord record in records)
{
Console.WriteLine(record.EntityId); //To get record id
Console.WriteLine(record.ModuleAPIName); //To get module api name
Console.WriteLine(record.LookupLabel); //To get lookup object name
ZCRMUser createdBy = record.CreatedBy;
Console.WriteLine(createdBy.Id); //To get UserId who created the record
Console.WriteLine(createdBy.FullName); //To get User name who created the record
ZCRMUser modifiedBy = record.ModifiedBy;
Console.WriteLine(modifiedBy.Id); //To get UserId who modified the record
Console.WriteLine(modifiedBy.FullName); //To get User name who modified the record
ZCRMUser owner = record.Owner;
Console.WriteLine(owner.Id); //To get record OwnerId
Console.WriteLine(owner.FullName);//To get record Owner name
Console.WriteLine(record.CreatedTime); //To get record created time
Console.WriteLine(record.ModifiedTime); //To get record modified time
Console.WriteLine(record.GetFieldValue("Last_Name")); //To get particular field value
if (record.Tags.Count > 0)
{
foreach (ZCRMTag tagnames in record.Tags)
{
Console.WriteLine(tagnames.Id);
Console.WriteLine(tagnames.Name);
}
Console.WriteLine("\n\n");
}
Dictionary<string, object> recordData = record.Data; //Returns record as Dictionary
//Console.WriteLine(record.PriceDetails);
foreach (KeyValuePair<string, object> data in record.Data)
{
if (data.Value is ZCRMRecord recordValue) //If data.Value is ZCRMRecord instance
{
Console.WriteLine(recordValue.EntityId); //To get record id
Console.WriteLine(recordValue.ModuleAPIName); //To get module api name
Console.WriteLine(recordValue.LookupLabel); //To get lookup object name
}
else if (data.Value is List<string>)
{
foreach (string tagnames in (List<string>)data.Value)
{
Console.WriteLine(tagnames);
}
Console.WriteLine("\n\n");
}
else //data.Value is not ZCRMRecord instance
{
Console.WriteLine(data.Key + "\t" + data.Value);
}
}
Console.WriteLine("\n\n");
/** Fields which start with "$" are considered to be property fields */
//Console.WriteLine(record.GetProperty("$fieldName")); //To get a particular property value
Dictionary<string, object> properties = record.Properties; //To get record properties as Dictionary
foreach (KeyValuePair<string, object> property in properties)
{
if (property.Value is List<string>) //If value is an array
{
Console.WriteLine("\n\n" + property.Key);
foreach (string data in (List<string>)property.Value)
{
Console.WriteLine(data + "\t");
}
}
else if (property.Value is Dictionary<string, object>)
{
Console.WriteLine("\n\n" + property.Key);
foreach (KeyValuePair<string, object> data in (Dictionary<string, object>)property.Value)
{
if (property.Value is Dictionary<string, object>)
{
foreach (KeyValuePair<string, object> data1 in (Dictionary<string, object>)data.Value)
{
Console.WriteLine(data1.Key + "\t" + data1.Value);
}
}
else
{
Console.WriteLine(data.Key + "\t" + data.Value);
}
}
}
else
{
Console.WriteLine(property.Key + "\t" + property.Value);
}
}
BulkAPIResponse<ZCRMRecord> relatedlist = record.GetRelatedListRecords("Products"); //To get Related records of a record
/** Related records is of type ZCRMRecord **/
List<ZCRMRecord> lists = relatedlist.BulkData; //To get related list data
foreach (ZCRMRecord rec in lists)
{
Console.WriteLine(rec.EntityId); //To get record id
Console.WriteLine(rec.ModuleAPIName); //To get module api name
}
BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes(); //To get record notes
//BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes(1,10); //page, perPage.
//BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes("title", CommonUtil.SortOrder.asc); //sortByField, sortOrder
//BulkAPIResponse<ZCRMNote> noteResponse = record.GetNotes("title", CommonUtil.SortOrder.asc,1,10, "2019-12-25T04:00:00+02:00"); //sortByField, sortOrder, page, perPage and modifiedSince(Header)
List<ZCRMNote> notes = noteResponse.BulkData;
foreach (ZCRMNote note in notes)
{
Console.WriteLine(note.Id); //To get note id
Console.WriteLine(note.Title); //To get note title
Console.WriteLine(note.Content); //To get note content
ZCRMRecord parentRecord = note.ParentRecord; //To get note's parent record
Console.WriteLine(parentRecord.EntityId); //To get note's parent record id
Console.WriteLine(parentRecord.ModuleAPIName); // To get note's parent record Module API name
ZCRMUser noteCreatedBy = note.CreatedBy;
Console.WriteLine(noteCreatedBy.Id); //To get UserId who created the notes
Console.WriteLine(noteCreatedBy.FullName); //To get User name who created the notes
ZCRMUser noteModifiedBy = note.ModifiedBy;
Console.WriteLine(noteModifiedBy.Id); //To get UserId who modified the notes
Console.WriteLine(noteModifiedBy.FullName); //To get User name who modified the notes
ZCRMUser noteOwner = note.NotesOwner;
Console.WriteLine(noteOwner.Id); //To get notes OwnerId
Console.WriteLine(noteOwner.FullName); //To get notes Owner name
Console.WriteLine(note.CreatedTime); //To get created time of the note
Console.WriteLine(note.ModifiedTime); //To get modified time of the note
List<ZCRMAttachment> noteAttachment = note.Attachments; //To get attachments of the note record
if (noteAttachment != null) //check If attachments is empty/not
{
foreach (ZCRMAttachment attachment in noteAttachment)
{
Console.WriteLine(attachment.Id); //To get the note's attachment id
Console.WriteLine(attachment.FileName); //To get the note's attachment file name
Console.WriteLine(attachment.FileType); //To get the note's attachment file type
Console.WriteLine(attachment.Size); //To get the note's attachment file size
ZCRMRecord attachmentRecord = attachment.ParentRecord;
Console.WriteLine(attachmentRecord.EntityId); //To get the note's parent record id
Console.WriteLine(attachmentRecord.ModuleAPIName); //To get the record name
ZCRMUser noteAttachmentCreatedBy = note.CreatedBy;
Console.WriteLine(noteAttachmentCreatedBy.Id); // To get user_id who created the note's attachment
Console.WriteLine(noteAttachmentCreatedBy.FullName); //To get user name who created the note's attachment
ZCRMUser noteAttachmentModifiedBy = note.ModifiedBy;
Console.WriteLine(noteAttachmentModifiedBy.Id); //To get user_id who modified the note's attachment
Console.WriteLine(noteAttachmentModifiedBy.FullName); //To get user name who modified the note's attachment
ZCRMUser noteAttachmentOwner = note.NotesOwner;
Console.WriteLine(noteAttachmentOwner.Id); //To get the note's attachment owner id
Console.WriteLine(noteAttachmentOwner.FullName); //To get the note's attachment owner name
Console.WriteLine(attachment.CreatedTime); //To get attachment created time
Console.WriteLine(attachment.ModifiedTime); //To get attachment modified time
}
}
}
BulkAPIResponse<ZCRMAttachment> attachmentResponse = record.GetAttachments(); //To get record's attachments
//BulkAPIResponse<ZCRMAttachment> attachmentResponse = record.GetAttachments(0,10, "019-12-25T04:00:00+02:00"); //page, perPage and modifiedSince(Header)
List<ZCRMAttachment> attachments = attachmentResponse.BulkData; // To get list of attachments
foreach (ZCRMAttachment attachment in attachments)
{
Console.WriteLine(attachment.Id); //To get the attachment id
Console.WriteLine(attachment.FileName); //To get attachment file name
Console.WriteLine(attachment.FileType); // To get attachment file type
Console.WriteLine(attachment.Size); //To get attachment file size
ZCRMRecord attachmentRecord = attachment.ParentRecord;
Console.WriteLine(attachmentRecord.EntityId); //To get the parent record id
Console.WriteLine(attachmentRecord.ModuleAPIName); //To get the parent record name
ZCRMUser attachmentCreatedBy = attachment.CreatedBy;
Console.WriteLine(attachmentCreatedBy.Id); // To get user_id who created the attachment
Console.WriteLine(attachmentCreatedBy.FullName); //To get user name who created the attachment
ZCRMUser attachmentModifiedBy = attachment.ModifiedBy;
Console.WriteLine(attachmentModifiedBy.Id); //To get user_id who modified the attachment
Console.WriteLine(attachmentModifiedBy.FullName); //To get user name who modified the attachment
ZCRMUser noteAttachmentOwner = attachment.Owner;
Console.WriteLine(noteAttachmentOwner.Id); //To get the attachment owner id
Console.WriteLine(noteAttachmentOwner.FullName); //To get the attachment owner name
Console.WriteLine(attachment.CreatedTime); //To get attachment created time
Console.WriteLine(attachment.ModifiedTime); //To get attachment modified time
FileAPIResponse fResponse = attachment.DownloadFile(); //To download the attachment file
Console.WriteLine("File Name:" + fResponse.GetFileName()); // To get attachment file name
Console.WriteLine("HTTP Status Code:" + fResponse.HttpStatusCode); //To get HTTP status code
Stream file = fResponse.GetFileAsStream(); //To get attachment file content
CommonUtil.SaveStreamAsFile("/Users/Desktop/photo", file, fResponse.GetFileName()); //To write a new file using the same attachment name
}
ZCRMLayout layout = record.Layout; //To get record layout
if (layout != null)
{
Console.WriteLine(layout.Id); //To get layout_id
Console.WriteLine(layout.Name); //To get layout name
}
/** Following methods are being used only by Inventory modules */
List<ZCRMTax> taxlists = record.TaxList; //To get the tax list
foreach (ZCRMTax tax in taxlists)
{
Console.WriteLine(tax.TaxName); //To get tax name
Console.WriteLine(tax.Percentage); //To get tax percentage
Console.WriteLine(tax.Value); //To get tax value
}
List<ZCRMInventoryLineItem> lineItems = record.LineItems; //To get list of line_items
foreach (ZCRMInventoryLineItem lineItem in lineItems)
{
Console.WriteLine(lineItem.Id); //To get lineItem id
Console.WriteLine(lineItem.ListPrice); //To get lineItem list price
Console.WriteLine(lineItem.Quantity); //To get lineItem quantity
Console.WriteLine(lineItem.Description); //To get lineItem description
Console.WriteLine(lineItem.Total); //To get lineItem total amount
Console.WriteLine(lineItem.Discount); //To get lineItem discount
Console.WriteLine(lineItem.DiscountPercentage); //To get lineItem discount percentage
Console.WriteLine(lineItem.TotalAfterDiscount); //To get lineItem amount after discount
Console.WriteLine(lineItem.TaxAmount); //To get lineItem tax amount
Console.WriteLine(lineItem.NetTotal); //To get lineItem net total amount
Console.WriteLine(lineItem.UnitPrice); //To get lineItem unit price
Console.WriteLine(lineItem.Product.EntityId); //To get line_item product's entity id
Console.WriteLine(lineItem.Product.LookupLabel); //To get line_item product's lookup label
List<ZCRMTax> linetaxs = lineItem.LineTax; //To get list of line_tax in lineItem
foreach (ZCRMTax tax in linetaxs)
{
Console.WriteLine(tax.TaxName); //To get line tax name
Console.WriteLine(tax.Percentage); //To get line tax percentage
Console.WriteLine(tax.Value); //To get line tax value
}
}
List<ZCRMPriceBookPricing> pricedetails = record.PriceDetails; //To get the price details array
foreach (ZCRMPriceBookPricing pricedetail in pricedetails)
{
Console.WriteLine(pricedetail.Id); //To get the record's priceId
Console.WriteLine(pricedetail.ToRange); //To get the price detail record's to_range
Console.WriteLine(pricedetail.FromRange); //To get the price detail record's from_range
Console.WriteLine(pricedetail.Discount); //To get the price detail record's discount
}
/** End Inventory **/
/** Following method is used only by 'Events' module */
List<ZCRMEventParticipant> participants = record.Participants; //To get Event record's participants
foreach (ZCRMEventParticipant participant in participants)
{
Console.WriteLine(participant.Id); //To get the record's participant id
Console.WriteLine(participant.Name); //To get the record's participant name
Console.WriteLine(participant.Email);//To get the record's participant email
Console.WriteLine(participant.Type); //To get the record's participant type
Console.WriteLine(participant.IsInvited); //To check if the record's participant(s) are invited or not
Console.WriteLine(participant.Status); //To get the record's participants' status
}
/* End Event */
}
//Console.WriteLine("Headers"+response.GetResponseHeaders());
BulkAPIResponse<ZCRMRecord>.ResponseInfo info = response.Info;
Console.WriteLine(info.AllowedCount);
Console.WriteLine(info.MoreRecords);
Console.WriteLine(info.PageNo);
Console.WriteLine(info.PerPage);
Console.WriteLine(info.RecordCount);
Console.WriteLine("RemainingAPICountForThisDay " + response.GetResponseHeaders().AllowedAPICallsPerMinute);
Console.WriteLine("RemainingAPICountForThisWindow " + response.GetResponseHeaders().RemainingAPICountForThisWindow);
Console.WriteLine("RemainingTimeForThisWindowReset " + response.GetResponseHeaders().RemainingTimeForThisWindowReset);
}
Tags
Get Tags
/** Get list of tags */
public void GetTags()
{
ZCRMModule tags = ZCRMModule.GetInstance("Leads"); //to get the instance of the module
BulkAPIResponse<ZCRMTag> response = tags.GetTags();
Console.WriteLine(response.HttpStatusCode);
foreach (ZCRMTag tag in response.BulkData)
{
Console.WriteLine(tag.Id);
Console.WriteLine(tag.Name);
ZCRMUser CreatedBy = tag.CreatedBy;
Console.WriteLine(CreatedBy.Id);
Console.WriteLine(CreatedBy.FullName);
ZCRMUser ModifiedBy = tag.ModifiedBy;
Console.WriteLine(ModifiedBy.Id);
Console.WriteLine(ModifiedBy.FullName);
Console.WriteLine(tag.CreatedTime);
Console.WriteLine(tag.ModifiedTime);
}
BulkAPIResponse<ZCRMTag>.ResponseInfo info = response.Info;
Console.WriteLine(info.AllowedCount);
Console.WriteLine(info.MoreRecords);
Console.WriteLine(info.PageNo);
Console.WriteLine(info.PerPage);
Console.WriteLine(info.RecordCount);
}
Get Record Count of a Tag
/** Get Record count for a specific tag */
public void GetCount()
{
ZCRMModule tags = ZCRMModule.GetInstance("Leads");
APIResponse count = tags.GetTagCount(538518000000443601);
ZCRMTag tagcount = (ZCRMTag)count.Data;
Console.WriteLine(tagcount.Count);
}
Create Tags
/** Create New Tags */
public void CreateTags()
{
ZCRMModule tags = ZCRMModule.GetInstance("Leads");
ZCRMTag addtag;
List<ZCRMTag> listtag = new List<ZCRMTag>();
addtag = ZCRMTag.GetInstance();
addtag.Name = "tagname";
listtag.Add(addtag);
addtag = ZCRMTag.GetInstance();
addtag.Name = "tagname1";
listtag.Add(addtag);
BulkAPIResponse<ZCRMTag> response = tags.CreateTags(listtag);
Console.WriteLine(response.HttpStatusCode);
foreach (EntityResponse eResponse in response.BulkEntitiesResponse)
{
Console.WriteLine(eResponse.Message);
Console.WriteLine(eResponse.Status);
Console.WriteLine(eResponse.Code);
Console.WriteLine(eResponse.ErrorDetails);
Console.WriteLine(eResponse.ResponseJSON);
ZCRMTag tag1 = (ZCRMTag)eResponse.Data;
Console.WriteLine(tag1.Id);
Console.WriteLine(tag1.Name);
ZCRMUser CreatedBy = tag1.CreatedBy;
Console.WriteLine(CreatedBy.Id);
Console.WriteLine(CreatedBy.FullName);
ZCRMUser ModifiedBy = tag1.ModifiedBy;
Console.WriteLine(ModifiedBy.Id);
Console.WriteLine(ModifiedBy.FullName);
Console.WriteLine(tag1.CreatedTime);
Console.WriteLine(tag1.ModifiedTime);
}
}
Update Tags
/** Multiple Tag updates */
public void UpdateTags()
{
/** Multiple Tag updates */
ZCRMModule modulesIns = ZCRMModule.GetInstance("Leads");
List<ZCRMTag> tags = new List<ZCRMTag>();
ZCRMTag tag1 = ZCRMTag.GetInstance(3477061000000335002);
tag1.Name = "Name3";
ZCRMTag tag2 = ZCRMTag.GetInstance(3477061000000335001);
tag2.Name = "Name4";
tags.Add(tag1);
tags.Add(tag2);
BulkAPIResponse<ZCRMTag> response = modulesIns.UpdateTags(tags); //tags - list of ZCRMTag instances filled with required data for update.
Console.WriteLine(response.HttpStatusCode);
foreach (EntityResponse eResponse in response.BulkEntitiesResponse)
{
Console.WriteLine(eResponse.Message);
Console.WriteLine(eResponse.Status);
Console.WriteLine(eResponse.Code);
Console.WriteLine(eResponse.ErrorDetails);
Console.WriteLine(eResponse.ResponseJSON);
ZCRMTag tag = (ZCRMTag)eResponse.Data;
Console.WriteLine(tag.Id);
Console.WriteLine(tag.Name);
ZCRMUser createdBy = tag.CreatedBy;
Console.WriteLine(createdBy.Id);
Console.WriteLine(createdBy.FullName);
ZCRMUser modifiedBy = tag.ModifiedBy;
Console.WriteLine(modifiedBy.Id);
Console.WriteLine(modifiedBy.FullName);
Console.WriteLine(tag.CreatedTime);
Console.WriteLine(tag.ModifiedTime);
}
}
Add Tags to Records
/** Add Tags to Multiple records */
public void AddTagMultipleRecord()
{
ZCRMModule module = ZCRMModule.GetInstance("Leads");
List<string> tagname = new List<string>() { "N3", "N4" };
List<long> recordid = new List<long>() { 538518000000449064, 538518000000449036, 538518000000449026 };
BulkAPIResponse<ZCRMRecord> response = module.AddTagsToRecords(recordid, tagname);//recordIds list of record id, tagname list of tag names
Console.WriteLine(response.HttpStatusCode);
foreach (EntityResponse eResponse in response.BulkEntitiesResponse)
{
Console.WriteLine(eResponse.Message);
Console.WriteLine(eResponse.Status);
Console.WriteLine(eResponse.Code);
Console.WriteLine(eResponse.ErrorDetails);
Console.WriteLine(eResponse.ResponseJSON);
ZCRMRecord record = (ZCRMRecord)eResponse.Data;
Console.WriteLine(record.ModuleAPIName);
Console.WriteLine(record.EntityId);
foreach (string tagnames in record.TagNames)
{
Console.WriteLine(tagnames);
}
Console.WriteLine(record.Data);
}
}
Remove Tags from Records
/** Remove Tags from Multiple records */
public void RemoveTagMultipleRecord()
{
ZCRMModule module = ZCRMModule.GetInstance("Leads");
List<string> tagname = new List<string>() { "N3", "N4" };
List<long> recordid = new List<long>() { 538518000000449064, 538518000000449036, 538518000000449026 };
BulkAPIResponse<ZCRMRecord> response = module.RemoveTagsFromRecords(recordid, tagname);//recordIds list of record id, tagname list of tag names
Console.WriteLine(response.HttpStatusCode);
foreach (EntityResponse eResponse in response.BulkEntitiesResponse)
{
Console.WriteLine(eResponse.Message);
Console.WriteLine(eResponse.Status);
Console.WriteLine(eResponse.Code);
Console.WriteLine(eResponse.ErrorDetails);
Console.WriteLine(eResponse.ResponseJSON);
ZCRMRecord record = (ZCRMRecord)eResponse.Data;
Console.WriteLine(record.ModuleAPIName);
Console.WriteLine(record.EntityId);
foreach (string tagnames in record.TagNames)
{
Console.WriteLine(tagnames);
}
Console.WriteLine(record.Data);
}
}