readCatalog method

Future<CatalogResponse> readCatalog({
  1. required String objectId,
  2. String? authToken,
})

Returns a single CatalogItem as a CatalogObject based on the provided ID.

The returned object includes all of the relevant CatalogItem information including: CatalogItemVariation children, references to its CatalogModifierList objects, and the ids of any CatalogTax objects that apply to it

Implementation

Future<CatalogResponse> readCatalog({
  required String objectId,
  String? authToken,
}) async {

  authToken ??= authenticationService.getCachedToken()?.accessToken;

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

  };

  Uri endpoint = Uri.https(
      baseUrl, "/v2/catalog/object/$objectId");

  //print (endpoint.toString());

  var response = await
  http.delete(endpoint, headers: headers);

  if (response.statusCode == 200) {
    print (jsonDecode(response.body));
    return CatalogResponse.fromJson(jsonDecode(response.body));
  }
  else {
    print (response.body);
    throw CatalogException(statusCode: response.statusCode, message: CatalogResponse.fromJson(jsonDecode(response.body)).errors?[0].detail?.toString());
  }
}