readInventoryCount method

Future<InventoryResponse> readInventoryCount({
  1. required String catalogObjectId,
  2. InventoryCountRequest? request,
  3. String? authToken,
})

Retrieves the current calculated stock count for a given CatalogObject at a given set of Locations.

Responses are paginated and unsorted. For more sophisticated queries, use a batch endpoint.

Implementation

Future<InventoryResponse> readInventoryCount({
  required String catalogObjectId,
  InventoryCountRequest? 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/inventory/$catalogObjectId", request?.toJson().toQueryParam());

  //print (endpoint.toString());

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

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