VB.NET Requires Chilkat v11.0.0+
VB.NET
Constant Contact V3: Create a contact
See more Constant Contact Examples
Create an account-entered contact and read its new ID. Use the email permission that accurately describes the contact’s relationship with the account. The optional postal address belongs in the street_addresses array. On a duplicate, look up the existing contact before deciding whether an update is appropriate. Authorize the app first and use the same credential store.
Constant Contact developer guide
Chilkat VB.NET Downloads
Dim success As Boolean = False
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim vault As New Chilkat.Secrets
vault.Location = "local_manager"
vault.AutoSplit = True
Dim entry As New Chilkat.JsonObject
entry.UpdateString("appName","ConstantContactV3")
entry.UpdateString("service","OAuth2")
entry.UpdateString("username","my-account")
Dim tokens As New Chilkat.JsonObject
Dim loaded As Boolean = vault.GetSecretJson(entry,tokens)
If (loaded <> True) Then
Debug.WriteLine("Run the desktop authorization example using this account and store.")
Exit Sub
End If
If (tokens.JsonTypeOf("access_token") <> 1) Then
Debug.WriteLine("The saved authorization has no access token.")
Exit Sub
End If
Dim http As New Chilkat.Http
http.RequireSslCertVerify = True
http.AuthToken = tokens.StringOf("access_token")
Dim resp As New Chilkat.HttpResponse
Dim body As New Chilkat.JsonObject
body.UpdateString("create_source","Account")
body.UpdateString("first_name","Alex")
body.UpdateString("last_name","Rivera")
body.UpdateString("email_address.address","reader+newsletter@example.com")
' This sample assumes the account has recorded a qualifying existing relationship.
body.UpdateString("email_address.permission_to_send","implicit")
body.UpdateString("street_addresses[0].kind","work")
body.UpdateString("street_addresses[0].street","100 Main Street")
body.UpdateString("street_addresses[0].city","Boston")
body.UpdateString("street_addresses[0].state","MA")
body.UpdateString("street_addresses[0].country","United States")
success = http.HttpJson("POST","https://api.cc.email/v3/contacts",body,"application/json",resp)
If (resp.StatusCode = 409) Then
Debug.WriteLine("Contact already exists. Look up the email address to obtain its ID.")
Exit Sub
End If
If ((success <> True) Or (resp.StatusCode <> 201)) Then
Debug.WriteLine("Expected HTTP 201. Received " & resp.StatusCode)
If (resp.StatusCode = 401) Then
Debug.WriteLine("Refresh the saved access token or authorize again.")
End If
Exit Sub
End If
Dim created As New Chilkat.JsonObject
success = created.Load(resp.BodyStr)
If (success <> True) Then
Debug.WriteLine("Expected a JSON response.")
Exit Sub
End If
If ((created.JsonTypeOf("contact_id") <> 1) Or (created.StringOfEquals("contact_id","",True) = True)) Then
Debug.WriteLine("Missing contact_id in the response.")
Exit Sub
End If
Debug.WriteLine("Created contact ID: " & created.StringOf("contact_id"))