Xbase++ Requires Chilkat v11.0.0+
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oVault
LOCAL oEntry
LOCAL oTokens
LOCAL nLoaded
LOCAL oHttp
LOCAL oResp
LOCAL oBody
LOCAL oCreated
nSuccess := 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
oVault := CreateObject("Chilkat.Secrets")
oVault:Location := "local_manager"
oVault:AutoSplit := 1
oEntry := CreateObject("Chilkat.JsonObject")
oEntry:UpdateString("appName", "ConstantContactV3")
oEntry:UpdateString("service", "OAuth2")
oEntry:UpdateString("username", "my-account")
oTokens := CreateObject("Chilkat.JsonObject")
nLoaded := oVault:GetSecretJson(oEntry, oTokens)
IF (nLoaded != 1)
? "Run the desktop authorization example using this account and store."
oVault:destroy()
oEntry:destroy()
oTokens:destroy()
RETURN
ENDIF
IF (oTokens:JsonTypeOf("access_token") != 1)
? "The saved authorization has no access token."
oVault:destroy()
oEntry:destroy()
oTokens:destroy()
RETURN
ENDIF
oHttp := CreateObject("Chilkat.Http")
oHttp:RequireSslCertVerify := 1
oHttp:AuthToken := oTokens:StringOf("access_token")
oResp := CreateObject("Chilkat.HttpResponse")
oBody := CreateObject("Chilkat.JsonObject")
oBody:UpdateString("name", "Workshop announcements")
oBody:UpdateString("description", "People who requested workshop updates")
nSuccess := oHttp:HttpJson("POST", "https://api.cc.email/v3/contact_lists", oBody, "application/json", oResp)
IF (oResp:StatusCode == 409)
? "A conflicting list already exists. Check the existing lists before retrying."
oVault:destroy()
oEntry:destroy()
oTokens:destroy()
oHttp:destroy()
oResp:destroy()
oBody:destroy()
RETURN
ENDIF
IF ((nSuccess != 1) .OR. (oResp:StatusCode != 201))
? "Expected HTTP 201. Received " + Str(oResp:StatusCode)
IF (oResp:StatusCode == 401)
? "Refresh the saved access token or authorize again."
ENDIF
oVault:destroy()
oEntry:destroy()
oTokens:destroy()
oHttp:destroy()
oResp:destroy()
oBody:destroy()
RETURN
ENDIF
oCreated := CreateObject("Chilkat.JsonObject")
nSuccess := oCreated:Load(oResp:BodyStr)
IF (nSuccess != 1)
? "Expected a JSON response."
oVault:destroy()
oEntry:destroy()
oTokens:destroy()
oHttp:destroy()
oResp:destroy()
oBody:destroy()
oCreated:destroy()
RETURN
ENDIF
IF ((oCreated:JsonTypeOf("list_id") != 1) .OR. (oCreated:StringOfEquals("list_id", "", 1) == 1))
? "Missing list_id in the response."
oVault:destroy()
oEntry:destroy()
oTokens:destroy()
oHttp:destroy()
oResp:destroy()
oBody:destroy()
oCreated:destroy()
RETURN
ENDIF
? "Created " + oCreated:StringOf("name") + ". List ID: " + oCreated:StringOf("list_id")
oVault:destroy()
oEntry:destroy()
oTokens:destroy()
oHttp:destroy()
oResp:destroy()
oBody:destroy()
oCreated:destroy()