createItem method

Future<Item> createItem({
  1. required Item item,
  2. String? realmId,
  3. String? authToken,
})

Creates an item

Implementation

Future<Item> createItem({
  required Item item,
  String? realmId,
  String? authToken,
}) async {

  authToken ??= authenticationService.getCachedToken()?.access_token;
  realmId ??= authenticationService.getCachedRealmId();

  Map<String, String> headers = {
    "Authorization": "Bearer ${authToken ?? ""}",
    'Content-Type': 'application/json; charset=UTF-8',
    'Accept': 'application/json',

  };

  Map<String, String> params = {
    "minorversion": minorVersion.toString()
  };


  Uri endpoint = Uri.https(
      baseUrl, "/v3/company/$realmId/item", params);

  //print (endpoint.toString());

  var response = await
  http.post(endpoint, body: jsonEncode(item.toJson()), headers: headers);

  if (response.statusCode == 200) {
    //print (jsonDecode(response.body));
    return Item.fromJson(jsonDecode(response.body)["Item"]);
  }
  else {
    throw ItemException(statusCode: response.statusCode, message: response.body);
  }
}