Zig Requires Chilkat v11.0.0+
Zig
Activix CRM Create a Communication
See more Activix CRM Examples
Create a communication. Returns the created communication.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 requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
http.setAuthToken("ACCESS_TOKEN");
http.setAccept("application/json");
// The following JSON is sent in the request body:
// {
// "lead_id": "LEAD_ID",
// "method": "phone",
// "type": "outgoing",
// "call_status": "calling"
// }
// Use this online tool to generate the code from sample JSON:
// Generate Code to Create JSON
const json_request_body = try chilkat.JsonObject.init();
defer json_request_body.deinit();
json_request_body.updateString("lead_id", "LEAD_ID") catch {};
json_request_body.updateString("method", "phone") catch {};
json_request_body.updateString("type", "outgoing") catch {};
json_request_body.updateString("call_status", "calling") catch {};
const url = "https://crm.activix.ca/api/v2/communications";
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpJson("POST", url, json_request_body, "application/json", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("Response Status Code: {d}\n", .{resp.getStatusCode()});
const json_response = try chilkat.JsonObject.init();
defer json_response.deinit();
json_response.load(try resp.getBodyStr(alloc)) catch {};
json_response.setEmitCompact(false);
std.debug.print("{s}\n", .{try json_response.emit(alloc)});
if (resp.getStatusCode() >= 300) {
std.debug.print("Failed.\n", .{});
return;
}
// Sample output...
// (See the parsing code below..)
//
// Use the this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// {
// "data": {
// "id": 5411998,
// "created_at": "2019-06-10T13:01:40+00:00",
// "updated_at": "2019-06-10T13:01:40+00:00",
// "lead_id": 7135833,
// "user_id": 13705,
// "method": "phone",
// "type": "outgoing",
// "email_subject": null,
// "email_body": null,
// "email_client": null,
// "email_user": null,
// "call_duration": null,
// "call_phone": null,
// "call_status": "calling"
// }
// }
//
_ = json_response.intOf("data.id");
_ = try json_response.stringOf(alloc, "data.created_at");
_ = try json_response.stringOf(alloc, "data.updated_at");
_ = json_response.intOf("data.lead_id");
_ = json_response.intOf("data.user_id");
_ = try json_response.stringOf(alloc, "data.method");
_ = try json_response.stringOf(alloc, "data.type");
_ = try json_response.stringOf(alloc, "data.email_subject");
_ = try json_response.stringOf(alloc, "data.email_body");
_ = try json_response.stringOf(alloc, "data.email_client");
_ = try json_response.stringOf(alloc, "data.email_user");
_ = try json_response.stringOf(alloc, "data.call_duration");
_ = try json_response.stringOf(alloc, "data.call_phone");
_ = try json_response.stringOf(alloc, "data.call_status");
}