/// <summary> /// Added by Viral /// Added On 13 June 2016 /// to check the authentication for Saleforce /// </summary> public bool AuthenticateforSFDC(Dictionary <string, string> sfdcCredentials, string AppId, string clientID) { HttpClient client = new HttpClient(); bool isAuthenticated = false; string IntegrstionApi = System.Configuration.ConfigurationManager.AppSettings.Get("IntegrationApi"); if (IntegrstionApi != null) { JObject obj = new JObject(); obj.Add("credentials", JsonConvert.SerializeObject(sfdcCredentials)); obj.Add("applicationId", AppId); obj.Add("clientId", clientID); Uri baseAddress = new Uri(IntegrstionApi); client.BaseAddress = baseAddress; ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; HttpResponseMessage response = client.PostAsJsonAsync("api/Sfdc/SalesForce_Authentication", obj).Result; if (response.IsSuccessStatusCode) { ReturnObject objData = JsonConvert.DeserializeObject <ReturnObject>(response.Content.ReadAsStringAsync().Result); isAuthenticated = objData.status; } } return(isAuthenticated); }
/// <summary> /// Created By Rahul Shah /// Created Date : 22-May-2016 /// Get list of marketo custom tag with api /// </summary> /// <returns></returns> public Dictionary <string, string> GetTargetCustomTags() { Dictionary <string, string> ListOfData = new Dictionary <string, string>(); Dictionary <string, string> marketoCredentialDictionary = new Dictionary <string, string>(); marketoCredentialDictionary.Add("host", _host); marketoCredentialDictionary.Add("clientid", _clientid); marketoCredentialDictionary.Add("clientsecret", _clientsecret); marketoCredentialDictionary.Add("token", _marketoToken); HttpClient client = new HttpClient(); string marketoIntegrstionApi = System.Configuration.ConfigurationManager.AppSettings.Get("IntegrationApi"); Uri baseAddress = new Uri(marketoIntegrstionApi); //Uri baseAddress = new Uri("http://121.244.200.162:8085/IntegrationApi/"); client.BaseAddress = baseAddress; ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; HttpResponseMessage response = client.PostAsJsonAsync("api/Marketo/Marketo_GetProgramFields", marketoCredentialDictionary).Result; if (response.IsSuccessStatusCode) { ReturnObject objData = JsonConvert.DeserializeObject <ReturnObject>(response.Content.ReadAsStringAsync().Result); ListOfData = objData.data; if (HttpContext.Current != null) { HttpContext.Current.Session["MarketoToken"] = objData.lstLogDetails.Where(tkn => tkn.EventName.ToString().Equals("strToken")).Select(th => th.Description).FirstOrDefault(); } } return(ListOfData); }
/// <summary> /// Created By Rahul Shah /// Created Date : 24-May-2016 /// to push the data to the marketo and get the loglist from marketo /// </summary> /// <returns></returns> public List <LogDetails> MarketoData_Push(string spName, List <fieldMapping> lstFieldsMap, int _clientId, List <SpParameters> spParams) { bool isAuthenticate = false; string strwebAPITimeout = System.Configuration.ConfigurationManager.AppSettings["CommonIntegrationWebAPITimeOut"]; int CommonWebAPITimeout = 0; if (!string.IsNullOrEmpty(strwebAPITimeout)) { CommonWebAPITimeout = Convert.ToInt32(strwebAPITimeout); } Parameters objParams = new Parameters(); List <LogDetails> logdetails = new List <LogDetails>(); Dictionary <string, string> marketoCredentialDictionary = new Dictionary <string, string>(); marketoCredentialDictionary.Add("host", _host); marketoCredentialDictionary.Add("clientid", _clientid); marketoCredentialDictionary.Add("clientsecret", _clientsecret); marketoCredentialDictionary.Add("token", _marketoToken); objParams.credentials = marketoCredentialDictionary; objParams.applicationId = _applicationId.ToString(); objParams.clientId = _clientId.ToString(); objParams.fieldMapList = lstFieldsMap; objParams.spName = spName; objParams.lstParameterList = spParams; HttpClient client = new HttpClient(); client.Timeout = TimeSpan.FromHours(CommonWebAPITimeout); //set timeout for Common Integration API call client.Timeout = TimeSpan.FromHours(3); //set timeout for Common Integration API call string marketoIntegrstionApi = System.Configuration.ConfigurationManager.AppSettings.Get("IntegrationApi"); Uri baseAddress = new Uri(marketoIntegrstionApi); //Uri baseAddress = new Uri("http://localhost:54371/"); client.BaseAddress = baseAddress; ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; HttpResponseMessage response = client.PostAsJsonAsync("api/Marketo/Marketo_PushMarketoPrograms ", objParams).Result; ReturnObject ro = new ReturnObject(); if (response.IsSuccessStatusCode) { ReturnObject obj2 = JsonConvert.DeserializeObject <ReturnObject>(response.Content.ReadAsStringAsync().Result); logdetails = obj2.lstLogDetails; isAuthenticate = obj2.lstLogDetails.Where(tkn => tkn.EventName.ToString().Equals(strAuthentication)).Select(th => th.Status).Any(); if (isAuthenticate) { _isAuthenticated = true; if (HttpContext.Current != null) { HttpContext.Current.Session["MarketoToken"] = obj2.lstLogDetails.Where(tkn => tkn.EventName.ToString().Equals(strToken)).Select(th => th.Description).FirstOrDefault(); } } } return(logdetails); }
/// <summary> /// Get list of Fields Name,Type, Length from SFDC. /// </summary> /// <param name="salesforceCredentials"></param> /// <returns></returns> public List <SalesForceFieldsDetails> GetSFDCmetaDataFields(Dictionary <string, string> salesforceCredentials, string AppId, string clientid, string objectName) { #region "Old Code" // //int CommonWebAPITimeout = 0; //string strwebAPITimeout = System.Configuration.ConfigurationManager.AppSettings["CommonIntegrationWebAPITimeOut"]; // //JObject obj = new JObject(); //obj.Add("credentials", JsonConvert.SerializeObject(salesforceCredentials)); //obj.Add("applicationId", AppId); //obj.Add("clientId", clientid); //obj.Add("object", objectname); //if (!string.IsNullOrEmpty(strwebAPITimeout)) // CommonWebAPITimeout = Convert.ToInt32(strwebAPITimeout); //else // CommonWebAPITimeout = 4; // if user has not defined Integration WEB API timeout then set static value to 4. //HttpClient client = new HttpClient(); //client.Timeout = TimeSpan.FromHours(CommonWebAPITimeout); //set timeout for Common Integration API call //string IntegrstionApi = System.Configuration.ConfigurationManager.AppSettings.Get("IntegrationApi"); //Uri baseAddress = new Uri(IntegrstionApi); //client.BaseAddress = baseAddress; //ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; //HttpResponseMessage response = client.PostAsJsonAsync("api/Sfdc/SalesForce_ReadMetadataDetails", obj).Result; // #endregion #region "Declare local variables" //string objectname = "Campaign"; HttpResponseMessage response = new HttpResponseMessage(); ReturnObject ro = new ReturnObject(); List <SalesForceFieldsDetails> lstSFDCFieldDetails = new List <SalesForceFieldsDetails>(); #endregion response = GetSFDCDataFields(salesforceCredentials, AppId, clientid, objectName); if (response.IsSuccessStatusCode) { string json = response.Content.ReadAsStringAsync().Result; ReturnObject obj2 = JsonConvert.DeserializeObject <ReturnObject>(response.Content.ReadAsStringAsync().Result); ro.status = obj2.status; //ro.logs = obj2.logs; lstSFDCFieldDetails = obj2.salesForceFieldsDetails; } return(lstSFDCFieldDetails); }
/// <summary> /// Added by Rahul Shah /// 21-05-2016 /// to check the authentication for Marketo /// </summary> public void AuthenticateforMarketo() { if (HttpContext.Current != null && HttpContext.Current.Session["MarketoToken"] != null) { _marketoToken = HttpContext.Current.Session["MarketoToken"].ToString(); } else { _marketoToken = ""; } Dictionary <string, string> marketoCredentialDictionary = new Dictionary <string, string>(); marketoCredentialDictionary.Add("host", _host); marketoCredentialDictionary.Add("clientid", _clientid); marketoCredentialDictionary.Add("clientsecret", _clientsecret); marketoCredentialDictionary.Add("token", _marketoToken); HttpClient client = new HttpClient(); string marketoIntegrstionApi = System.Configuration.ConfigurationManager.AppSettings.Get("IntegrationApi"); if (marketoIntegrstionApi != null) { Uri baseAddress = new Uri(marketoIntegrstionApi); client.BaseAddress = baseAddress; ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; HttpResponseMessage response = client.PostAsJsonAsync("api/Marketo/Marketo_Authentication", marketoCredentialDictionary).Result; if (response.IsSuccessStatusCode) { ReturnObject objData = JsonConvert.DeserializeObject <ReturnObject>(response.Content.ReadAsStringAsync().Result); if (objData.status == true) { _isAuthenticated = true; if (HttpContext.Current != null) { HttpContext.Current.Session["MarketoToken"] = objData.lstLogDetails.Where(tkn => tkn.EventName.ToString().Equals("strToken")).Select(th => th.Description).FirstOrDefault(); } } else { _isAuthenticated = false; //_ErrorMessage = objData.lstLogDetails.Select(err => err.Description.ToString()).FirstOrDefault(); } } } }
/// <summary> /// Created By Nishant Sheth /// Created Date : 21-May-2016 /// Get list of marketo campaign folder with api /// </summary> /// <returns></returns> public ReturnObject GetMarketoCampaignFolderList() { ReturnObject ListOfData = new ReturnObject(); if (_TypeofData == Enums.ApiIntegrationData.CampaignFolderList.ToString()) { if (HttpContext.Current != null && HttpContext.Current.Session["MarketoToken"] != null) { _marketoToken = HttpContext.Current.Session["MarketoToken"].ToString(); } else { _marketoToken = ""; } Dictionary <string, string> marketoCredentialDictionary = new Dictionary <string, string>(); marketoCredentialDictionary.Add("host", _host); marketoCredentialDictionary.Add("clientid", _clientid); marketoCredentialDictionary.Add("clientsecret", _clientsecret); marketoCredentialDictionary.Add("token", _marketoToken); marketoCredentialDictionary.Add("rootfolder", "Marketing Activities"); HttpClient client = new HttpClient(); string marketoIntegrstionApi = System.Configuration.ConfigurationManager.AppSettings.Get("IntegrationApi"); Uri baseAddress = new Uri(marketoIntegrstionApi); // Uri baseAddress = new Uri("http://121.244.200.162:8085/IntegrationApi/"); client.BaseAddress = baseAddress; ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; HttpResponseMessage response = client.PostAsJsonAsync("api/Marketo/Marketo_GetFolders_MarketingActivity", marketoCredentialDictionary).Result; if (response.IsSuccessStatusCode) { var responseobj = response.Content.ReadAsStringAsync().Result; ReturnObject objData = JsonConvert.DeserializeObject <ReturnObject>(responseobj); if (HttpContext.Current != null) { HttpContext.Current.Session["MarketoToken"] = objData.lstLogDetails.Where(tkn => tkn.EventName.ToString().Equals("Token")).Select(th => th.Description).FirstOrDefault(); } ListOfData = objData; } } return(ListOfData); }