Sample code for 30+ languages & platforms
Zig

Activix CRM Update a Phone

See more Activix CRM Examples

Updates a phone and returns the updated phone.

Chilkat Zig Downloads

Zig
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:

    // {
    //   "number": "+15141234459",
    //   "type": "home",
    //   "mobile": true
    // }

    // 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("number", "+15141234459") catch {};
    json_request_body.updateString("type", "home") catch {};
    json_request_body.updateBool("mobile", true) catch {};

    const url = "https://crm.activix.ca/api/v2/lead-phones/PHONE_ID";

    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpJson("PUT", 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": 34566,
    //         "created_at": "2018-04-09T18:05:00+00:00",
    //         "updated_at": "2018-04-09T18:07:00+00:00",
    //         "lead_id": 3466512,
    //         "number": "+15141234455",
    //         ...
    //     }
    // }

    _ = 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");
    _ = try json_response.stringOf(alloc, "data.extension");
    _ = try json_response.stringOf(alloc, "data.number");
    _ = try json_response.stringOf(alloc, "data.type");
    _ = json_response.boolOf("data.valid");
    _ = json_response.boolOf("data.validated");
    _ = json_response.boolOf("data.mobile");
}