PowerBuilder
PowerBuilder
Constant Contact - Add Contacts to List
See more Constant Contact Examples
Demonstrates a call to add five existing contacts to two lists.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Activity_id
string ls_State
string ls_Created_at
string ls_Updated_at
integer li_Percent_done
integer li_StatusList_count
string ls_V_linksSelfHref
integer i
integer li_Count_i
string ls_ErrMsg
li_Success = 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// Implements the following CURL command:
// curl -X POST \
// https://api.cc.email/v3/activities/add_list_memberships \
// -H 'Accept: application/json' \
// -H 'Authorization: Bearer {access_token}' \
// -H 'cache-control: no-cache' \
// -H 'content-type: application/json' \
// -d '{
// "source": {
// "contact_ids": [
// "{contact_id1}",
// "{contact_id2}",
// "{contact_id3}",
// "{contact_id4}",
// "{contact_id5}",
// "{contact_id6}"
// ]
// },
// "list_ids": [
// "{list_id1}",
// "{list_id2}"
// ]
// }'
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "source": {
// "contact_ids": [
// "{contact_id1}",
// "{contact_id2}",
// "{contact_id3}",
// "{contact_id4}",
// "{contact_id5}",
// "{contact_id6}"
// ]
// },
// "list_ids": [
// "{list_id1}",
// "{list_id2}"
// ]
// }
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("source.contact_ids[0]","{contact_id1}")
loo_Json.UpdateString("source.contact_ids[1]","{contact_id2}")
loo_Json.UpdateString("source.contact_ids[2]","{contact_id3}")
loo_Json.UpdateString("source.contact_ids[3]","{contact_id4}")
loo_Json.UpdateString("source.contact_ids[4]","{contact_id5}")
loo_Json.UpdateString("source.contact_ids[5]","{contact_id6}")
loo_Json.UpdateString("list_ids[0]","{list_id1}")
loo_Json.UpdateString("list_ids[1]","{list_id2}")
// Adds the "Authorization: Bearer ACCESS_TOKEN" header.
loo_Http.AuthToken = "ACCESS_TOKEN"
loo_Http.SetRequestHeader("content-type","application/json")
loo_Http.SetRequestHeader("Accept","application/json")
loo_Http.SetRequestHeader("cache-control","no-cache")
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Success = loo_Http.HttpJson("POST","https://api.cc.email/v3/activities/add_list_memberships",loo_Json,"application/json",loo_Resp)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
destroy loo_Resp
return
end if
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Http
destroy loo_Json
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "activity_id": "activity_id",
// "state": "initialized",
// "created_at": "2018-02-28T13:49:41-05:00",
// "updated_at": "2018-02-28T13:49:41-05:00",
// "percent_done": 1,
// "activity_errors": [
// ],
// "status": {
// "list_count": 2
// },
// "_links": {
// "self": {
// "href": "/v3/activities/activity_id"
// }
// }
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
ls_Activity_id = loo_JResp.StringOf("activity_id")
ls_State = loo_JResp.StringOf("state")
ls_Created_at = loo_JResp.StringOf("created_at")
ls_Updated_at = loo_JResp.StringOf("updated_at")
li_Percent_done = loo_JResp.IntOf("percent_done")
li_StatusList_count = loo_JResp.IntOf("status.list_count")
ls_V_linksSelfHref = loo_JResp.StringOf("_links.self.href")
i = 0
li_Count_i = loo_JResp.SizeOfArray("activity_errors")
do while i < li_Count_i
loo_JResp.I = i
ls_ErrMsg = loo_JResp.StringOf("activity_errors[i]")
i = i + 1
loop
destroy loo_Http
destroy loo_Json
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp