Dart
Dart
Shopware Update Product Data
See more Shopware Examples
Update information about an existing 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 following JSON is sent in the request body.
// {
// "name": "Super-Duper Sports Shoes"
// }
final json = CkJsonObject();
json.updateString('name', 'Super-Duper Sports Shoes');
// 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}';
final resp = CkHttpResponse();
try {
http.httpJson('PUT', url, json, 'application/json', 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.
final respStatusCode = resp.statusCode;
print('Response Status Code = $respStatusCode');
if (respStatusCode >= 400) {
print('Response Header:');
print(resp.header);
print('Failed.');
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "success": true,
// "data": {
// "id": 8312,
// "location": "https:\/\/my-shopware-shop.com\/api\/articles\/8312"
// }
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
jResp.boolOf('success');
final dataId = jResp.intOf('data.id');
final dataLocation = jResp.stringOf('data.location');
}