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); } }
private BulkAPIResponse <ZCRMTrashRecord> GetDeletedRecords(string type) { try { requestMethod = APIConstants.RequestMethod.GET; urlPath = module.ApiName + "/deleted"; 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); } }
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 ZCRMException(e); } return(retDict); }
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 BulkAPIResponse <ZCRMRecord> GetRecords(long?cvId, string sortByField, CommonUtil.SortOrder?sortOrder, int page, int perPage, string modifiedSince, string isConverted, string isApproved, List <string> fields) { try { 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); } catch (Exception e) when(!(e is ZCRMException)) { ZCRMLogger.LogError(e); throw new ZCRMException(APIConstants.SDK_ERROR, e); } }
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); }
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); } }
public APIResponse CreateBulkWriteJob() { try { if (this.writeRecord.JobId > 0) { throw new ZCRMException("JOB ID must be null for create operation."); } requestMethod = APIConstants.RequestMethod.POST; urlPath = APIConstants.WRITE; requestBody = this.GetZCRMBulkWriteAsJSON(); isBulk = true; APIResponse response = APIRequest.GetInstance(this).GetAPIResponse(); JObject responseData = response.ResponseJSON; JObject recordDetails = (JObject)responseData[APIConstants.DETAILS]; this.SetBulkWriteRecordProperties(recordDetails); response.Data = this.writeRecord; return(response); } catch (Exception e) when((e is ZCRMException)) { ZCRMLogger.LogError(e); throw new ZCRMException(APIConstants.SDK_ERROR, e); } }
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); } }
//TODO: Handle Exceptions <IMPORTANT = Handle UploadFile method in APIRequest>; public APIResponse UploadAttachment(string filePath) { //TODO: Validate File <IMPORTANT> try { requestMethod = APIConstants.RequestMethod.POST; urlPath = $"{parentRecord.ModuleAPIName}/{parentRecord.EntityId}/{relatedList.ApiName}"; ZCRMLogger.LogInfo("urlPath : " + urlPath); APIResponse response = APIRequest.GetInstance(this).UploadFile(filePath); JArray responseDataArray = (JArray)response.ResponseJSON.GetValue("data"); JObject responseData = (JObject)responseDataArray[0]; JObject responseDetails = (JObject)responseData.GetValue("details"); response.Data = GetZCRMAttachment(responseDetails); return(response); } catch (Exception e) { //TODO: Log the exception; Console.WriteLine("Exception in UploadAttachment"); Console.WriteLine(e); throw new ZCRMException("ZCRM_INTERNAL_ERROR"); } }
public ZohoOAuthTokens GetOAuthTokens(string userMailId) { ZohoOAuthTokens tokens; try { tokens = new ZohoOAuthTokens(); Dictionary <string, string> oauthTokens = ZohoOAuthUtil.GetFileAsDict(new FileStream(GetPersistenceHandlerFilePath(), FileMode.Open)); //Dictionary<string, string> oauthTokens = ZohoOAuthUtil.ConfigFileSectionToDict("tokens", "oauth_tokens.config"); if (!oauthTokens["useridentifier"].Equals(userMailId)) { throw new ZohoOAuthException("Given User not found in configuration"); } tokens.UserMaiilId = oauthTokens["useridentifier"]; tokens.AccessToken = oauthTokens["accesstoken"]; tokens.RefreshToken = oauthTokens["refreshtoken"]; tokens.ExpiryTime = Convert.ToInt64(oauthTokens["expirytime"]); return(tokens); } catch (FileNotFoundException e) { ZCRMLogger.LogError("Exception while fetching tokens from configuration." + e); throw new ZohoOAuthException(e); } }
public APIResponse CreateBulkReadJob() { try { if (this.readRecord.JobId != null) { throw new ZCRMException("JOB ID must be null for create operation."); } requestMethod = APIConstants.RequestMethod.POST; urlPath = APIConstants.READ; requestBody = this.GetZCRMBulkQueryAsJSON(); isBulk = true; APIResponse response = APIRequest.GetInstance(this).GetAPIResponse(); JArray responseDataArray = (JArray)response.ResponseJSON[APIConstants.DATA]; JObject responseData = (JObject)responseDataArray[0]; JObject recordDetails = (JObject)responseData[APIConstants.DETAILS]; this.SetBulkReadRecordProperties(recordDetails); response.Data = this.readRecord; return(response); } catch (Exception e) when(!(e is ZCRMException)) { ZCRMLogger.LogError(e); throw new ZCRMException(APIConstants.SDK_ERROR, e); } }
public APIResponse GetBulkReadJobDetails() { try { if (this.readRecord.JobId == null) { throw new ZCRMException("JOB ID must not be null for get operation."); } requestMethod = APIConstants.RequestMethod.GET; urlPath = APIConstants.READ + "/" + this.readRecord.JobId; isBulk = true; APIResponse response = APIRequest.GetInstance(this).GetAPIResponse(); JArray responseDataArray = (JArray)response.ResponseJSON[APIConstants.DATA]; JObject recordDetails = (JObject)responseDataArray[0]; this.SetBulkReadRecordProperties(recordDetails); response.Data = this.readRecord; 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); } }
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); } }
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); } }
//TODO: Create ZohoOAuthException class and change the throw exception class; private 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 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); } }
/// <summary> /// To get access token from grantToken. /// </summary> /// <returns>ZohoOAuthTokens class instance.</returns> /// <param name="grantToken">Grant token (String) of the oauth client</param> public ZohoOAuthTokens GenerateAccessToken(string grantToken) { if (grantToken == null || grantToken.Length == 0) { throw new ZohoOAuthException("Grant Type is not provided"); } try { var conn = GetZohoConnector(ZohoOAuth.GetTokenURL()); conn.AddParam(ZohoOAuthConstants.GRANT_TYPE, ZohoOAuthConstants.GRANT_TYPE_AUTH_CODE); conn.AddParam(ZohoOAuthConstants.CODE, grantToken); string response = conn.Post(); JObject responseJSON = JObject.Parse(response); if (responseJSON.ContainsKey(ZohoOAuthConstants.ACCESS_TOKEN)) { ZohoOAuthTokens tokens = GetTokensFromJSON(responseJSON); tokens.UserMaiilId = GetUserMailId(tokens.AccessToken); ZohoOAuth.GetPersistenceHandlerInstance().SaveOAuthTokens(tokens); 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 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); } }
private Stream GetFileRequestBodyStream(Stream fileContent, string fileName) { try { Stream fileDataStream = new MemoryStream(); //File Content-Disposition header excluding the boundary header; string fileHeader = string.Format("\r\nContent-Disposition: form-data; name=\"file\"; filename=\"" + fileName + "\"\r\nContent-Type: application/octet-stream\r\n\r\n"); byte[] fileHeaderBytes = Encoding.UTF8.GetBytes(fileHeader); fileDataStream.Write(fileHeaderBytes, 0, fileHeaderBytes.Length); //File content byte[] buffer = new byte[1024]; int bytesRead = 0; while ((bytesRead = fileContent.Read(buffer, 0, buffer.Length)) != 0) { fileDataStream.Write(buffer, 0, bytesRead); } //Footer byte[] fileFooterBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "--"); fileDataStream.Write(fileFooterBytes, 0, fileFooterBytes.Length); fileDataStream.Position = 0; return(fileDataStream); } catch (IOException e) { ZCRMLogger.LogError(e); throw new ZCRMException(e); } }
public APIResponse Update(ZCRMTag tag) { try { requestMethod = APIConstants.RequestMethod.PUT; urlPath = "settings/tags/" + tag.Id; requestQueryParams.Add("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 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 <ZCRMTag> GetTags() { try { requestMethod = APIConstants.RequestMethod.GET; urlPath = "settings/tags"; requestQueryParams.Add("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 BulkAPIResponse <ZCRMEntity> DeleteRecords(List <long> entityIds) { try { 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); } 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 { requestMethod = APIConstants.RequestMethod.POST; urlPath = "" + record.ModuleAPIName + "/" + record.EntityId + "/actions/remove_tags"; requestQueryParams.Add("tag_names", string.Join(",", JToken.FromObject(tagNames))); Console.WriteLine(JsonConvert.SerializeObject(requestQueryParams)); 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 recordIns = record; EntityAPIHandler.GetInstance(recordIns).SetRecordProperties(recordDetails); response.Data = recordIns; return(response); } catch (Exception e) when(!(e is ZCRMException)) { ZCRMLogger.LogError(e); throw new ZCRMException(APIConstants.SDK_ERROR, e); } }
private BulkAPIResponse <ZCRMRecord> SearchRecords(string searchKey, string searchValue, Dictionary <string, string> methodParams) { try { requestMethod = APIConstants.RequestMethod.GET; urlPath = module.ApiName + "/search"; requestQueryParams.Add(searchKey, searchValue); foreach (KeyValuePair <string, string> methodParam in methodParams) { requestQueryParams.Add(methodParam.Key, methodParam.Value); } 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); } catch (Exception e) when(!(e is ZCRMException)) { ZCRMLogger.LogError(e); throw new ZCRMException(APIConstants.SDK_ERROR, e); } }
public APIResponse CreateRecord(List <string> trigger, string lar_id) { 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); } 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); } }
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 ZCRMException(e); } }
public void SaveOAuthTokens(ZohoOAuthTokens zohoOAuthTokens) { string connectionString = $"server={GetServerName()};username={GetMySqlUserName()};password={GetMySqlPassword()};database={GetDataBaseName()};port={GetPortNumber()};persistsecurityinfo=True;SslMode=none;"; MySqlConnection connection = null; try { connection = new MySqlConnection(connectionString); string commandStatement = "insert into oauthtokens (useridentifier, accesstoken, refreshtoken, expirytime) values (@userIdentifier, @accessToken, @refreshToken, @expiryTime) on duplicate key update accesstoken = @accessToken, refreshtoken = @refreshToken, expirytime = @expiryTime"; connection.Open(); MySqlCommand command = new MySqlCommand(commandStatement, connection); command.Parameters.AddWithValue("@userIdentifier", zohoOAuthTokens.UserMaiilId); command.Parameters.AddWithValue("@accessToken", zohoOAuthTokens.AccessToken); command.Parameters.AddWithValue("@refreshToken", zohoOAuthTokens.RefreshToken); command.Parameters.AddWithValue("@expiryTime", zohoOAuthTokens.ExpiryTime); command.ExecuteNonQuery(); } catch (MySqlException e) { ZCRMLogger.LogError("Exception while inserting tokens to database." + e); throw new ZohoOAuthException(e); } finally { if (connection != null) { connection.Close(); } } }