Sample code for 30+ languages & platforms
Swift

Akeneo: Create New Attribute

See more HTTP Misc Examples

Demonstrates how to create a new attribute.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let http = CkoHttp()!

    // Use your previously obtained access token.
    // See Get Akeneo Access Token
    http.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"
    //   }
    // }

    let json = CkoJsonObject()!
    json.updateString(jsonPath: "code", value: "release_date")
    json.updateString(jsonPath: "type", value: "pim_catalog_date")
    json.updateString(jsonPath: "group", value: "marketing")
    json.updateBool(jsonPath: "unique", value: false)
    json.updateBool(jsonPath: "useable_as_grid_filter", value: true)
    json.updateNewArray(jsonPath: "allowed_extensions")
    json.updateNull(jsonPath: "metric_family")
    json.updateNull(jsonPath: "default_metric_unit")
    json.updateNull(jsonPath: "reference_data_name")
    json.updateNewArray(jsonPath: "available_locales")
    json.updateNull(jsonPath: "max_characters")
    json.updateNull(jsonPath: "validation_rule")
    json.updateNull(jsonPath: "validation_regexp")
    json.updateNull(jsonPath: "wysiwyg_enabled")
    json.updateNull(jsonPath: "number_min")
    json.updateNull(jsonPath: "number_max")
    json.updateNull(jsonPath: "decimals_allowed")
    json.updateNull(jsonPath: "negative_allowed")
    json.updateString(jsonPath: "date_min", value: "2017-06-28T08:00:00")
    json.updateString(jsonPath: "date_max", value: "2017-08-08T22:00:00")
    json.updateNull(jsonPath: "max_file_size")
    json.updateNull(jsonPath: "minimum_input_length")
    json.updateNumber(jsonPath: "sort_order", numericStr: "1")
    json.updateBool(jsonPath: "localizable", value: false)
    json.updateBool(jsonPath: "scopable", value: false)
    json.updateString(jsonPath: "labels.en_US", value: "Sale date")
    json.updateString(jsonPath: "labels.fr_FR", value: "Date des soldes")

    json.emitCompact = false
    // Show the JSON to be sent..
    print("\(json.emit()!)")

    var url: String? = "http://pim.my-akeneo-site.com/api/rest/v1/attributes"
    let resp = CkoHttpResponse()!
    success = http.httpJson(verb: "POST", url: url, json: json, contentType: "application/json", response: resp)
    if success == false {
        print("\(http.lastErrorText!)")
        return
    }

    print("Response Status Code: \(resp.statusCode.intValue)")
    print("Response Body: ")
    print("\(resp.bodyStr!)")

}