getAllProducts method

Future<PrintifyGetShopProductsResponse> getAllProducts({
  1. required String baseUrl,
})

Gets all products from Printify.

Implementation

Future<PrintifyGetShopProductsResponse> getAllProducts({
  required String baseUrl,
}) async {
  Response? response;

  try {
    final dio = Dio(
      BaseOptions(
        contentType: 'application/json',
        responseType: ResponseType.json,
        baseUrl: 'https://$baseUrl/app',
      ),
    );
    response = await dio.get(
      '/getAllProducts',
      queryParameters: {},
    );

    if (response.statusCode == 200) {
      return PrintifyGetShopProductsResponse.fromJson(response.data);
    } else {
      throw Exception(
          'Non 200 return code for getting articles. Response: ${response.statusCode}');
    }
  } catch (e) {
    throw Exception(
        'Non 200 return code for getting articles. Response: ${response?.statusCode}');
  }
}