PowerBuilder Requires Chilkat v11.0.0+
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Vault
oleobject loo_Entry
oleobject loo_Tokens
long li_Loaded
oleobject loo_Http
oleobject loo_Resp
oleobject loo_Body
oleobject loo_Created
li_Success = 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
loo_Vault = create oleobject
li_rc = loo_Vault.ConnectToNewObject("Chilkat.Secrets")
if li_rc < 0 then
destroy loo_Vault
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Vault.Location = "local_manager"
loo_Vault.AutoSplit = 1
loo_Entry = create oleobject
li_rc = loo_Entry.ConnectToNewObject("Chilkat.JsonObject")
loo_Entry.UpdateString("appName","ConstantContactV3")
loo_Entry.UpdateString("service","OAuth2")
loo_Entry.UpdateString("username","my-account")
loo_Tokens = create oleobject
li_rc = loo_Tokens.ConnectToNewObject("Chilkat.JsonObject")
li_Loaded = loo_Vault.GetSecretJson(loo_Entry,loo_Tokens)
if li_Loaded <> 1 then
Write-Debug "Run the desktop authorization example using this account and store."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
return
end if
if loo_Tokens.JsonTypeOf("access_token") <> 1 then
Write-Debug "The saved authorization has no access token."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
return
end if
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
loo_Http.RequireSslCertVerify = 1
loo_Http.AuthToken = loo_Tokens.StringOf("access_token")
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
loo_Body = create oleobject
li_rc = loo_Body.ConnectToNewObject("Chilkat.JsonObject")
loo_Body.UpdateString("name","Workshop announcements")
loo_Body.UpdateString("description","People who requested workshop updates")
li_Success = loo_Http.HttpJson("POST","https://api.cc.email/v3/contact_lists",loo_Body,"application/json",loo_Resp)
if loo_Resp.StatusCode = 409 then
Write-Debug "A conflicting list already exists. Check the existing lists before retrying."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp
destroy loo_Body
return
end if
if (li_Success <> 1) OR (loo_Resp.StatusCode <> 201) then
Write-Debug "Expected HTTP 201. Received " + string(loo_Resp.StatusCode)
if loo_Resp.StatusCode = 401 then
Write-Debug "Refresh the saved access token or authorize again."
end if
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp
destroy loo_Body
return
end if
loo_Created = create oleobject
li_rc = loo_Created.ConnectToNewObject("Chilkat.JsonObject")
li_Success = loo_Created.Load(loo_Resp.BodyStr)
if li_Success <> 1 then
Write-Debug "Expected a JSON response."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp
destroy loo_Body
destroy loo_Created
return
end if
if (loo_Created.JsonTypeOf("list_id") <> 1) OR (loo_Created.StringOfEquals("list_id","",1) = 1) then
Write-Debug "Missing list_id in the response."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp
destroy loo_Body
destroy loo_Created
return
end if
Write-Debug "Created " + loo_Created.StringOf("name") + ". List ID: " + loo_Created.StringOf("list_id")
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp
destroy loo_Body
destroy loo_Created