getCardsByIdentifiers method

Future<CardList> getCardsByIdentifiers(
  1. List<CardIdentifier> identifiers
)

POST /cards/collection

Returns a CardList containing a List of MtgCards identified by identifiers.

A maximum of 75 card references may be submitted per request.

identifiers: A List of CardIdentifiers.

Implementation

Future<CardList> getCardsByIdentifiers(
  List<CardIdentifier> identifiers,
) async {
  final url = Uri.https(_baseUrl, '/cards/collection');
  final body = jsonEncode({
    'identifiers': identifiers.map((i) => i.toJson()).toList(),
  });
  final response = await _httpClient.post(
    url,
    body: body,
    headers: {'Content-Type': 'application/json'},
  );

  final json = jsonDecode(response.body) as Map<String, dynamic>;

  if (response.statusCode != 200) {
    throw ScryfallException.fromJson(json);
  }

  return CardList.fromJson(json);
}