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); } }
public static Dictionary <string, string> GetFileAsDict(Stream inputStream) { try { Dictionary <string, string> outDict = new Dictionary <string, string>(); using (StreamReader reader = new StreamReader(inputStream)) { string line; while ((line = reader.ReadLine()) != null) { string[] values = line.Split('='); if (!values[0].StartsWith("#", StringComparison.CurrentCulture)) { string val = null; if (values.Length == 2 && values[1] != null && values[1] != "") { val = values[1]; } else { continue; } outDict.Add(values[0], val); } } } return(outDict); } catch (Exception e) { ZCRMLogger.LogError(e); throw new Exception(e.Message); } }
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); } }
public static Dictionary <string, string> GetConfigFileAsDict(string sectionName) { Dictionary <string, string> retDict = new Dictionary <string, string>(); try { Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigFileSection section = configuration.GetSection(sectionName) as ConfigFileSection; if (section != null) { foreach (ConfigFileElement element in section.Settings) { if (element.Value != null && element.Value != "") { retDict.Add(element.Key, element.Value); } } } } catch (Exception e) { ZCRMLogger.LogError(e); throw new Exception(e.Message); } return(retDict); }
public string GetAccessToken(string userMailId) { IZohoPersistenceHandler persistenceHandler = ZohoOAuth.GetPersistenceHandlerInstance(); ZohoOAuthTokens tokens; try { ZCRMLogger.LogInfo("Retreiving access token.."); tokens = persistenceHandler.GetOAuthTokens(userMailId); } catch (Exception e) when(!(e is ZohoOAuthException)) { ZCRMLogger.LogError("Exception while fetching tokens from persistence" + e); throw new ZohoOAuthException(e); } try { return(tokens.AccessToken); } catch (ZohoOAuthException) { ZCRMLogger.LogInfo("Access Token expired, Refreshing Access token"); tokens = RefreshAccessToken(tokens.RefreshToken, userMailId); } return(tokens.AccessToken); }
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); } }
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); } }
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 UpdateRecord() { try { requestMethod = APIConstants.RequestMethod.PUT; urlPath = record.ModuleAPIName + "/" + record.EntityId; JObject requestBodyObject = new JObject(); JArray dataArray = new JArray(); dataArray.Add(GetZCRMRecordAsJSON()); 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]; SetRecordProperties(responseDetails); response.Data = record; return(response); } catch (Exception e) when(!(e is ZCRMException)) { ZCRMLogger.LogError(e); throw new ZCRMException(APIConstants.SDK_ERROR, e); } }
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); } }
private void AuthenticateRequest() { try { if (ZCRMConfigUtil.HandleAuthentication) { string accessToken = (string)(Type.GetType(ZCRMConfigUtil.GetAuthenticationClass()).GetMethod("GetAccessToken", BindingFlags.Static | BindingFlags.Public).Invoke(null, null)); if (accessToken == null) { ZCRMLogger.LogError("Access token is not set"); throw new ZCRMException(APIConstants.AUTHENTICATION_FAILURE, "Access token is not set"); } SetHeader("Authorization", APIConstants.authHeaderPrefix + accessToken); ZCRMLogger.LogInfo("Token fetched successfully.."); } } catch (TargetInvocationException e) { ZCRMLogger.LogError(e.GetBaseException()); if (e.GetBaseException() is ZCRMException) { throw (ZCRMException)(e.GetBaseException()); } throw new ZCRMException(e.GetBaseException()); } catch (Exception e) when(e is TargetException || e is MethodAccessException) { ZCRMLogger.LogError(e); throw new ZCRMException(e); } }
//TODO: Change the access-modifier to internal; public string Post() { try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); string postData = null; if (requestParams.Count != 0) { foreach (KeyValuePair <string, string> param in requestParams) { if (postData == null) { postData = param.Key + "=" + param.Value; } else { postData += "&" + param.Key + "=" + param.Value; } } } request.UserAgent = "Mozilla/5.0"; var data = Encoding.UTF8.GetBytes(postData); if (RequestHeaders.Count != 0) { foreach (KeyValuePair <string, string> header in RequestHeaders) { if (header.Value != null && string.IsNullOrEmpty(header.Value)) { request.Headers[header.Key] = header.Value; } } } request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; request.Method = "POST"; using (var dataStream = request.GetRequestStream()) { dataStream.Write(data, 0, data.Length); } ZCRMLogger.LogInfo("POST - " + APIConstants.URL + " = " + url + ", " + APIConstants.HEADERS + " = " + CommonUtil.DictToString(RequestHeaders) + ", " + APIConstants.PARAMS + " = " + CommonUtil.DictToString(requestParams)); var response = (HttpWebResponse)request.GetResponse(); string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); ZCRMLogger.LogInfo(APIConstants.STATUS_CODE + " = " + response.StatusCode + ", " + APIConstants.RESPONSE_JSON + " = " + responseString); return(responseString); } catch (WebException e) { ZCRMLogger.LogError(e); new ZohoOAuthException(e); return("Error: " + e.Message); //Messagebox.Show(e.Message) } }
//TODO: Create ZohoOAuthException class and change the throw exception class; public ZohoOAuthTokens RefreshAccessToken(string refreshToken, string userMailId) { if (refreshToken == null) { throw new ZohoOAuthException("Refresh token is not provided"); } try { ZohoHTTPConnector conn = GetZohoConnector(ZohoOAuth.GetRefreshTokenURL()); conn.AddParam(ZohoOAuthConstants.GRANT_TYPE, ZohoOAuthConstants.REFRESH_TOKEN); conn.AddParam(ZohoOAuthConstants.REFRESH_TOKEN, refreshToken); string response = conn.Post(); JObject responseJSON = JObject.Parse(response); if (responseJSON.ContainsKey(ZohoOAuthConstants.ACCESS_TOKEN)) { ZohoOAuthTokens tokens = GetTokensFromJSON(responseJSON); tokens.RefreshToken = refreshToken; tokens.UserMaiilId = userMailId; ZohoOAuth.GetPersistenceHandlerInstance().SaveOAuthTokens(tokens); return(tokens); } throw new ZohoOAuthException("Exception while fetching access tokens from Refresh Token" + response); } catch (WebException e) { ZCRMLogger.LogError(e); throw new ZohoOAuthException(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); } }
//TODO: Throw Exceptions public string Get() { try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); request.UserAgent = "Mozilla/5.0"; if (RequestHeaders != null && RequestHeaders.Count != 0) { foreach (KeyValuePair <string, string> header in RequestHeaders) { request.Headers[header.Key] = header.Value; } } ZCRMLogger.LogInfo("GET - " + APIConstants.URL + " = " + url + ", " + APIConstants.HEADERS + " = " + CommonUtil.DictToString(RequestHeaders) + ", " + APIConstants.PARAMS + " = " + CommonUtil.DictToString(requestParams)); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string responseString = ""; using (StreamReader reader = new StreamReader(response.GetResponseStream())) { responseString = reader.ReadToEnd(); } ZCRMLogger.LogInfo(APIConstants.STATUS_CODE + " = " + response.StatusCode + ", " + APIConstants.RESPONSE_JSON + " = " + responseString); return(responseString); } catch (WebException e) { ZCRMLogger.LogError(e); new ZohoOAuthException(e); MessageBox.Show(e.Message, "Get", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
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); } }
internal static Dictionary <string, string> GetFileAsDict(Stream inputStream) { try { Dictionary <string, string> outDict = new Dictionary <string, string>(); using (StreamReader reader = new StreamReader(inputStream)) { string line; while ((line = reader.ReadLine()) != null) { string[] values = line.Split('='); if (!values[0].StartsWith("#", StringComparison.CurrentCulture)) { string val = null; if (values.Length == 2 && values[1] != null && values[1] != "") { val = values[1]; } outDict.Add(values[0], val); } } } return(outDict); } catch (ArgumentNullException e) { ZCRMLogger.LogError("Exception while initializing Zoho OAuth Client .. Essential configuration data not found"); throw new ZohoOAuthException(e); } }
protected override void HandleFaultyResponse() { if (HttpStatusCode == APIConstants.ResponseCode.NO_CONTENT) { throw new ZCRMException(APIConstants.INVALID_DATA, APIConstants.INVALID_ID_MSG); } ZCRMLogger.LogError(ResponseJSON[APIConstants.CODE] + " " + ResponseJSON[APIConstants.MESSAGE]); throw new ZCRMException(ResponseJSON.GetValue(APIConstants.CODE).ToString(), ResponseJSON.GetValue(APIConstants.MESSAGE).ToString()); }
public static void Initialize(bool initOAuth, Stream configStream, Dictionary <string, string> configData) { Assembly assembly = Assembly.GetAssembly(typeof(ZCRMConfigUtil)); //ConfigProperties = // CommonUtil.GetFileAsDict( // assembly.GetManifestResourceStream(assembly.GetName().Name + ".Resources.configuration.txt")); // Stream st = new Stream; ConfigProperties = CommonUtil.GetFileAsDict(File.Open(@"D:\Github\configuration.txt", FileMode.Open)); if (configStream == null && configData == null) { Dictionary <string, string> keyValuePairs = CommonUtil.GetConfigFileAsDict("zcrm_configuration"); foreach (KeyValuePair <string, string> keyValues in keyValuePairs) { ConfigProperties[keyValues.Key] = keyValues.Value; } } if (configStream != null) { configData = CommonUtil.GetFileAsDict(configStream); configStream = null; } if (configData != null) { AddConfigurationData(configData); } ZCRMLogger.Init(); if (initOAuth) { HandleAuthentication = true; try { ZohoOAuth.Initialize(ConfigProperties.ContainsKey(APIConstants.DOMAIN_SUFFIX) ? (string)ConfigProperties[APIConstants.DOMAIN_SUFFIX] : null, configData); if (ConfigProperties.ContainsKey(APIConstants.DOMAIN_SUFFIX)) { SetAPIBaseUrl(ConfigProperties[APIConstants.DOMAIN_SUFFIX]); } } catch (Exception e) { throw new ZCRMException(e); } } ZCRMLogger.LogInfo("C# Client Library Configuration Properties : " + CommonUtil.DictToString(ConfigProperties)); }
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); } }
public void GetToken() { //ZCRMRestClient.Initialize(Dictionary.config); //ZohoOAuthClient client = ZohoOAuthClient.GetInstance(); ZohoOAuthClient.Initialize(); ZCRMRestClient.Initialize(null); ZohoOAuthClient client = ZohoOAuthClient.GetInstance(); //ZohoOAuthParams param = new ZohoOAuthParams(); //param.ClientId = "1000.BT8QS94IIA8278417LUKT1DE7XXBFH"; //param.ClientSecret = "e319f52223bc374d77c65ab410587593cf3ae7e20c"; //param.RedirectURL = "https://zohoapis.zoho.com/"; //param.AccessType = "code"; //param.Scopes = "ZohoCRM.modules.all"; ///ZohoOAuthClient client = new ZohoOAuthClient(param); string grantToken = "1000.a25f043b256bcdcab5804a0cec61c684.ba747fb495a81327a9d78b0e2a1d052f"; // ZohoOAuthTokens tokens = client.GenerateAccessToken(grantToken); //string accessToken = tokens.AccessToken; //string refreshToken = tokens.RefreshToken; try { var conn = client.GetZohoConnector(ZohoOAuth.GetTokenURL()); conn.AddParam(ZohoOAuthConstants.GRANT_TYPE, ZohoOAuthConstants.GRANT_TYPE_AUTH_CODE); conn.AddParam(ZohoOAuthConstants.CODE, grantToken); string response = conn.Post(); string v = string.Empty; JObject responseJSON = JObject.Parse(response); //if (responseJSON.ContainsKey(ZohoOAuthConstants.ACCESS_TOKEN)) //{ // ZohoOAuthTokens tokens = client.GetTokensFromJSON(responseJSON); // tokens.UserMaiilId = client.GetUserMailId(tokens.AccessToken); // ZohoOAuth.GetPersistenceHandlerInstance().SaveOAuthTokens(tokens); // string accessToken = tokens.AccessToken; // string refreshToken = tokens.RefreshToken; // //return tokens; //} //throw new ZohoOAuthException("Exception while fetching Access Token from grant token" + response); } catch (WebException e) { ZCRMLogger.LogError(e); throw new ZohoOAuthException(e); } }
public static string GetAllowedAPICallsPerMinute() { try { return(apiCountStats[APIConstants.ALLOWED_API_CALLS_PER_MINUTE]); } catch (KeyNotFoundException e) { ZCRMLogger.LogError(e); throw new ZCRMException("Stats not set!.", e); } }
public static string GetRemainingCountForCurrentWindow() { try { return(apiCountStats[APIConstants.REMAINING_COUNT_FOR_THIS_WINDOW]); } catch (KeyNotFoundException e) { ZCRMLogger.LogError(e); throw new ZCRMException("Stats not set!.", e); } }
public static string GetRemainingTimeForWindowReset() { try { return(apiCountStats[APIConstants.REMAINING_TIME_FOR_WINDOW__RESET]); } catch (KeyNotFoundException e) { ZCRMLogger.LogError(e); throw new ZCRMException("Stats not set!.", e); } }
private void PopulateRequestStream(HttpWebRequest request) { try { //If JSON Payload if (RequestBody.Type != JTokenType.Null && RequestBody.Count > 0) { string dataString = RequestBody.ToString(); var data = Encoding.UTF8.GetBytes(dataString); int dataLength = data.Length; request.ContentType = "application/json"; request.ContentLength = dataLength; using (var writer = request.GetRequestStream()) { writer.Write(data, 0, dataLength); } } //If either file Payload or empty request body else { requestStream = new MemoryStream(); String multiPartHeader = "\r\n--" + boundary; byte[] multiPartHeaderBytes = Encoding.UTF8.GetBytes(multiPartHeader); requestStream.Write(multiPartHeaderBytes, 0, multiPartHeaderBytes.Length); byte[] buffer = new byte[1024]; int bytesRead = 0; if (fileRequestBody != null && fileRequestBody.Length > 0) { while ((bytesRead = fileRequestBody.Read(buffer, 0, buffer.Length)) != 0) { requestStream.Write(buffer, 0, bytesRead); } } requestStream.Position = 0; request.ContentType = "multipart/form-data; boundary=" + boundary; request.ContentLength = requestStream.Length; using (var writer = request.GetRequestStream()) { while ((bytesRead = requestStream.Read(buffer, 0, buffer.Length)) != 0) { writer.Write(buffer, 0, bytesRead); } } } } catch (Exception e) { ZCRMLogger.LogError(e); throw new ZCRMException(e); } }
protected override void HandleFaultyResponse() { if ((HttpStatusCode == APIConstants.ResponseCode.NO_CONTENT) || (HttpStatusCode == APIConstants.ResponseCode.NOT_MODIFIED)) { ResponseJSON = new JObject(); BulkData = new List <T>(); } else { ZCRMLogger.LogError(ResponseJSON[APIConstants.CODE] + " " + ResponseJSON[APIConstants.MESSAGE]); throw new ZCRMException((string)ResponseJSON[APIConstants.CODE], (string)ResponseJSON[APIConstants.MESSAGE]); } }
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 FileAPIResponse DownloadFile() { try { GetResponseFromServer(); FileAPIResponse fileAPIResponse = new FileAPIResponse(response); return(fileAPIResponse); } catch (Exception e) when(!(e is ZCRMException)) { ZCRMLogger.LogError(e); throw new ZCRMException(e); } }
public APIResponse Delete(long?tagid) { try { requestMethod = APIConstants.RequestMethod.DELETE; urlPath = "settings/tags/" + tagid; return(APIRequest.GetInstance(this).GetAPIResponse()); } catch (Exception e) when(!(e is ZCRMException)) { ZCRMLogger.LogError(e); throw new ZCRMException(APIConstants.SDK_ERROR, e); } }
public CommonAPIResponse(HttpWebResponse response) { try { Response = response; Init(); ProcessResponse(); SetResponseHeaders(); ZCRMLogger.LogInfo(ToString()); } catch (Exception) { ZCRMLogger.LogInfo(ToString()); } }