Sample code for 30+ languages & platforms
PowerBuilder

Constant Contact - Restore a Deleted Contact

See more Constant Contact Examples

Restores a previously deleted contact with a given id.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Json
oleobject loo_SbRequestBody
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Contact_id
string ls_First_name
string ls_Last_name
string ls_Update_source
string ls_Create_source
string ls_Created_at
string ls_Updated_at
string ls_Email_addressAddress
string ls_Email_addressPermission_to_send
string ls_Email_addressCreated_at
string ls_Email_addressUpdated_at
string ls_Email_addressOpt_in_source
string ls_Email_addressOpt_in_date
string ls_Email_addressConfirm_status

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 PUT \
//   https://api.cc.email/v3/contacts/{contact_id} \
//   -H 'Accept: application/json' \
//   -H 'Authorization: Bearer {access_token}' \
//   -H 'Cache-Control: no-cache' \
//   -H 'Content-Type: application/json' \
//   -d '{
// 
//     "first_name": "John",
//     "last_name": "Byrd",
//     "email_address": {
//         "address": "example@example.com",
//         "permission_to_send": "explicit"
//       },
//     "update_source": "Contact",
//     "list_memberships":["{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.

// {
//   "first_name": "John",
//   "last_name": "Byrd",
//   "email_address": {
//     "address": "example@example.com",
//     "permission_to_send": "explicit"
//   },
//   "update_source": "Contact",
//   "list_memberships": [
//     "{list_id1}",
//     "{list_id2}"
//   ]
// }

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.UpdateString("first_name","John")
loo_Json.UpdateString("last_name","Byrd")
loo_Json.UpdateString("email_address.address","example@example.com")
loo_Json.UpdateString("email_address.permission_to_send","explicit")
loo_Json.UpdateString("update_source","Contact")
loo_Json.UpdateString("list_memberships[0]","{list_id1}")
loo_Json.UpdateString("list_memberships[1]","{list_id2}")

// Adds the "Authorization: Bearer ACCESS_TOKEN" header.
loo_Http.AuthToken = "ACCESS_TOKEN"
loo_Http.SetRequestHeader("Accept","application/json")
loo_Http.SetRequestHeader("Content-Type","application/json")
loo_Http.SetRequestHeader("Cache-Control","no-cache")

loo_SbRequestBody = create oleobject
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_Json.EmitSb(loo_SbRequestBody)

loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

li_Success = loo_Http.HttpSb("PUT","https://api.cc.email/v3/contacts/{contact_id}",loo_SbRequestBody,"utf-8","application/json",loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    destroy loo_SbRequestBody
    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_SbRequestBody
    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)

// {
//   "contact_id": "{contact_id}",
//   "first_name": "John",
//   "last_name": "Byrd",
//   "update_source": "Contact",
//   "create_source": "Account",
//   "created_at": "2013-04-01T15:07:07-04:00",
//   "updated_at": "2018-02-20T16:47:40-05:00",
//   "email_address": {
//     "address": "example@example.com",
//     "permission_to_send": "implicit",
//     "created_at": "2013-04-01T15:07:07-04:00",
//     "updated_at": "2018-02-20T16:47:40-05:00",
//     "opt_in_source": "Account",
//     "opt_in_date": "2015-03-17T11:13:28-04:00",
//     "confirm_status": "off"
//   }
// }

// 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_Contact_id = loo_JResp.StringOf("contact_id")
ls_First_name = loo_JResp.StringOf("first_name")
ls_Last_name = loo_JResp.StringOf("last_name")
ls_Update_source = loo_JResp.StringOf("update_source")
ls_Create_source = loo_JResp.StringOf("create_source")
ls_Created_at = loo_JResp.StringOf("created_at")
ls_Updated_at = loo_JResp.StringOf("updated_at")
ls_Email_addressAddress = loo_JResp.StringOf("email_address.address")
ls_Email_addressPermission_to_send = loo_JResp.StringOf("email_address.permission_to_send")
ls_Email_addressCreated_at = loo_JResp.StringOf("email_address.created_at")
ls_Email_addressUpdated_at = loo_JResp.StringOf("email_address.updated_at")
ls_Email_addressOpt_in_source = loo_JResp.StringOf("email_address.opt_in_source")
ls_Email_addressOpt_in_date = loo_JResp.StringOf("email_address.opt_in_date")
ls_Email_addressConfirm_status = loo_JResp.StringOf("email_address.confirm_status")


destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp