Zig
Zig
Square API - Delete Catalog Object
See more Square Examples
Deletes a single CatalogObject based on the provided ID and returns the set of successfully deleted IDs in the response.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 https://connect.squareup.com/v2/catalog/object/object_id0 \
// -X DELETE \
// -H 'Square-Version: 2020-07-22' \
// -H 'Authorization: Bearer ACCESS_TOKEN' \
// -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
// Adds the "Authorization: Bearer ACCESS_TOKEN" header.
http.setAuthToken("ACCESS_TOKEN");
http.setRequestHeader("Square-Version", "2020-07-22");
http.setRequestHeader("Content-Type", "application/json");
// This example uses the sandbox: connect.squareupsandbox.com
// Production should use connect.squareup.com
http.setUrlVar("object_id", "2PTZYUOFGGDMT75UZLHQAPAC") catch {};
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpNoBody("DELETE", "https://connect.squareupsandbox.com/v2/catalog/object/{$object_id}", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const sb_response_body = try chilkat.StringBuilder.init();
defer sb_response_body.deinit();
resp.getBodySb(sb_response_body) catch {};
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 = resp.getStatusCode();
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 resp.getHeader(alloc)});
std.debug.print("Failed.\n", .{});
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "deleted_object_ids": [
// "2PTZYUOFGGDMT75UZLHQAPAC",
// "KQLFFHA6K6J3YQAQAWDQAL57"
// ],
// "deleted_at": "2016-11-16T22:25:24.878Z"
// }
// 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 str_val: [:0]const u8 = "";
_ = try j_resp.stringOf(alloc, "deleted_at");
var i: i32 = 0;
const count_i = j_resp.sizeOfArray("deleted_object_ids");
while (i < count_i) {
j_resp.setI(i);
str_val = try j_resp.stringOf(alloc, "deleted_object_ids[i]");
i = i + 1;
}
}