I have to admit, I’ve never worked with an API before, ok I’ve pulled an image from flickr or the twitter feed on the side bar with API but someone else showed me how to do that. For work I had to write vb.net code to work with CVent’s API. So over the next few post, I’ll be adding code that may help others (Since I could find any for the API newbie!), I will also admit that this isn’t the prettiest or even the most logical code but it works for how we’re doing things and will give you a beginning point to work with.
There are many spots in the code that the API uses arrays and as you’ll see I’ve created my loops to add only a single element into the array. I know, I know but when you’re on a tight schedule and you’re just figuring out the API, if something works, you go with it.. and if you use my code and actually change it to work correctly, please send me your examples so I can share with everyone. (richard(@)curbob.com).
Lets start at the beginning.. adding the API to VisualStudio
You have to have an API account with Cvent to even access the API, so untill all contracts are signed, don’t even try. I thought for a day I was doing something wrong.. nope, no access.
To connect VS2005/2008 to CVent API, right click the project in solution explorer and choose “Add Web Reference”. The URL is https://api.cvent.com/soap/V200611.asmx?WSDL. After adding this URL I was bombarded with 4 popup boxes asking about letting this secure page show, click yes on all of them and also unblock the activeX content. Then Click Add Reference.
Private _ws As New com.cvent.api.V200611()
Lets login into CVent API
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Login("account Number", "UserName", "Password") = True Then Label1.Text = "Login worked" Else Label1.Text = "Login failed" End If End Sub Public Function Login(ByVal Acct As [String], ByVal userName As [String], ByVal pwd As [String]) As [Boolean] Dim loginResult As com.cvent.api.LoginResult = _ws.Login(Acct, userName, pwd) _ws.CventSessionHeaderValue = New com.cvent.api.CventSessionHeader() _ws.CventSessionHeaderValue.CventSessionValue = loginResult.CventSessionHeader Return (loginResult.LoginSuccess) End Function