Sample code for 30+ languages & platforms
AutoIt Requires Chilkat v11.0.0+

Constant Contact V3: Create a contact list

See more Constant Contact Examples

Create a list with a unique name and a short description. Save the returned list_id with your application’s list record and use it in the membership examples. The new list starts empty. Authorize the app first and use the same credential store.

Constant Contact developer guide

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

;  Assumes Chilkat is unlocked. See Global Unlock Sample.
$oVault = ObjCreate("Chilkat.Secrets")
$oVault.Location = "local_manager"
$oVault.AutoSplit = True
$oEntry = ObjCreate("Chilkat.JsonObject")
$oEntry.UpdateString("appName","ConstantContactV3")
$oEntry.UpdateString("service","OAuth2")
$oEntry.UpdateString("username","my-account")
$oTokens = ObjCreate("Chilkat.JsonObject")
Local $bLoaded = $oVault.GetSecretJson($oEntry,$oTokens)
If ($bLoaded <> True) Then
    ConsoleWrite("Run the desktop authorization example using this account and store." & @CRLF)
    Exit
EndIf

If ($oTokens.JsonTypeOf("access_token") <> 1) Then
    ConsoleWrite("The saved authorization has no access token." & @CRLF)
    Exit
EndIf

$oHttp = ObjCreate("Chilkat.Http")
$oHttp.RequireSslCertVerify = True
$oHttp.AuthToken = $oTokens.StringOf("access_token")
$oResp = ObjCreate("Chilkat.HttpResponse")

$oBody = ObjCreate("Chilkat.JsonObject")
$oBody.UpdateString("name","Workshop announcements")
$oBody.UpdateString("description","People who requested workshop updates")
$bSuccess = $oHttp.HttpJson("POST","https://api.cc.email/v3/contact_lists",$oBody,"application/json",$oResp)
If ($oResp.StatusCode = 409) Then
    ConsoleWrite("A conflicting list already exists. Check the existing lists before retrying." & @CRLF)
    Exit
EndIf

If (($bSuccess <> True) Or ($oResp.StatusCode <> 201)) Then
    ConsoleWrite("Expected HTTP 201. Received " & $oResp.StatusCode & @CRLF)
    If ($oResp.StatusCode = 401) Then
        ConsoleWrite("Refresh the saved access token or authorize again." & @CRLF)
    EndIf

    Exit
EndIf

$oCreated = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oCreated.Load($oResp.BodyStr)
If ($bSuccess <> True) Then
    ConsoleWrite("Expected a JSON response." & @CRLF)
    Exit
EndIf

If (($oCreated.JsonTypeOf("list_id") <> 1) Or ($oCreated.StringOfEquals("list_id","",True) = True)) Then
    ConsoleWrite("Missing list_id in the response." & @CRLF)
    Exit
EndIf

ConsoleWrite("Created " & $oCreated.StringOf("name") & ". List ID: " & $oCreated.StringOf("list_id") & @CRLF)