Zig
Zig
Clickatell Send SMS Text Message using HTTP GET
See more Clickatell Examples
Demonstrate how to send a Clickatell SMS text message using an HTTP GET request with query params.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 -G https://api.clickatell.com/http/sendmsg \
// -d "api_id=xxxx" \
// -d "user=yourUsername" \
// -d "password=yourPassword" \
// -d "from=yourFromPhoneNumber" \
// -d "to=receiverPhoneNumber" \
// -d "text=The text of your message"
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
const query_params = try chilkat.JsonObject.init();
defer query_params.deinit();
query_params.updateString("api_id", "xxxx") catch {};
query_params.updateString("user", "yourUsername") catch {};
query_params.updateString("password", "yourPassword") catch {};
query_params.updateString("from", "yourFromPhoneNumber") catch {};
query_params.updateString("to", "receiverPhoneNumber") catch {};
query_params.updateString("text", "The text of your message") catch {};
// If the following URL does not work, then try "https://api.clickatell.com/http/sendmsg"
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpParams("GET", "https://platform.clickatell.com/messages/http/send", query_params, resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("{d}\n", .{resp.getStatusCode()});
std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});
}