Sample code for 30+ languages & platforms
Dart

Akeneo: Create New Attribute

See more HTTP Misc Examples

Demonstrates how to create a new attribute.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

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

  final http = CkHttp();

  // 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"
  //   }
  // }

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

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

  final url = 'http://pim.my-akeneo-site.com/api/rest/v1/attributes';
  final resp = CkHttpResponse();
  try {
    http.httpJson('POST', url, json, 'application/json', resp);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print('Response Status Code: ${resp.statusCode}');
  print('Response Body: ');
  print(resp.bodyStr);
}