Dart
Dart
ShopwareDelete Product
See more Shopware Examples
Deletes a product in Shopware.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final http = CkHttp();
http.login = 'api_username';
http.password = 'api_key';
http.basicAuth = true;
// The id of the product is appended to the path part of the URL.
http.setUrlVar('id', '8312');
final url = 'https://my-shopware-shop.com/api/articles/{\$id}';
// Send a DELETE request with nothing in the request body.
final resp = CkHttpResponse();
try {
http.httpNoBody('DELETE', url, resp);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
final sbResponseBody = CkStringBuilder();
resp.getBodySb(sbResponseBody);
final jResp = CkJsonObject();
jResp.loadSb(sbResponseBody);
jResp.emitCompact = false;
print('Response Body:');
print(jResp.emit());
// A 200 response code indicates success (i.e. the request was sent and a response was received).
final respStatusCode = resp.statusCode;
print('Response Status Code = $respStatusCode');
if (respStatusCode >= 400) {
print('Response Header:');
print(resp.header);
print('Failed.');
return;
}
// Sample JSON response:
// {
// "success": true
// }
final bDeleted = jResp.boolOf('success');
print('Deleted: $bDeleted');
// A failed response would look like this:
// {
// "success": false,
// "message": "Product by \"id\" 8312 not found"
// }
}