Zig
Zig
Square API - Batch Delete Catalog Objects
See more Square Examples
Deletes a set of CatalogItems based on the provided list of target IDs and returns a 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/batch-delete \
// -X POST \
// -H 'Square-Version: 2020-07-22' \
// -H 'Authorization: Bearer ACCESS_TOKEN' \
// -H 'Content-Type: application/json' \
// -d '{
// "object_ids": [
// "W62UWFY35CWMYGVWK6TWJDNI",
// "AA27W3M2GGTF3H6AVPNB77CK"
// ]
// }'
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "object_ids": [
// "W62UWFY35CWMYGVWK6TWJDNI",
// "AA27W3M2GGTF3H6AVPNB77CK"
// ]
// }
const json = try chilkat.JsonObject.init();
defer json.deinit();
var i: i32 = 0;
json.setI(i);
json.updateString("object_ids[i]", "W62UWFY35CWMYGVWK6TWJDNI") catch {};
i = i + 1;
json.setI(i);
json.updateString("object_ids[i]", "AA27W3M2GGTF3H6AVPNB77CK") catch {};
// Adds the "Authorization: Bearer ACCESS_TOKEN" header.
http.setAuthToken("ACCESS_TOKEN");
http.setRequestHeader("Square-Version", "2020-07-22");
// This example uses the sandbox: connect.squareupsandbox.com
// Production should use connect.squareup.com
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpJson("POST", "https://connect.squareupsandbox.com/v2/catalog/batch-delete", json, "application/json", 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": [
// "W62UWFY35CWMYGVWK6TWJDNI",
// "AA27W3M2GGTF3H6AVPNB77CK"
// ],
// "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");
i = 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;
}
}