Zig
Zig
Akeneo: Create New Attribute
See more HTTP Misc Examples
Demonstrates how to create a new attribute.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 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": "release_date",
// "type": "pim_catalog_date",
// "group": "marketing",
// "unique": false,
// "useable_as_grid_filter": true,
// "allowed_extensions": [],
// "metric_family": null,
// "default_metric_unit": null,
// "reference_data_name": null,
// "available_locales": [],
// "max_characters": null,
// "validation_rule": null,
// "validation_regexp": null,
// "wysiwyg_enabled": null,
// "number_min": null,
// "number_max": null,
// "decimals_allowed": null,
// "negative_allowed": null,
// "date_min": "2017-06-28T08:00:00",
// "date_max": "2017-08-08T22:00:00",
// "max_file_size": null,
// "minimum_input_length": null,
// "sort_order": 1,
// "localizable": false,
// "scopable": false,
// "labels": {
// "en_US": "Sale date",
// "fr_FR": "Date des soldes"
// }
// }
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("code", "release_date") catch {};
json.updateString("type", "pim_catalog_date") catch {};
json.updateString("group", "marketing") catch {};
json.updateBool("unique", false) catch {};
json.updateBool("useable_as_grid_filter", true) catch {};
json.updateNewArray("allowed_extensions") catch {};
json.updateNull("metric_family") catch {};
json.updateNull("default_metric_unit") catch {};
json.updateNull("reference_data_name") catch {};
json.updateNewArray("available_locales") catch {};
json.updateNull("max_characters") catch {};
json.updateNull("validation_rule") catch {};
json.updateNull("validation_regexp") catch {};
json.updateNull("wysiwyg_enabled") catch {};
json.updateNull("number_min") catch {};
json.updateNull("number_max") catch {};
json.updateNull("decimals_allowed") catch {};
json.updateNull("negative_allowed") catch {};
json.updateString("date_min", "2017-06-28T08:00:00") catch {};
json.updateString("date_max", "2017-08-08T22:00:00") catch {};
json.updateNull("max_file_size") catch {};
json.updateNull("minimum_input_length") catch {};
json.updateNumber("sort_order", "1") catch {};
json.updateBool("localizable", false) catch {};
json.updateBool("scopable", false) catch {};
json.updateString("labels.en_US", "Sale date") catch {};
json.updateString("labels.fr_FR", "Date des soldes") 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/attributes";
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;
};
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)});
}