Xbase++
Xbase++
Akeneo: Create New Attribute
See more HTTP Misc Examples
Demonstrates how to create a new attribute.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oJson
LOCAL cUrl
LOCAL oResp
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// Use your previously obtained access token.
// See Get Akeneo Access Token
oHttp:AuthToken := "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"
// }
// }
oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("code", "release_date")
oJson:UpdateString("type", "pim_catalog_date")
oJson:UpdateString("group", "marketing")
oJson:UpdateBool("unique", 0)
oJson:UpdateBool("useable_as_grid_filter", 1)
oJson:UpdateNewArray("allowed_extensions")
oJson:UpdateNull("metric_family")
oJson:UpdateNull("default_metric_unit")
oJson:UpdateNull("reference_data_name")
oJson:UpdateNewArray("available_locales")
oJson:UpdateNull("max_characters")
oJson:UpdateNull("validation_rule")
oJson:UpdateNull("validation_regexp")
oJson:UpdateNull("wysiwyg_enabled")
oJson:UpdateNull("number_min")
oJson:UpdateNull("number_max")
oJson:UpdateNull("decimals_allowed")
oJson:UpdateNull("negative_allowed")
oJson:UpdateString("date_min", "2017-06-28T08:00:00")
oJson:UpdateString("date_max", "2017-08-08T22:00:00")
oJson:UpdateNull("max_file_size")
oJson:UpdateNull("minimum_input_length")
oJson:UpdateNumber("sort_order", "1")
oJson:UpdateBool("localizable", 0)
oJson:UpdateBool("scopable", 0)
oJson:UpdateString("labels.en_US", "Sale date")
oJson:UpdateString("labels.fr_FR", "Date des soldes")
oJson:EmitCompact := 0
// Show the JSON to be sent..
? oJson:Emit()
cUrl := "http://pim.my-akeneo-site.com/api/rest/v1/attributes"
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("POST", cUrl, oJson, "application/json", oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oJson:destroy()
oResp:destroy()
RETURN
ENDIF
? "Response Status Code: " + Str(oResp:StatusCode)
? "Response Body: "
? oResp:BodyStr
oHttp:destroy()
oJson:destroy()
oResp:destroy()