Lua
Lua
Akeneo: Create New Attribute
See more HTTP Misc Examples
Demonstrates how to create a new attribute.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
-- Use your previously obtained access token.
-- See Get Akeneo Access Token
http.auth_token = "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"
-- }
-- }
local json = chilkat.JsonObject.new()
json:update_string("code", "release_date")
json:update_string("type", "pim_catalog_date")
json:update_string("group", "marketing")
json:update_bool("unique", false)
json:update_bool("useable_as_grid_filter", true)
json:update_new_array("allowed_extensions")
json:update_null("metric_family")
json:update_null("default_metric_unit")
json:update_null("reference_data_name")
json:update_new_array("available_locales")
json:update_null("max_characters")
json:update_null("validation_rule")
json:update_null("validation_regexp")
json:update_null("wysiwyg_enabled")
json:update_null("number_min")
json:update_null("number_max")
json:update_null("decimals_allowed")
json:update_null("negative_allowed")
json:update_string("date_min", "2017-06-28T08:00:00")
json:update_string("date_max", "2017-08-08T22:00:00")
json:update_null("max_file_size")
json:update_null("minimum_input_length")
json:update_number("sort_order", "1")
json:update_bool("localizable", false)
json:update_bool("scopable", false)
json:update_string("labels.en_US", "Sale date")
json:update_string("labels.fr_FR", "Date des soldes")
json.emit_compact = false
-- Show the JSON to be sent..
print(json:emit())
local url = "http://pim.my-akeneo-site.com/api/rest/v1/attributes"
local resp = chilkat.HttpResponse.new()
local success = http:http_json("POST", url, json, "application/json", resp)
if not success then
print(http.last_error_text)
return
end
print("Response Status Code: " .. resp.status_code)
print("Response Body: ")
print(resp.body_str)