listCatalog method

Future<CatalogResponse> listCatalog({
  1. required ListCatalogRequest request,
  2. String? authToken,
})

Returns a list of all CatalogObjects of the specified types in the catalog.

The types parameter is specified as a comma-separated list of the CatalogObjectType values, for example, "ITEM, ITEM_VARIATION, MODIFIER, MODIFIER_LIST, CATEGORY, DISCOUNT, TAX, IMAGE".

Important: ListCatalog does not return deleted catalog items. To retrieve deleted catalog items, use SearchCatalogObjects and set the include_deleted_objects attribute value to true.

Implementation

Future<CatalogResponse> listCatalog({
  required ListCatalogRequest request,
  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/list", request.toJson().toQueryParam());

  //print (endpoint.toString());

  var response = await
  http.get(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());
  }
}