private BulkAPIResponse <ZCRMRecord> SearchRecords(string searchKey, string searchValue, int page, int perPage)
        {
            requestMethod = APIConstants.RequestMethod.GET;
            urlPath       = module.ApiName + "/search";
            requestQueryParams.Add(searchKey, searchValue);
            requestQueryParams.Add(APIConstants.PAGE, page.ToString());
            requestQueryParams.Add(APIConstants.PER_PAGE, perPage.ToString());

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            BulkAPIResponse <ZCRMRecord> response = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMRecord>();

            List <ZCRMRecord> recordsList  = new List <ZCRMRecord>();
            JObject           responseJSON = response.ResponseJSON;

            if (responseJSON.ContainsKey(APIConstants.DATA))
            {
                JArray recordsArray = (JArray)responseJSON[APIConstants.DATA];
                foreach (JObject recordDetails in recordsArray)
                {
                    ZCRMRecord record = ZCRMRecord.GetInstance(module.ApiName, Convert.ToInt64(recordDetails["id"]));
                    EntityAPIHandler.GetInstance(record).SetRecordProperties(recordDetails);
                    recordsList.Add(record);
                }
            }
            response.BulkData = recordsList;
            return(response);
        }
Esempio n. 2
0
        public ZCRMInventoryLineItem GetZCRMInventoryLineItem(JObject lineItemJSON)
        {
            JObject productDetails         = (JObject)lineItemJSON["product"];
            long    lineItemId             = Convert.ToInt64(lineItemJSON["id"]);
            ZCRMInventoryLineItem lineItem = ZCRMInventoryLineItem.GetInstance(lineItemId);

            ZCRMRecord product = ZCRMRecord.GetInstance("Products", Convert.ToInt64(productDetails["id"]));

            product.LookupLabel         = (string)productDetails["name"];
            lineItem.Product            = product;
            lineItem.Description        = (string)lineItemJSON["product_description"];
            lineItem.Quantity           = Convert.ToDouble(lineItemJSON["quantity"]);
            lineItem.ListPrice          = Convert.ToDouble(lineItemJSON["list_price"]);
            lineItem.UnitPrice          = Convert.ToDouble(lineItemJSON["unit_price"]);
            lineItem.Total              = Convert.ToDouble(lineItemJSON["total"]);
            lineItem.Discount           = Convert.ToDouble(lineItemJSON["Discount"]);
            lineItem.TotalAfterDiscount = Convert.ToDouble(lineItemJSON["tota_after_discount"]);
            lineItem.TaxAmount          = Convert.ToDouble(lineItemJSON["Tax"]);
            JArray lineTaxes = (JArray)lineItemJSON["line_tax"];

            foreach (JObject lineTax in lineTaxes)
            {
                ZCRMTax tax = ZCRMTax.GetInstance((string)lineTax["name"]);
                tax.Percentage = Convert.ToDouble(lineTax["percentage"]);
                tax.Value      = Convert.ToDouble(lineTax["value"]);
                lineItem.AddLineTax(tax);
            }
            lineItem.NetTotal = Convert.ToDouble(lineItemJSON["net_total"]);
            return(lineItem);
        }
        public BulkAPIResponse <ZCRMRecord> GetRecords(long?cvId, string sortByField, CommonUtil.SortOrder?sortOrder, int page, int perPage, string modifiedSince, string isConverted, string isApproved, List <string> fields)
        {
            requestMethod = APIConstants.RequestMethod.GET;
            urlPath       = module.ApiName;
            if (cvId != null)
            {
                requestQueryParams.Add("cvid", cvId.ToString());
            }
            if (sortByField != null)
            {
                requestQueryParams.Add("sort_by", sortByField);
            }
            if (sortOrder != null)
            {
                requestQueryParams.Add("sort_order", sortOrder.ToString());
            }
            requestQueryParams.Add(APIConstants.PAGE, page.ToString());
            requestQueryParams.Add(APIConstants.PER_PAGE, perPage.ToString());
            if (isApproved != null && isApproved != "")
            {
                requestQueryParams.Add("approved", isApproved);
            }
            if (isConverted != null && isConverted != "")
            {
                requestQueryParams.Add("converted", isConverted);
            }
            if (fields != null)
            {
                requestQueryParams.Add("fields", CommonUtil.CollectionToCommaDelimitedString(fields));
            }
            if (modifiedSince != null && modifiedSince != "")
            {
                requestHeaders.Add("If-Modified-Since", modifiedSince);
            }

            BulkAPIResponse <ZCRMRecord> response = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMRecord>();

            List <ZCRMRecord> records      = new List <ZCRMRecord>();
            JObject           responseJSON = response.ResponseJSON;

            if (responseJSON.ContainsKey(APIConstants.DATA))
            {
                JArray recordsArray = (JArray)responseJSON[APIConstants.DATA];
                foreach (JObject recordDetails in recordsArray)
                {
                    ZCRMRecord record = ZCRMRecord.GetInstance(module.ApiName, Convert.ToInt64(recordDetails["id"]));
                    EntityAPIHandler.GetInstance(record).SetRecordProperties(recordDetails);
                    records.Add(record);
                }
            }
            response.BulkData = records;
            return(response);
        }
Esempio n. 4
0
 public BulkAPIResponse <ZCRMRecord> RemoveTagsFromRecords(List <long> recordId, List <string> tagNames)
 {
     if (tagNames.Count > 10)
     {
         throw new ZCRMException(APIConstants.API_MAX_RECORD_TAGS_MSG);
     }
     if (recordId.Count > 100)
     {
         throw new ZCRMException(APIConstants.API_MAX_RECORDS_MSG);
     }
     try
     {
         string tagname = "", recordid = "";
         requestMethod = APIConstants.RequestMethod.POST;
         foreach (long id in recordId)
         {
             recordid += id + ",";
         }
         foreach (string tag in tagNames)
         {
             tagname += tag + ",";
         }
         urlPath = "" + module.ApiName + "/actions/remove_tags?ids=" + recordid + "&tag_names=" + tagname + "";
         BulkAPIResponse <ZCRMRecord> response = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMRecord>();
         List <ZCRMRecord>            removetags = new List <ZCRMRecord>();
         List <EntityResponse>        responses = response.BulkEntitiesResponse;
         foreach (EntityResponse entityResponse in responses)
         {
             if (entityResponse.Status.Equals(APIConstants.CODE_SUCCESS))
             {
                 JObject    responseData = entityResponse.ResponseJSON;
                 JObject    tagDetails   = (JObject)responseData[APIConstants.DETAILS];
                 ZCRMRecord removeTag    = ZCRMRecord.GetInstance(module.ApiName, Convert.ToInt64(tagDetails["id"]));
                 EntityAPIHandler.GetInstance(removeTag).SetRecordProperties(tagDetails);
                 removetags.Add(removeTag);
                 entityResponse.Data = removeTag;
             }
             else
             {
                 entityResponse.Data = null;
             }
         }
         response.BulkData = removetags;
         return(response);
     }
     catch (Exception e) when(!(e is ZCRMException))
     {
         ZCRMLogger.LogError(e);
         throw new ZCRMException(APIConstants.SDK_ERROR, e);
     }
 }
        public BulkAPIResponse <ZCRMRecord> MassUpdateRecords(List <long> entityIds, string fieldAPIName, Object value)
        {
            if (entityIds.Count > 100)
            {
                throw new ZCRMException(APIConstants.API_MAX_RECORDS_MSG);
            }
            //NOTE: null value is not converted to JObject of type null;
            requestMethod = APIConstants.RequestMethod.PUT;
            urlPath       = module.ApiName;
            JObject requestBodyObject = new JObject();
            JArray  dataArray         = new JArray();

            foreach (long id in entityIds)
            {
                JObject updateJSON = new JObject
                {
                    { fieldAPIName, value.ToString() },
                    { "id", Convert.ToString(id) }
                };
                dataArray.Add(updateJSON);
            }
            requestBodyObject.Add(APIConstants.DATA, dataArray);
            requestBody = requestBodyObject;

            BulkAPIResponse <ZCRMRecord> response = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMRecord>();

            List <ZCRMRecord>     updatedRecords = new List <ZCRMRecord>();
            List <EntityResponse> responses      = response.BulkEntitiesResponse;

            foreach (EntityResponse entityResponse in responses)
            {
                if (entityResponse.Status.Equals(APIConstants.CODE_SUCCESS))
                {
                    JObject    responseData  = entityResponse.ResponseJSON;
                    JObject    recordDetails = (JObject)responseData[APIConstants.DETAILS];
                    ZCRMRecord updatedRecord = ZCRMRecord.GetInstance(module.ApiName, Convert.ToInt64(recordDetails["id"]));
                    EntityAPIHandler.GetInstance(updatedRecord).SetRecordProperties(recordDetails);
                    updatedRecords.Add(updatedRecord);
                    entityResponse.Data = updatedRecord;
                }
                else
                {
                    entityResponse.Data = null;
                }
            }
            response.BulkData = updatedRecords;
            return(response);
        }
        public BulkAPIResponse <ZCRMRecord> GetRecords(string sortByField, CommonUtil.SortOrder?sortOrder, int page, int perPage, string modifiedSince)
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.GET;
                urlPath       = parentRecord.ModuleAPIName + "/" + parentRecord.EntityId + "/" + relatedList.ApiName;
                if (sortByField != null)
                {
                    requestQueryParams.Add("sort_by", sortByField);
                }
                if (sortOrder != null)
                {
                    requestQueryParams.Add("sort_order", sortOrder.ToString());
                }
                requestQueryParams.Add(APIConstants.PAGE, page.ToString());
                requestQueryParams.Add(APIConstants.PER_PAGE, perPage.ToString());
                if (modifiedSince != null && modifiedSince != "")
                {
                    requestHeaders.Add("If-Modified-Since", modifiedSince);
                }

                BulkAPIResponse <ZCRMRecord> response = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMRecord>();

                List <ZCRMRecord> recordsList  = new List <ZCRMRecord>();
                JObject           responseJSON = response.ResponseJSON;
                if (responseJSON.ContainsKey(APIConstants.DATA))
                {
                    JArray recordsArray = (JArray)responseJSON[APIConstants.DATA];
                    foreach (JObject recordDetails in recordsArray)
                    {
                        ZCRMRecord record = ZCRMRecord.GetInstance(relatedList.ApiName, Convert.ToInt64(recordDetails["id"]));
                        EntityAPIHandler.GetInstance(record).SetRecordProperties(recordDetails);
                        recordsList.Add(record);
                    }
                }
                response.BulkData = recordsList;
                return(response);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);
                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
        public BulkAPIResponse <ZCRMEntity> DeleteRecords(List <long> entityIds)
        {
            if (entityIds.Count > 100)
            {
                throw new ZCRMException(APIConstants.API_MAX_RECORDS_MSG);
            }
            requestMethod = APIConstants.RequestMethod.DELETE;
            urlPath       = module.ApiName;
            requestQueryParams.Add("ids", CommonUtil.CollectionToCommaDelimitedString(entityIds));

            BulkAPIResponse <ZCRMEntity> response = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMEntity>();

            List <EntityResponse> responses = response.BulkEntitiesResponse;

            foreach (EntityResponse entityResponse in responses)
            {
                JObject    entityResponseJSON = entityResponse.ResponseJSON;
                JObject    recordJSON         = (JObject)entityResponseJSON[APIConstants.DETAILS];
                ZCRMRecord record             = ZCRMRecord.GetInstance(module.ApiName, Convert.ToInt64(recordJSON["id"]));
                entityResponse.Data = record;
            }
            return(response);
        }
Esempio n. 8
0
 /// <summary>
 /// To delete the attachment of the notes based on attachment Id.
 /// </summary>
 /// <returns>APIResponse class instance.</returns>
 /// <param name="attachmentId">Attachment Id (Long) of the notes</param>
 public APIResponse DeleteAttachment(long attachmentId)
 {
     return(ZCRMModuleRelation.GetInstance(ZCRMRecord.GetInstance("Notes", id), "Attachments").DeleteAttachment(attachmentId));
 }
Esempio n. 9
0
 /// <summary>
 /// To upload the attachment of the notes based on file path.
 /// </summary>
 /// <returns>APIResponse class instance.</returns>
 /// <param name="filePath">File path (String) of the note attachment</param>
 public APIResponse UploadAttachment(string filePath)
 {
     return(ZCRMModuleRelation.GetInstance(ZCRMRecord.GetInstance("Notes", id), "Attachments").UploadAttachment(filePath));
 }
Esempio n. 10
0
        public void SetRecordProperties(JObject recordJSON, ZCRMRecord record)
        {
            foreach (KeyValuePair <string, JToken> token in recordJSON)
            {
                string fieldAPIName = token.Key;
                if (fieldAPIName.Equals("id"))
                {
                    record.EntityId = Convert.ToInt64(token.Value);
                }
                else if (fieldAPIName.Equals("Product_Details"))
                {
                    SetInventoryLineItems(token.Value);
                }
                else if (fieldAPIName.Equals("Participants"))
                {
                    SetParticipants(token.Value);
                }
                else if (fieldAPIName.Equals("Pricing_Details"))
                {
                    SetPriceDetails((JArray)token.Value);
                }
                else if (fieldAPIName.Equals("Created_By") && token.Value.Type != JTokenType.Null)
                {
                    JObject  createdObject = (JObject)token.Value;
                    ZCRMUser createdUser   = ZCRMUser.GetInstance(Convert.ToInt64(createdObject["id"]), (string)createdObject["name"]);
                    record.CreatedBy = createdUser;
                }
                else if (fieldAPIName.Equals("Modified_By") && token.Value.Type != JTokenType.Null)
                {
                    JObject  modifiedObject = (JObject)token.Value;
                    ZCRMUser modifiedBy     = ZCRMUser.GetInstance(Convert.ToInt64(modifiedObject["id"]), (string)modifiedObject["name"]);
                    record.ModifiedBy = modifiedBy;
                }
                else if (fieldAPIName.Equals("Created_Time"))
                {
                    record.CreatedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(token.Value));
                }
                else if (fieldAPIName.Equals("Modified_Time"))
                {
                    record.ModifiedTime = CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(token.Value));
                }
                else if (fieldAPIName.Equals("Owner") && token.Value.Type != JTokenType.Null)
                {
                    JObject  ownerObject = (JObject)token.Value;
                    ZCRMUser ownerUser   = ZCRMUser.GetInstance(Convert.ToInt64(ownerObject["id"]), (string)ownerObject["name"]);
                    record.Owner = ownerUser;
                }
                else if (fieldAPIName.Equals("Layout") && token.Value.Type != JTokenType.Null)
                {
                    JObject    layoutObject = (JObject)token.Value;
                    ZCRMLayout layout       = ZCRMLayout.GetInstance(Convert.ToInt64(layoutObject["id"]));
                    layout.Name = (string)layoutObject["name"];
                }
                else if (fieldAPIName.Equals("Handler") && token.Value.Type != JTokenType.Null)
                {
                    JObject  handlerObject = (JObject)token.Value;
                    ZCRMUser handler       = ZCRMUser.GetInstance(Convert.ToInt64(handlerObject["id"]), (string)handlerObject["name"]);
                    record.SetFieldValue(fieldAPIName, handler);
                }

                else if (fieldAPIName.Equals("Remind_At") && token.Value.Type != JTokenType.Null)
                {
                    if (token.Value is JObject)
                    {
                        JObject remindObject = (JObject)token.Value;
                        record.SetFieldValue(fieldAPIName, remindObject["ALARM"]);
                    }
                    else
                    {
                        record.SetFieldValue(fieldAPIName, token.Value);
                    }
                }
                else if (fieldAPIName.Equals("Recurring_Activity") && token.Value.Type != JTokenType.Null)
                {
                    JObject recurringActivityObject = (JObject)token.Value;
                    record.SetFieldValue(fieldAPIName, recurringActivityObject["RRULE"]);
                }
                else if (fieldAPIName.Equals("$line_tax") && token.Value.Type != JTokenType.Null)
                {
                    JArray taxDetails = (JArray)token.Value;
                    foreach (JObject taxDetail in taxDetails)
                    {
                        ZCRMTax tax = ZCRMTax.GetInstance((string)taxDetail["name"]);
                        tax.Percentage = Convert.ToDouble(taxDetail["percentage"]);
                        tax.Value      = Convert.ToDouble(taxDetail["value"]);
                        record.AddTax(tax);
                    }
                }
                else if (fieldAPIName.Equals("Tax") && token.Value.Type != JTokenType.Null)
                {
                    var taxNames = token.Value;
                    foreach (string data in taxNames)
                    {
                        ZCRMTax tax = ZCRMTax.GetInstance(data);
                        record.AddTax(tax);
                    }
                }
                else if (fieldAPIName.Equals("tags") && token.Value.Type != JTokenType.Null)
                {
                    JArray        jsonArray = (JArray)token.Value;
                    List <string> tags      = new List <string>();
                    foreach (string tag in jsonArray)
                    {
                        tags.Add(tag);
                    }
                    record.TagNames = tags;
                }
                else if (fieldAPIName.Equals("Tag") && token.Value.Type != JTokenType.Null)
                {
                    JArray jsonArray = (JArray)token.Value;
                    foreach (JObject tag in jsonArray)
                    {
                        ZCRMTag tagIns = ZCRMTag.GetInstance(Convert.ToInt64(tag.GetValue("id")));
                        tagIns.Name = tag.GetValue("name").ToString();
                        record.Tags.Add(tagIns);
                    }
                }
                else if (fieldAPIName.StartsWith("$", StringComparison.CurrentCulture))
                {
                    fieldAPIName = fieldAPIName.TrimStart('\\', '$');
                    if (APIConstants.PROPERTIES_AS_FILEDS.Contains(fieldAPIName))
                    {
                        record.SetFieldValue(fieldAPIName, token.Value);
                    }
                    else
                    {
                        record.SetProperty(fieldAPIName, token.Value);
                    }
                }
                else if (token.Value is JObject)
                {
                    JObject    lookupDetails = (JObject)token.Value;
                    ZCRMRecord lookupRecord  = ZCRMRecord.GetInstance(fieldAPIName, Convert.ToInt64(lookupDetails["id"]));
                    lookupRecord.LookupLabel = (string)lookupDetails["name"];
                    record.SetFieldValue(fieldAPIName, lookupRecord);
                }
                else if (token.Value is JArray)
                {
                    JArray        jsonArray = (JArray)token.Value;
                    List <object> values    = new List <object>();

                    foreach (Object obj in jsonArray)
                    {
                        if (obj is JObject)
                        {
                            values.Add((JObject)obj);
                        }
                        else
                        {
                            values.Add(obj);
                        }
                    }
                    record.SetFieldValue(fieldAPIName, values);
                }
                else
                {
                    if (token.Value.Type.ToString().Equals("Date"))
                    {
                        record.SetFieldValue(fieldAPIName, CommonUtil.removeEscaping((string)JsonConvert.SerializeObject(token.Value)));
                    }
                    else
                    {
                        record.SetFieldValue(fieldAPIName, token.Value);
                    }
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// To get the record based on record Id of the module.
        /// </summary>
        /// <returns>APIResponse class instance.</returns>
        /// <param name="entityId">Entity(record) Id (Long) of the module</param>
        public APIResponse GetRecord(long entityId)
        {
            ZCRMRecord record = ZCRMRecord.GetInstance(ApiName, entityId);

            return(EntityAPIHandler.GetInstance(record).GetRecord());
        }
Esempio n. 12
0
 /// <summary>
 /// To get ZohoCRM record instance by passing module API name and entity(record) Id.
 /// </summary>
 /// <returns>ZCRMRecord class instance.</returns>
 /// <param name="moduleAPIName">modules' API name (String)</param>
 /// <param name="entityId">entity(record) Id (Long)</param>
 public ZCRMRecord GetRecordInstance(string moduleAPIName, long entityId)
 {
     return(ZCRMRecord.GetInstance(moduleAPIName, entityId));
 }