Zig
Zig
Constant Contact - Get Contact by Email Address
See more Constant Contact Examples
Get the contact details for a given email address.Chilkat 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?email=new_contact_email&status=all' \
// -H 'Accept: application/json' \
// -H 'Authorization: Bearer ACCESS_TOKEN' \
// -H 'Content-Type: application/json' \
// -H 'Postman-Token: 98980ee6-b99f-41a9-9a7a-3b5651d2ea7f' \
// -H 'cache-control: no-cache'
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
http.setRequestHeader("Accept", "application/json");
// Adds the "Authorization: Bearer ACCESS_TOKEN" header.
http.setAuthToken("ACCESS_TOKEN");
http.setRequestHeader("Postman-Token", "98980ee6-b99f-41a9-9a7a-3b5651d2ea7f");
http.setRequestHeader("Content-Type", "application/json");
http.setRequestHeader("cache-control", "no-cache");
const sb_response_body = try chilkat.StringBuilder.init();
defer sb_response_body.deinit();
http.quickGetSb("https://api.cc.email/v3/contacts?email=danipper@example.com&status=all", 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": "8207fa8e-13dd-11eb-8a66-fa163e37306a",
// "email_address": {
// "address": "danipper@example.com",
// "permission_to_send": "implicit",
// "created_at": "2020-10-21T20:39:25Z",
// "updated_at": "2020-10-21T20:39:25Z",
// "opt_in_source": "Account",
// "opt_in_date": "2020-10-21T20:39:25Z",
// "confirm_status": "off"
// },
// "first_name": "David",
// "last_name": "Nipper",
// "job_title": "Musician",
// "company_name": "Acme Corp.",
// "birthday_month": 11,
// "birthday_day": 24,
// "anniversary": "2006-11-15",
// "create_source": "Account",
// "created_at": "2020-10-21T20:39:25Z",
// "updated_at": "2020-10-21T20:39:25Z"
// }
// ]
// }
// 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 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 create_source: [:0]const u8 = "";
var created_at: [:0]const u8 = "";
var updated_at: [: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");
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");
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");
i = i + 1;
}
}