Dart
Dart
effectconnect Product Update
See more effectconnect Examples
Use this call to update a product (f.e. stock or price) in EffectConnect.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 uri = '/products';
final apiVersion = '2.0';
final http = CkHttp();
final req = CkHttpRequest();
// Use your effectconnect public key here...
req.addHeader('KEY', 'PUBLIC_KEY');
req.addHeader('VERSION', apiVersion);
req.addHeader('URI', uri);
req.addHeader('RESPONSETYPE', 'XML');
req.addHeader('RESPONSELANGUAGE', 'en');
// Get the current date/time in timestamp format.
final dt = CkDateTime();
dt.setFromCurrentSystemTime();
final timestamp = dt.getAsTimestamp(true);
req.addHeader('TIME', timestamp);
print('timestamp = $timestamp');
final sbXml = CkStringBuilder();
sbXml.loadFile('qa_data/xml/effectconnect/effconUpdate.xml', 'utf-8');
print('length = ${sbXml.length}');
req.httpVerb = 'PUT';
req.path = uri;
req.contentType = 'multipart/form-data';
try {
req.addStringForUpload('payload', 'effconUpdate.xml', sbXml.getAsString(), 'utf-8');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Build a string-to-sign and sign it using our effectconnect private key
final sbStringToSign = CkStringBuilder();
sbStringToSign.appendInt(sbXml.length);
sbStringToSign.append('PUT');
sbStringToSign.append(uri);
sbStringToSign.append(apiVersion);
sbStringToSign.append(timestamp);
final crypt = CkCrypt2();
crypt.macAlgorithm = 'hmac';
crypt.hashAlgorithm = 'sha512';
crypt.encodingMode = 'base64';
// Use your effectconnect private key here:
crypt.setMacKeyString('PRIVATE_KEY');
req.addHeader('SIGNATURE', crypt.macStringENC(sbStringToSign.getAsString()));
final resp = CkHttpResponse();
try {
http.httpSReq('submit.effectconnect.com', 443, true, req, resp);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('response status code = ${resp.statusCode}');
// Examine the response. The response status code can be 200 for both errors and success.
// The success or error is based on the XML returned in the response body.
final xmlResp = CkXml();
xmlResp.loadXml(resp.bodyStr);
print('response body:');
print(xmlResp.getXml());
// A sample response:
// <?xml version="1.0" encoding="utf-8"?>
// <ApiResponseContainer>
// <Request>
// <RequestType>Products</RequestType>
// <RequestAction>Update</RequestAction>
// <RequestVersion>2.0</RequestVersion>
// <RequestIdentifier/>
// <ProcessedAt>2019-04-18T15:37:32+02:00</ProcessedAt>
// </Request>
// <Response>
// <Result>Success</Result>
// <ProductsUpdateResponseContainer>
// <ProcessID><![CDATA[f81ngzD2S7gooFk3]]></ProcessID>
// </ProductsUpdateResponseContainer>
// </Response>
// </ApiResponseContainer>
//
final tagPath = '';
final requestType = xmlResp.getChildContent('Request|RequestType');
final requestAction = xmlResp.getChildContent('Request|RequestAction');
final requestVersion = xmlResp.getChildContent('Request|RequestVersion');
final processedAt = xmlResp.getChildContent('Request|ProcessedAt');
final result = xmlResp.getChildContent('Response|Result');
final processID = xmlResp.getChildContent('Response|ProductsUpdateResponseContainer|ProcessID');
}