Zig
Zig
ShopwareDelete Product
See more Shopware Examples
Deletes a product in Shopware.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();
http.setLogin("api_username");
http.setPassword("api_key");
http.setBasicAuth(true);
// The id of the product is appended to the path part of the URL.
http.setUrlVar("id", "8312") catch {};
const url = "https://my-shopware-shop.com/api/articles/{$id}";
// Send a DELETE request with nothing in the request body.
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpNoBody("DELETE", url, 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)});
// A 200 response code indicates success (i.e. the request was sent and a response was received).
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:
// {
// "success": true
// }
const b_deleted = j_resp.boolOf("success");
std.debug.print("Deleted: {}\n", .{b_deleted});
// A failed response would look like this:
// {
// "success": false,
// "message": "Product by \"id\" 8312 not found"
// }
}