Dart Requires Chilkat v11.0.0+
Dart
Shopify Query a variant for its inventory item ID
See more Shopify Examples
Query a product variant to find the ID of its inventory item.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final http = CkHttp();
http.login = 'SHOPIFY_PRIVATE_API_KEY';
http.password = 'SHOPIFY_PRIVATE_API_KEY';
http.accept = 'application/json';
final resp = CkHttpResponse();
try {
http.httpNoBody('GET', 'https://{shop}.myshopify.com/admin/api/2020-04/products/{product_id}/variants/{variant_id}.json', resp);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('Response Status Code: ${resp.statusCode}');
final jsonResponse = CkJsonObject();
jsonResponse.load(resp.bodyStr);
jsonResponse.emitCompact = false;
print(jsonResponse.emit());
if (resp.statusCode != 200) {
print('Failed.');
return;
}
// Sample output...
// (See the parsing code below..)
//
// Use the this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// {
// "id": 12195009364024,
// "product_id": 1321541042232,
// "title": "xs",
// ...
// "inventory_item_id": 12250274365496,
// ...
// "admin_graphql_api_id": "gid://shopify/ProductVariant/12195009364024"
// }
//
final id = jsonResponse.intOf('id');
final productId = jsonResponse.intOf('product_id');
final title = jsonResponse.stringOf('title');
final inventoryItemId = jsonResponse.intOf('inventory_item_id');
final adminGraphqlApiId = jsonResponse.stringOf('admin_graphql_api_id');
}