Zig
Zig
Constant Contact - View List Members
See more Constant Contact Examples
View the list membership by making a GET call to the Contact Collection endpointlChilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// Implements the following CURL command:
// curl -X GET \
// 'https://api.cc.email/v3/contacts?lists={list_id},{list_id2}' \
// -H 'accept: application/json' \
// -H 'authorization: Bearer {access_token}' \
// -H 'cache-control: no-cache' \
// -H 'content-type: application/json'
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
http.setRequestHeader("content-type", "application/json");
// Adds the "Authorization: Bearer ACCESS_TOKEN" header.
http.setAuthToken("ACCESS_TOKEN");
http.setRequestHeader("cache-control", "no-cache");
http.setRequestHeader("accept", "application/json");
const sb_response_body = try chilkat.StringBuilder.init();
defer sb_response_body.deinit();
http.quickGetSb("https://api.cc.email/v3/contacts?lists={list_id},{list_id2}", sb_response_body) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const j_resp = try chilkat.JsonObject.init();
defer j_resp.deinit();
j_resp.loadSb(sb_response_body) catch {};
j_resp.setEmitCompact(false);
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try j_resp.emit(alloc)});
const resp_status_code = http.getLastStatus();
std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
if (resp_status_code >= 400) {
std.debug.print("Response Header:\n", .{});
std.debug.print("{s}\n", .{try http.getLastHeader(alloc)});
std.debug.print("Failed.\n", .{});
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "contacts": [
// {
// "contact_id": "{contact_id}",
// "email_address": {
// "address": "dprice@example.com",
// "permission_to_send": "implicit",
// "created_at": "2013-11-26T15:45:42-05:00",
// "updated_at": "2013-11-26T15:45:42-05:00",
// "opt_in_source": "Account",
// "opt_in_date": "2013-11-26T15:45:42-05:00",
// "confirm_status": "off"
// },
// "first_name": "David",
// "last_name": "Price",
// "update_source": "Account",
// "create_source": "Account",
// "created_at": "2013-11-26T15:45:42-05:00",
// "updated_at": "2017-09-06T15:48:31-04:00"
// },
// {
// "contact_id": "{contact_id}",
// "email_address": {
// "address": "jprice@example.com",
// "permission_to_send": "implicit",
// "created_at": "2013-11-26T15:45:50-05:00",
// "updated_at": "2013-11-26T15:45:50-05:00",
// "opt_in_source": "Account",
// "opt_in_date": "2013-11-26T15:45:50-05:00",
// "confirm_status": "off"
// },
// "first_name": "Jennifer",
// "last_name": "Price",
// "create_source": "Account",
// "created_at": "2013-11-26T15:45:50-05:00",
// "updated_at": "2013-11-26T15:45:50-05:00"
// },
// {
// "contact_id": "{contact_id}",
// "email_address": {
// "address": "joe.jones@example.com",
// "permission_to_send": "implicit",
// "created_at": "2017-11-06T15:35:30-05:00",
// "updated_at": "2017-11-06T15:35:30-05:00",
// "opt_in_source": "Account",
// "opt_in_date": "2017-11-06T15:35:30-05:00",
// "confirm_status": "off"
// },
// "first_name": "Joe",
// "last_name": "Jones",
// "job_title": "Chief Innovation Officer",
// "company_name": "RelativeGravity, Inc.",
// "birthday_month": 11,
// "birthday_day": 24,
// "anniversary": "2006-11-15",
// "create_source": "Account",
// "created_at": "2017-11-06T15:35:30-05:00",
// "updated_at": "2017-11-06T15:35:30-05:00"
// },
// {
// "contact_id": "{contact_id}",
// "email_address": {
// "address": "mmiller@example.com",
// "permission_to_send": "implicit",
// "created_at": "2013-11-26T15:46:04-05:00",
// "updated_at": "2013-11-26T15:46:04-05:00",
// "opt_in_source": "Account",
// "opt_in_date": "2013-11-26T15:46:04-05:00",
// "confirm_status": "off"
// },
// "first_name": "Mike",
// "last_name": "Miller.",
// "create_source": "Account",
// "created_at": "2013-11-26T15:46:04-05:00",
// "updated_at": "2013-11-26T15:46:04-05:00"
// },
// {
// "contact_id": "{contact_id}",
// "email_address": {
// "address": "sheryl.kavanaugh@example.com",
// "permission_to_send": "implicit",
// "created_at": "2013-11-26T15:46:10-05:00",
// "updated_at": "2013-11-26T15:46:10-05:00",
// "opt_in_source": "Account",
// "opt_in_date": "2013-11-26T15:46:10-05:00",
// "confirm_status": "off"
// },
// "first_name": "Sheryl",
// "last_name": "Kavanaugh",
// "create_source": "Account",
// "created_at": "2013-11-26T15:46:10-05:00",
// "updated_at": "2013-11-26T15:46:10-05:00"
// }
// ]
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
var contact_id: [:0]const u8 = "";
var email_address_address: [:0]const u8 = "";
var email_address_permission_to_send: [:0]const u8 = "";
var email_address_created_at: [:0]const u8 = "";
var email_address_updated_at: [:0]const u8 = "";
var email_address_opt_in_source: [:0]const u8 = "";
var email_address_opt_in_date: [:0]const u8 = "";
var email_address_confirm_status: [:0]const u8 = "";
var first_name: [:0]const u8 = "";
var last_name: [:0]const u8 = "";
var update_source: [:0]const u8 = "";
var create_source: [:0]const u8 = "";
var created_at: [:0]const u8 = "";
var updated_at: [:0]const u8 = "";
var job_title: [:0]const u8 = "";
var company_name: [:0]const u8 = "";
var birthday_month: i32 = 0;
var birthday_day: i32 = 0;
var anniversary: [:0]const u8 = "";
var i: i32 = 0;
const count_i = j_resp.sizeOfArray("contacts");
while (i < count_i) {
j_resp.setI(i);
contact_id = try j_resp.stringOf(alloc, "contacts[i].contact_id");
email_address_address = try j_resp.stringOf(alloc, "contacts[i].email_address.address");
email_address_permission_to_send = try j_resp.stringOf(alloc, "contacts[i].email_address.permission_to_send");
email_address_created_at = try j_resp.stringOf(alloc, "contacts[i].email_address.created_at");
email_address_updated_at = try j_resp.stringOf(alloc, "contacts[i].email_address.updated_at");
email_address_opt_in_source = try j_resp.stringOf(alloc, "contacts[i].email_address.opt_in_source");
email_address_opt_in_date = try j_resp.stringOf(alloc, "contacts[i].email_address.opt_in_date");
email_address_confirm_status = try j_resp.stringOf(alloc, "contacts[i].email_address.confirm_status");
first_name = try j_resp.stringOf(alloc, "contacts[i].first_name");
last_name = try j_resp.stringOf(alloc, "contacts[i].last_name");
update_source = try j_resp.stringOf(alloc, "contacts[i].update_source");
create_source = try j_resp.stringOf(alloc, "contacts[i].create_source");
created_at = try j_resp.stringOf(alloc, "contacts[i].created_at");
updated_at = try j_resp.stringOf(alloc, "contacts[i].updated_at");
job_title = try j_resp.stringOf(alloc, "contacts[i].job_title");
company_name = try j_resp.stringOf(alloc, "contacts[i].company_name");
birthday_month = j_resp.intOf("contacts[i].birthday_month");
birthday_day = j_resp.intOf("contacts[i].birthday_day");
anniversary = try j_resp.stringOf(alloc, "contacts[i].anniversary");
i = i + 1;
}
}