readCatalogInfo method

Future<CatalogInfoResponse> readCatalogInfo({
  1. required UpdateCatalogImageRequest request,
  2. required String imageId,
  3. String? authToken,
})

Retrieves information about the Square Catalog API, such as batch size limits that can be used by the BatchUpsertCatalogObjects endpoint

Implementation

Future<CatalogInfoResponse> readCatalogInfo({
  required UpdateCatalogImageRequest request,
  required String imageId,
  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/info");

  //print (endpoint.toString());

  var response = await
  http.put(endpoint, body: jsonEncode(request),  headers: headers);

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