Sometimes it is hard to appreciate the degree to which the development world has changed over the last ten years or so, especially when one is surrounded by it on a daily basis.
Anyway, I was recently reminded of it while working on a project involving Pardot, the popular online marketing service provider. In past years, finding .NET based code snippets -- or examples -- demonstrating the process of interacting with the application programming interface (API) for such a service would have been relatively easy. The development world, however, has long moved past that and .NET is no longer considered the dominant player it once was. As a result, snippets of the type I referenced earlier have tended to become a bit more scarce.
But there are still a number of .NET users like myself out there, and here is a code snippet I wanted to share which I think others might find helpful. This VB.NET snippet demonstrates the manner in which we can login to the Pardot API.
Dim sResults As String
'Email address used to login to Pardot
Dim sPardotEmail As String = "my_email@mymail.com"
'Corresponding password for login
Dim sPardotPwd As String = "my_pardot_password"
'Obtained from user settings page in Pardot -- user specific
Dim sPardotUserKey As String = "pardot user key"
Dim sURL As String = "https://pi.pardot.com/api/login/version/3"
Dim sMsg As String = "email=" & sPardotEmail & "&password=" & sPardotPwd & "&user_key=" & sPardotUserKey
Dim wrRequest As System.Net.WebRequest = System.Net.WebRequest.Create(sURL)
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(sMsg)
wrRequest.Method = "POST"
wrRequest.ContentType = "application/x-www-form-urlencoded"
wrRequest.ContentLength = byteArray.Length
'Post it to Pardot!
Dim dataStream As System.IO.Stream = wrRequest.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
'Get the response from Pardot
Dim wrResponse As System.Net.WebResponse = wrRequest.GetResponse()
dataStream = wrResponse.GetResponseStream()
Dim dataReader As New System.IO.StreamReader(dataStream)
'Response is an XML document containing the Pardot API key
sResults = dataReader.ReadToEnd()
dataReader.Close()
dataStream.Close()
wrResponse.Close()
Your first step when integrating with Pardot should always be to login, as that process provides the Pardot API key that in turn is used in subsequent API calls.
If you have some useful tips for Pardot API integration and .NET, please share in the comments. Thanks in advance.
Thursday, September 20, 2012
Tuesday, August 7, 2012
SugarCRM Customization: Utilizing Custom JavaScript
SugarCRM, being a web application, naturally prompts some users to ask whether it is possible to apply customizations to the system which in turn mimic behavior they may have seen on a random web site in the course of their general web browsing. A good example would be formatting numbers entered into the phone number fields in SugarCRM, similar to the manner in which many web sites handle that type of data on a contact form.
By default, SugarCRM does not format the value one enters into any of the phone fields. For example, if one enters the value of 310.555.1212 into the Office Phone field on a contact record, it remains as such. But some users would prefer the number to be formatted, such as (310) 555-1212, or other pattern. This need gave rise to the phone formatter module that I released some years ago and made available via SugarForge.org. More importantly, it highlights the manner in which a little JavaScript code embedded within SugarCRM can be used to enrich the user experience.
A number of other enhancements can be applied by means of custom JavaScript code, but we must first understand the manner in which it should be embedded.
Lets dissect some of the files that make up the phone formatter module to get a clearer understanding of the process one can follow to apply custom JavaScript in an upgrade-safe manner.
If you have not already done so, download the phone formatter module from SugarForge.org. We will not be installing the module, just examining some files. Thus, simply download the most current version of the module and do not concern yourself with the version of SugarCRM you are using.
Friday, July 20, 2012
Logic Hooks: Odds and Ends
On occasion I run into a logic hook use case that ultimately exposes a limitation of the framework, or generates peculiar challenges during its implementation. Lets review some of these items in hopes they may help you avoid frustration and save you some time.
before_save vs. after_save
It is not uncommon to stumble upon references to either of these terms as one reads about logic hooks. They refer to the timing of the execution of your logic hook code. A before_save hook triggers your code before the record a SugarCRM user is interacting with is physically written to the database, and an after_save hook triggers it after the data has been written to the database.
While those conditions are easy to understand, the same cannot be said for the technical subtleties each carry. It is important to understand these subtleties because some may require one to change from using before_save instead of after_save or vice-versa. More importantly, being aware of these subtleties helps us reduce the amount of time that would otherwise be wasted on troubleshooting the problems the subtleties bring about.
Subscribe to:
Posts (Atom)