The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Trying to convert to BASIC VB.NET

Highlighted
Occasional Advisor

Trying to convert to BASIC VB.NET

No help needed for this, it appears that the only change required is to piont to https and not http.


Here is the code we previously ran fine. It now will not run under the new BASIC. Can anyone tell us why or how to change it to work?


Public Shared Sub GetctctLists(ByRef dropdown As DropDownList)

        Dim ConnectStr As String = _

        ConfigurationManager.ConnectionStrings("2ConnectionString").ConnectionString


        Try

            Dim ctu As String = Constant_Contact.GetCTU()

            Dim ctp As String = Constant_Contact.GetCTP()

            'check if user has ct's

            If String.IsNullOrEmpty(ctu) Then

                Exit Sub

            End If

            If String.IsNullOrEmpty(ctp) Then

                Exit Sub

            End If


            'this returns an xml list of lists for the ctct account.

            Dim sUri As String = "http://api.constantcontact.com/ws/customers/" & ctu & "/lists"

            Dim sAPIKey As String = "Dev Code Here"


            'setup httpWebReqeust to send the request

            Dim address As New Uri(sUri)

            Dim theRequest As HttpWebRequest = TryCast(WebRequest.Create(address), HttpWebRequest)

            theRequest.Credentials = New NetworkCredential((sAPIKey & "%" & ctu), ctp)

            theRequest.Method = "GET"

            theRequest.ContentType = "application/vnd.ctct+xml"


            Using theResponse As HttpWebResponse = TryCast(theRequest.GetResponse(), HttpWebResponse)

                'load dataset with xml response

                Dim xtr As New XmlTextReader(theResponse.GetResponseStream())

                xtr.ReadString()

                Dim dsct As New DataSet()

                dsct.ReadXml(xtr)

  'Filter out unwanted lists

                Dim dataView As DataView = dsct.Tables("ContactList").DefaultView

                dataView.RowFilter = "ShortName Not like 'Active' And ShortName Not like 'Do Not Mail' And ShortName Not like 'Removed' "


                'load dropdown list with list names from name xml node

                dropdown.DataSource = dataView

                dropdown.DataTextField = "ShortName"

                dropdown.DataValueField = "id"

                dropdown.DataBind()

                dropdown.Items.Insert(0, "")

                'Create the xml file to check what we are receiving.

                '   ds.WriteXml("C:\Data.xml")

            End Using

        Catch ex As Exception

            HttpContext.Current.Response.Write(ex.Message)

        End Try

    End Sub

Thank you,


Charles

2 REPLIES 2
Highlighted
Moderator

It should be a simple change

It should be a simple change to setting up the credentials of your request.  Change the following code:


 


theRequest.Credentials = New NetworkCredential((sAPIKey & "%" & ctu), ctp)


 


To set up a LoginCredentials class which allows you to specify the base domain and the authentication type:


 


dim LoginCredentials = new CredentialCache()

LoginCredentials.Add("https://api.constantcontact.com/ws/customers/" & ctu, "Basic",

                new NetworkCredential((sAPIKey & "%" & ctu), ctp))


theRequest.Credentials = LoginCredentials

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Occasional Advisor

Thanks Dave

It looks like it was simply needing us to change the HTTP to HTTPS.


 

Thank you,


Charles

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured