Sample code for 30+ languages & platforms
Zig Requires Chilkat v11.0.0+

Akeneo: Create New Attribute Group

See more HTTP Misc Examples

Demonstrates how to create a new attribute group.

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();

    // Use your previously obtained access token.
    // See Get Akeneo Access Token
    http.setAuthToken("access_token");

    // Build the following JSON to be sent in the request body:
    // Use this online tool to generate the code from sample JSON:
    // Generate Code to Create JSON

    // {
    //   "code": "marketing",
    // }

    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    json.updateString("code", "marketing") catch {};

    json.setEmitCompact(false);
    // Show the JSON to be sent..
    std.debug.print("{s}\n", .{try json.emit(alloc)});

    const url = "http://pim.my-akeneo-site.com/api/rest/v1/attribute-groups";
    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpJson("POST", url, json, "application/json", resp) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    // Success is a 201 response status code with an empty body.
    std.debug.print("Response Status Code: {d}\n", .{resp.getStatusCode()});
    std.debug.print("Response Body: \n", .{});
    std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});
}