Exemplo n.º 1
0
        public APIResponse UpdateNote(ZCRMNote note)
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.PUT;
                urlPath       = parentRecord.ModuleAPIName + "/" + parentRecord.EntityId + "/" + relatedList.ApiName + "/" + note.Id;
                JObject requestBodyObject = new JObject();
                JArray  dataArray         = new JArray();
                dataArray.Add(GetZCRMNoteAsJSON(note));
                requestBodyObject.Add(APIConstants.DATA, dataArray);
                requestBody = requestBodyObject;


                APIResponse response = APIRequest.GetInstance(this).GetAPIResponse();

                JArray  responseDataArray = (JArray)response.ResponseJSON[APIConstants.DATA];
                JObject responseData      = (JObject)responseDataArray[0];
                JObject responseDetails   = (JObject)responseData[APIConstants.DETAILS];
                note          = GetZCRMNote(responseDetails, note);
                response.Data = note;
                return(response);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);
                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
Exemplo n.º 2
0
        public BulkAPIResponse <ZCRMAttachment> GetAttachments(int page, int perPage, string modifiedSince)
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.GET;
                urlPath       = parentRecord.ModuleAPIName + "/" + parentRecord.EntityId + "/" + relatedList.ApiName;
                requestQueryParams.Add(APIConstants.PAGE, page.ToString());
                requestQueryParams.Add(APIConstants.PER_PAGE, perPage.ToString());
                if (modifiedSince != null && modifiedSince != "")
                {
                    requestHeaders.Add("If-Modified-Since", modifiedSince);
                }

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

                List <ZCRMAttachment> allAttachments = new List <ZCRMAttachment>();
                JObject responseJSON = response.ResponseJSON;
                if (responseJSON.ContainsKey(APIConstants.DATA))
                {
                    JArray attachmentsArray = (JArray)responseJSON[APIConstants.DATA];
                    foreach (JObject attachmentDetails in attachmentsArray)
                    {
                        allAttachments.Add(GetZCRMAttachment(attachmentDetails));
                    }
                }
                response.BulkData = allAttachments;
                return(response);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);
                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
 public APIResponse RemoveTags(ZCRMRecord record, List <string> tagNames)
 {
     if (tagNames.Count > 10)
     {
         throw new ZCRMException(APIConstants.API_MAX_RECORD_TAGS_MSG);
     }
     try
     {
         string tagname = "";
         requestMethod = APIConstants.RequestMethod.POST;
         foreach (string name in tagNames)
         {
             tagname += name + ",";
         }
         urlPath = "" + record.ModuleAPIName + "/" + record.EntityId + "/actions/remove_tags?tag_names=" + tagname + "";
         APIResponse response          = APIRequest.GetInstance(this).GetAPIResponse();
         JArray      responseDataArray = (JArray)response.ResponseJSON[APIConstants.DATA];
         JObject     responseData      = (JObject)responseDataArray[0];
         JObject     recordDetails     = (JObject)responseData[APIConstants.DETAILS];
         ZCRMRecord  tag = record;
         EntityAPIHandler.GetInstance(tag).SetRecordProperties(recordDetails);
         response.Data = tag;
         return(response);
     }
     catch (Exception e) when(!(e is ZCRMException))
     {
         ZCRMLogger.LogError(e);
         throw new ZCRMException(APIConstants.SDK_ERROR, e);
     }
 }
Exemplo n.º 4
0
        public APIResponse GetRecord()
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.GET;

                urlPath = record.ModuleAPIName + "/" + record.EntityId;

                APIResponse response = APIRequest.GetInstance(this).GetAPIResponse();

                JArray responseDataArray = (JArray)response.ResponseJSON[APIConstants.DATA];

                JObject recordDetails = (JObject)responseDataArray[0];

                SetRecordProperties(recordDetails);

                response.Data = record;

                return(response);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);

                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
        public APIResponse Update(ZCRMTag tag)
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.PUT;
                urlPath       = "settings/tags/" + tag.Id + "?module=" + tag.ModuleApiName;

                JObject requestBodyObject = new JObject();
                JArray  dataArray         = new JArray();
                JObject TagJSON           = new JObject();
                TagJSON.Add("name", tag.Name);
                dataArray.Add(TagJSON);
                requestBodyObject.Add(APIConstants.TAGS, dataArray);
                requestBody = requestBodyObject;

                APIResponse response          = APIRequest.GetInstance(this).GetAPIResponse();
                JArray      responseDataArray = (JArray)response.ResponseJSON[APIConstants.TAGS];
                JObject     responseData      = (JObject)responseDataArray[0];
                JObject     tagDetails        = (JObject)responseData[APIConstants.DETAILS];
                ZCRMTag     updatetag         = tag;
                SetTagProperties(updatetag, tagDetails);
                response.Data = updatetag;
                return(response);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);
                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
 public BulkAPIResponse <ZCRMTag> GetTags()
 {
     try
     {
         requestMethod = APIConstants.RequestMethod.GET;
         urlPath       = "settings/tags?module=" + module.ApiName + "";
         BulkAPIResponse <ZCRMTag> response = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMTag>();
         List <ZCRMTag>            tags     = new List <ZCRMTag>();
         JObject responseJSON = response.ResponseJSON;
         if (responseJSON.ContainsKey(APIConstants.TAGS))
         {
             JArray tagsArray = (JArray)responseJSON[APIConstants.TAGS];
             foreach (JObject tagDetails in tagsArray)
             {
                 ZCRMTag tag = ZCRMTag.GetInstance(Convert.ToInt64(tagDetails["id"]));
                 SetTagProperties(tag, tagDetails);
                 tags.Add(tag);
             }
         }
         response.BulkData = tags;
         return(response);
     }
     catch (Exception e) when((e is ZCRMException))
     {
         ZCRMLogger.LogError(e);
         throw new ZCRMException(APIConstants.SDK_ERROR, e);
     }
 }
        public APIResponse DeleteRelation()
        {
            requestMethod = APIConstants.RequestMethod.DELETE;
            urlPath       = parentRecord.ModuleAPIName + "/" + parentRecord.EntityId + "/" + junctionRecord.ApiName + "/" + junctionRecord.Id;

            return(APIRequest.GetInstance(this).GetAPIResponse());
        }
Exemplo n.º 8
0
        public BulkAPIResponse <ZCRMProfile> GetAllProfiles()
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.GET;
                urlPath       = "settings/profiles";

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

                List <ZCRMProfile> allProfiles   = new List <ZCRMProfile>();
                JObject            responseJSON  = response.ResponseJSON;
                JArray             profilesArray = (JArray)responseJSON["profiles"];
                foreach (JObject profileDetails in profilesArray)
                {
                    allProfiles.Add(GetZCRMProfile(profileDetails));
                }
                response.BulkData = allProfiles;
                return(response);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);
                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
Exemplo n.º 9
0
        public BulkAPIResponse <ZCRMModule> GetAllModules(string modifiedSince)
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.GET;
                urlPath       = "settings/modules";
                if (!string.IsNullOrEmpty(modifiedSince))
                {
                    requestHeaders.Add("If-Modified-Since", modifiedSince);
                }

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

                JObject           responseJSON = response.ResponseJSON;
                List <ZCRMModule> allModules   = new List <ZCRMModule>();

                if (responseJSON.ContainsKey("modules"))
                {
                    JArray modulesArray = (JArray)responseJSON["modules"];
                    foreach (JObject moduleDetails in modulesArray)
                    {
                        allModules.Add(GetZCRMModule(moduleDetails));
                    }
                    response.BulkData = allModules;
                }
                return(response);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);
                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
        public FileAPIResponse DownloadAttachment(long attachmentId)
        {
            requestMethod = APIConstants.RequestMethod.GET;
            urlPath       = parentRecord.ModuleAPIName + "/" + parentRecord.EntityId + "/" + relatedList.ApiName + "/" + attachmentId;

            return(APIRequest.GetInstance(this).DownloadFile());
        }
Exemplo n.º 11
0
        public BulkAPIResponse <ZCRMModule> GetAllModules(string modifiedSince)
        {
            requestMethod = APIConstants.RequestMethod.GET;
            urlPath       = "settings/modules";
            if (modifiedSince != null && modifiedSince != "")
            {
                requestHeaders.Add("If-Modified-Since", modifiedSince);
            }

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

            JObject           responseJSON = response.ResponseJSON;
            List <ZCRMModule> allModules   = new List <ZCRMModule>();

            if (responseJSON.ContainsKey("modules"))
            {
                JArray modulesArray = (JArray)responseJSON["modules"];
                foreach (JObject moduleDetails in modulesArray)
                {
                    allModules.Add(GetZCRMModule(moduleDetails));
                }
                response.BulkData = allModules;
            }
            return(response);
        }
Exemplo n.º 12
0
        //TOOD: Handle exceptions;
        public APIResponse GetUser(long?userId)
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.GET;
                if (userId != null)
                {
                    urlPath = "users/" + userId;
                }
                else
                {
                    urlPath = "users";
                    requestQueryParams.Add("type", "CurrentUser");
                }

                APIResponse response = APIRequest.GetInstance(this).GetAPIResponse();

                JArray usersArray = (JArray)response.ResponseJSON["users"];
                response.Data = GetZCRMUser((JObject)usersArray[0]);

                return(response);
            }
            catch (Exception e)
            {
                //TODO: Log the exceptions;

                Console.WriteLine("exception in GetUser");
                Console.WriteLine(e);
                throw new ZCRMException("ZCRM_INTERNAL_ERROR");
            }
        }
Exemplo n.º 13
0
        public BulkAPIResponse <ZCRMOrgTax> UpdateTaxes(List <ZCRMOrgTax> taxes)
        {
            if (taxes.Count > 100)
            {
                throw new ZCRMException("Cannot process more than 100 records at a time");
            }
            try
            {
                requestMethod = APIConstants.RequestMethod.POST;
                urlPath       = "org/taxes";
                JObject requestBodyObject = new JObject();
                JArray  dataArray         = new JArray();
                foreach (ZCRMOrgTax tax in taxes)
                {
                    dataArray.Add(GetZCRMOrgTaxAsJSON(tax));
                }
                requestBodyObject.Add("taxes", dataArray);
                requestBody = requestBodyObject;

                return(APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMOrgTax>());
            }
            catch (Exception e)
            {
                //TODO: Handle exceptions and log the exceptions;
                Console.WriteLine("Exception in  UpdateTaxes");
                Console.WriteLine(e);
                throw new ZCRMException("ZCRM_INTERNAL_ERROR");
            }
        }
Exemplo n.º 14
0
        public BulkAPIResponse <ZCRMProfile> GetAllProfiles()
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.GET;
                urlPath       = "settings/profiles";

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

                List <ZCRMProfile> allProfiles   = new List <ZCRMProfile>();
                JObject            responseJSON  = response.ResponseJSON;
                JArray             profilesArray = (JArray)responseJSON["profiles"];
                foreach (JObject profileDetails in profilesArray)
                {
                    allProfiles.Add(GetZCRMProfile(profileDetails));
                }
                response.BulkData = allProfiles;
                return(response);
            }
            catch (Exception e)
            {
                //TODO: Handle exceptions and log the exceptions;
                Console.WriteLine("Exception in GetAllProfiles");
                Console.WriteLine(e);
                throw new ZCRMException("ZCRM_INTERNAL_ERROR");
            }
        }
Exemplo n.º 15
0
        public APIResponse Merge(long?tagId, long?mergetagId)
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.POST;
                urlPath       = "settings/tags/" + mergetagId + "/actions/merge";

                JObject requestBodyObject = new JObject();
                JArray  dataArray         = new JArray();
                JObject TagJSON           = new JObject();
                TagJSON.Add("conflict_id", tagId);
                dataArray.Add(TagJSON);
                requestBodyObject.Add(APIConstants.TAGS, dataArray);
                requestBody = requestBodyObject;

                APIResponse response          = APIRequest.GetInstance(this).GetAPIResponse();
                JArray      responseDataArray = (JArray)response.ResponseJSON[APIConstants.TAGS];
                JObject     responseData      = (JObject)responseDataArray[0];
                JObject     tagDetails        = (JObject)responseData[APIConstants.DETAILS];
                ZCRMTag     mergetag          = ZCRMTag.GetInstance(Convert.ToInt64(tagDetails["id"]));
                SetTagProperties(mergetag, tagDetails);
                response.Data = mergetag;
                return(response);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);
                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
Exemplo n.º 16
0
        private BulkAPIResponse <ZCRMUser> GetUsers(string type, string modifiedSince, int page, int perPage)
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.GET;
                urlPath       = "users";
                requestQueryParams.Add("type", type);
                requestQueryParams.Add(APIConstants.PAGE, page.ToString());
                requestQueryParams.Add(APIConstants.PER_PAGE, perPage.ToString());
                if (modifiedSince != null && modifiedSince != "")
                {
                    requestHeaders.Add("If-Modified-Since", modifiedSince);
                }

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

                List <ZCRMUser> allUsers     = new List <ZCRMUser>();
                JObject         responseJSON = response.ResponseJSON;
                if (responseJSON.ContainsKey("users"))
                {
                    JArray usersArray = (JArray)responseJSON["users"];
                    foreach (JObject userJSON in usersArray)
                    {
                        allUsers.Add(GetZCRMUser(userJSON));
                    }
                }
                response.BulkData = allUsers;
                return(response);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);
                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
Exemplo n.º 17
0
        public APIResponse GetUser(long?userId)
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.GET;
                if (userId != null)
                {
                    urlPath = "users/" + userId;
                }
                else
                {
                    urlPath = "users";
                    requestQueryParams.Add("type", "CurrentUser");
                }

                APIResponse response = APIRequest.GetInstance(this).GetAPIResponse();

                JArray usersArray = (JArray)response.ResponseJSON["users"];
                response.Data = GetZCRMUser((JObject)usersArray[0]);

                return(response);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);
                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
Exemplo n.º 18
0
        //TODO: Handle exceptions for all the below functions;
        private BulkAPIResponse <ZCRMUser> GetUsers(string type, string modifiedSince, int page, int perPage)
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.GET;
                urlPath       = "users";
                requestQueryParams.Add("type", type);
                requestQueryParams.Add("page", page.ToString());
                requestQueryParams.Add("per_page", perPage.ToString());
                requestHeaders.Add("If-Modified-Since", modifiedSince);

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

                List <ZCRMUser> allUsers     = new List <ZCRMUser>();
                JObject         responseJSON = response.ResponseJSON;
                JArray          usersArray   = (JArray)responseJSON["users"];
                foreach (JObject userJSON in usersArray)
                {
                    allUsers.Add(GetZCRMUser(userJSON));
                }
                response.BulkData = allUsers;
                return(response);
            }
            catch (Exception e)
            {
                //TODO: Handle exceptions;
                Console.WriteLine("Exception at GetUsers");
                Console.WriteLine(e);
                throw new ZCRMException("ZCRM_INTERNAL_ERROR");
            }
        }
        public BulkAPIResponse <ZCRMRecord> CreateRecords(List <ZCRMRecord> records, List <string> trigger, string lar_id)
        {
            if (records.Count > 100)
            {
                throw new ZCRMException(APIConstants.API_MAX_RECORDS_MSG);
            }
            requestMethod = APIConstants.RequestMethod.POST;
            urlPath       = module.ApiName;
            JObject requestBodyObject = new JObject();
            JArray  dataArray         = new JArray();

            foreach (ZCRMRecord record in records)
            {
                if (record.EntityId == null)
                {
                    dataArray.Add(EntityAPIHandler.GetInstance(record).GetZCRMRecordAsJSON());
                }
                else
                {
                    throw new ZCRMException("Entity ID Must be null/empty for CreateRecords operation.");
                }
            }
            requestBodyObject.Add(APIConstants.DATA, dataArray);
            if (trigger != null && trigger.Count > 0)
            {
                requestBodyObject.Add("trigger", JArray.FromObject(trigger));
            }
            if (lar_id != null)
            {
                requestBodyObject.Add("lar_id", lar_id);
            }
            requestBody = requestBodyObject;

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

            List <ZCRMRecord>     createdRecords = new List <ZCRMRecord>();
            List <EntityResponse> responses      = response.BulkEntitiesResponse;
            int responseSize = responses.Count;

            for (int i = 0; i < responseSize; i++)
            {
                EntityResponse entityResponse = responses[i];
                if (entityResponse.Status.Equals(APIConstants.CODE_SUCCESS))
                {
                    JObject    responseData  = entityResponse.ResponseJSON;
                    JObject    recordDetails = (JObject)responseData[APIConstants.DETAILS];
                    ZCRMRecord newRecord     = records[i];
                    EntityAPIHandler.GetInstance(newRecord).SetRecordProperties(recordDetails);
                    createdRecords.Add(newRecord);
                    entityResponse.Data = newRecord;
                }
                else
                {
                    entityResponse.Data = null;
                }
            }
            response.BulkData = createdRecords;
            return(response);
        }
Exemplo n.º 20
0
        public Dictionary <string, long> ConvertRecord(ZCRMRecord potential, ZCRMUser assignToUser)
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.POST;

                urlPath = record.ModuleAPIName + "/" + record.EntityId + "/actions/convert";

                JObject requestBodyObject = new JObject();

                JArray dataArray = new JArray();

                JObject dataObject = new JObject();

                if (assignToUser != null)
                {
                    dataObject.Add("assign_to", assignToUser.Id.ToString());
                }

                if (potential != null)
                {
                    dataObject.Add(APIConstants.DEALS, GetInstance(potential).GetZCRMRecordAsJSON());
                }

                dataArray.Add(dataObject);

                requestBodyObject.Add(APIConstants.DATA, dataArray);

                requestBody = requestBodyObject;

                APIResponse response = APIRequest.GetInstance(this).GetAPIResponse();

                JArray responseJson = (JArray)response.ResponseJSON[APIConstants.DATA];

                JObject convertedIdsJSON = (JObject)responseJson[0];

                Dictionary <string, long> convertedIds = new Dictionary <string, long>();

                convertedIds.Add(APIConstants.CONTACTS, Convert.ToInt64(convertedIdsJSON[APIConstants.CONTACTS]));

                if (convertedIdsJSON[APIConstants.ACCOUNTS].Type != JTokenType.Null)
                {
                    convertedIds.Add(APIConstants.ACCOUNTS, Convert.ToInt64(convertedIdsJSON[APIConstants.ACCOUNTS]));
                }

                if (convertedIdsJSON[APIConstants.DEALS].Type != JTokenType.Null)
                {
                    convertedIds.Add(APIConstants.DEALS, Convert.ToInt64(convertedIdsJSON[APIConstants.DEALS]));
                }

                return(convertedIds);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);

                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
Exemplo n.º 21
0
        private BulkAPIResponse <ZCRMTrashRecord> GetDeletedRecords(string type, Dictionary <string, string> methodParams, Dictionary <string, string> methodHeaders)
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.GET;

                urlPath = module.ApiName + "/deleted";

                if (methodParams != null)
                {
                    foreach (KeyValuePair <string, string> methodParam in methodParams)
                    {
                        requestQueryParams.Add(methodParam.Key, methodParam.Value);
                    }
                }

                if (methodHeaders != null)
                {
                    foreach (KeyValuePair <string, string> methodHeader in methodHeaders)
                    {
                        requestHeaders.Add(methodHeader.Key, methodHeader.Value);
                    }
                }

                requestQueryParams.Add("type", type);

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

                List <ZCRMTrashRecord> trashRecordList = new List <ZCRMTrashRecord>();

                JObject responseJSON = response.ResponseJSON;

                if (responseJSON.ContainsKey(APIConstants.DATA))
                {
                    JArray trashRecordsArray = (JArray)responseJSON[APIConstants.DATA];

                    foreach (JObject trashRecordDetails in trashRecordsArray)
                    {
                        trashRecord = ZCRMTrashRecord.GetInstance((string)trashRecordDetails["type"], Convert.ToInt64(trashRecordDetails["id"]));

                        SetTrashRecordProperties(trashRecordDetails);

                        trashRecordList.Add(trashRecord);
                    }
                }

                response.BulkData = trashRecordList;

                return(response);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);

                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
Exemplo n.º 22
0
        public BulkAPIResponse <ZCRMRecord> UpdateRecords(List <ZCRMRecord> records, List <string> trigger)
        {
            try
            {
                if (records.Count > 100)
                {
                    throw new ZCRMException(APIConstants.API_MAX_RECORDS_MSG);
                }
                requestMethod = APIConstants.RequestMethod.PUT;
                urlPath       = module.ApiName;
                JObject requestBodyObject = new JObject();
                JArray  dataArray         = new JArray();
                foreach (ZCRMRecord record in records)
                {
                    if (record.GetFieldValue("id") == null || (long)record.GetFieldValue("id") <= 0)
                    {
                        throw new ZCRMException("Entity ID Must Not be null/empty for UpdateRecords operation.");
                    }
                    dataArray.Add(EntityAPIHandler.GetInstance(record).GetZCRMRecordAsJSON());
                }
                requestBodyObject.Add(APIConstants.DATA, dataArray);
                if (trigger != null && trigger.Count > 0)
                {
                    requestBodyObject.Add("trigger", JArray.FromObject(trigger));
                }
                requestBody = requestBodyObject;

                BulkAPIResponse <ZCRMRecord> response       = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMRecord>();
                List <ZCRMRecord>            updatedRecords = new List <ZCRMRecord>();
                List <EntityResponse>        responses      = response.BulkEntitiesResponse;
                int responseSize = responses.Count;
                for (int i = 0; i < responseSize; i++)
                {
                    EntityResponse entityResponse = responses[i];
                    if (entityResponse.Status.Equals(APIConstants.CODE_SUCCESS))
                    {
                        JObject    responseData  = entityResponse.ResponseJSON;
                        JObject    recordDetails = (JObject)responseData[APIConstants.DETAILS];
                        ZCRMRecord newRecord     = records[i];
                        EntityAPIHandler.GetInstance(newRecord).SetRecordProperties(recordDetails);
                        updatedRecords.Add(newRecord);
                        entityResponse.Data = newRecord;
                    }
                    else
                    {
                        entityResponse.Data = null;
                    }
                }
                response.BulkData = updatedRecords;
                return(response);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);
                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
Exemplo n.º 23
0
        public APIResponse DeleteRelation()
        {
            Console.WriteLine("DeleteRelation() Method");
            requestMethod = APIConstants.RequestMethod.DELETE;
            Console.WriteLine(requestMethod);
            urlPath = $"{parentRecord.ModuleAPIName}/{parentRecord.EntityId}/{junctionRecord.ApiName}/{junctionRecord.Id}";

            return(APIRequest.GetInstance(this).GetAPIResponse());
        }
Exemplo n.º 24
0
        public APIResponse DeleteNote(ZCRMNote note)
        {
            requestMethod = APIConstants.RequestMethod.DELETE;
            urlPath       = $"{parentRecord.ModuleAPIName}/{parentRecord.EntityId}/{relatedList.ApiName}/{note.Id}";

            APIResponse response = APIRequest.GetInstance(this).GetAPIResponse();

            return(response);
        }
Exemplo n.º 25
0
        public BulkAPIResponse <ZCRMRecord> CreateRecords(List <ZCRMRecord> records)
        {
            if (records.Count > 100)
            {
                throw new ZCRMException("Cannot process more than 100 records at a time");
            }
            try{
                requestMethod = APIConstants.RequestMethod.POST;
                urlPath       = module.ApiName;
                JObject requestBodyObject = new JObject();
                JArray  dataArray         = new JArray();
                foreach (ZCRMRecord record in records)
                {
                    if (record.EntityId == null)
                    {
                        dataArray.Add(EntityAPIHandler.GetInstance(record).GetZCRMRecordAsJSON());
                    }
                    else
                    {
                        throw new ZCRMException("Entity ID MUST be null for create operation.");
                    }
                }
                requestBodyObject.Add("data", dataArray);
                requestBody = requestBodyObject;

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

                List <ZCRMRecord>     createdRecords = new List <ZCRMRecord>();
                List <EntityResponse> responses      = response.BulkEntitiesResponse;
                int responseSize = responses.Count;
                for (int i = 0; i < responseSize; i++)
                {
                    EntityResponse entityResponse = responses[i];
                    if (entityResponse.Status.Equals("success"))
                    {
                        JObject    responseData  = entityResponse.ResponseJSON;
                        JObject    recordDetails = (JObject)responseData.GetValue("details");
                        ZCRMRecord newRecord     = records[i];
                        EntityAPIHandler.GetInstance(newRecord).SetRecordProperties(recordDetails);
                        createdRecords.Add(newRecord);
                        entityResponse.Data = newRecord;
                    }
                    else
                    {
                        entityResponse.Data = null;
                    }
                }
                response.BulkData = createdRecords;
                return(response);
            }catch (Exception e) {
                //TODO: Log the info;
                Console.WriteLine("Exception at createRecords");
                Console.WriteLine(e);
                throw new ZCRMException("ZCRM_INTERNAL_ERROR");
            }
        }
Exemplo n.º 26
0
 public BulkAPIResponse <ZCRMTag> CreateTags(List <ZCRMTag> tags)
 {
     if (tags.Count > 50)
     {
         throw new ZCRMException(APIConstants.API_MAX_TAGS_MSG);
     }
     try
     {
         requestMethod = APIConstants.RequestMethod.POST;
         urlPath       = "settings/tags?module=" + module.ApiName;
         JObject requestBodyObject = new JObject();
         JArray  dataArray         = new JArray();
         foreach (ZCRMTag tag in tags)
         {
             if (tag.Id == null)
             {
                 dataArray.Add(GetZCRMTagAsJSON(tag));
             }
             else
             {
                 throw new ZCRMException("Tag ID MUST be null for CreateTags operation.");
             }
         }
         requestBodyObject.Add(APIConstants.TAGS, dataArray);
         requestBody = requestBodyObject;
         BulkAPIResponse <ZCRMTag> response   = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMTag>();
         List <ZCRMTag>            createtags = new List <ZCRMTag>();
         List <EntityResponse>     responses  = response.BulkEntitiesResponse;
         int responseSize = responses.Count;
         for (int i = 0; i < responseSize; i++)
         {
             EntityResponse entityResponse = responses[i];
             if (entityResponse.Status.Equals(APIConstants.CODE_SUCCESS))
             {
                 JObject responseData = entityResponse.ResponseJSON;
                 JObject tagDetails   = (JObject)responseData[APIConstants.DETAILS];
                 ZCRMTag newTag       = tags[i];
                 SetTagProperties(newTag, tagDetails);
                 createtags.Add(newTag);
                 entityResponse.Data = newTag;
             }
             else
             {
                 entityResponse.Data = null;
             }
         }
         response.BulkData = createtags;
         return(response);
     }
     catch (Exception e) when((e is ZCRMException))
     {
         ZCRMLogger.LogError(e);
         throw new ZCRMException(APIConstants.SDK_ERROR, e);
     }
 }
Exemplo n.º 27
0
        public BulkAPIResponse <ZCRMRecord> MassUpdateRecords(List <long> entityIds, string fieldAPIName, Object value)
        {
            try
            {
                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);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);
                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
Exemplo n.º 28
0
        public BulkAPIResponse <ZCRMRecord> UpdateRecords(List <long> entityIds, string fieldAPIName, Object value)
        {
            if (entityIds.Count > 100)
            {
                throw new ZCRMException("Cannot process more than 100 records at a time");
            }
            //NOTE: null value is not converted to JObject of type null;
            try
            {
                requestMethod = APIConstants.RequestMethod.PUT;
                urlPath       = module.ApiName;
                JObject requestBodyObject = new JObject();
                JArray  dataArray         = new JArray();
                foreach (long id in entityIds)
                {
                    JObject updateJSON = new JObject();
                    //TODO: Check the below line on the usage of arrays;
                    updateJSON.Add(fieldAPIName, value.ToString());
                    updateJSON.Add("id", Convert.ToString(id));
                    dataArray.Add(updateJSON);
                }
                requestBodyObject.Add("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("success"))
                    {
                        JObject    responseData  = entityResponse.ResponseJSON;
                        JObject    recordDetails = (JObject)responseData.GetValue("details");
                        ZCRMRecord updatedRecord = ZCRMRecord.GetInstance(module.ApiName, Convert.ToInt64(recordDetails.GetValue("id")));
                        EntityAPIHandler.GetInstance(updatedRecord).SetRecordProperties(recordDetails);
                        updatedRecords.Add(updatedRecord);
                        entityResponse.Data = updatedRecord;
                    }
                    else
                    {
                        entityResponse.Data = null;
                    }
                }
                response.BulkData = updatedRecords;
                return(response);
            }catch (Exception e)
            {
                //TODO: Log the info;
                Console.WriteLine("Exception at updateRecords");
                Console.WriteLine(e);
                throw new ZCRMException("ZCRM_INTERNAL_ERROR");
            }
        }
        public APIResponse CreateRecord(List <string> trigger, string lar_id, List <string> process)
        {
            try
            {
                requestMethod = APIConstants.RequestMethod.POST;

                urlPath = record.ModuleAPIName;

                JObject requestBodyObject = new JObject();

                JArray dataArray = new JArray();

                dataArray.Add(GetZCRMRecordAsJSON());

                requestBodyObject.Add(APIConstants.DATA, dataArray);

                if (trigger != null && trigger.Count > 0)
                {
                    requestBodyObject.Add("trigger", JArray.FromObject(trigger));
                }

                if (lar_id != null)
                {
                    requestBodyObject.Add("lar_id", lar_id);
                }

                if (process != null && process.Count > 0)
                {
                    requestBodyObject.Add("process", JArray.FromObject(process));
                }

                requestBody = requestBodyObject;

                APIResponse response = APIRequest.GetInstance(this).GetAPIResponse();

                JArray responseDataArray = (JArray)response.ResponseJSON[APIConstants.DATA];

                JObject responseData = (JObject)responseDataArray[0];

                JObject recordDetails = (JObject)responseData[APIConstants.DETAILS];

                SetRecordProperties(recordDetails);

                response.Data = record;

                return(response);
            }
            catch (Exception e) when(!(e is ZCRMException))
            {
                ZCRMLogger.LogError(e);

                throw new ZCRMException(APIConstants.SDK_ERROR, e);
            }
        }
Exemplo n.º 30
0
        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);
        }