Sample code for 30+ languages & platforms
Dart Requires Chilkat v11.0.0+

effectconnect Read Orderlist

See more effectconnect Examples

Get a set of orders filtered by the parameters in the XML payload.

Chilkat Dart Downloads

Dart
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 fullUri = 'https://submit.effectconnect.com/orderlist';
  final uri = '/orderlist';
  final apiVersion = '2.0';

  final http = CkHttp();

  // Use your effectconnect public key here..
  http.setRequestHeader('KEY', 'PUBLIC_KEY');
  http.setRequestHeader('VERSION', apiVersion);
  http.setRequestHeader('URI', uri);
  http.setRequestHeader('RESPONSETYPE', 'XML');
  http.setRequestHeader('RESPONSELANGUAGE', 'en');

  // Get the current date/time in timestamp format.
  final dt = CkDateTime();
  dt.setFromCurrentSystemTime();
  final timestamp = dt.getAsTimestamp(true);

  http.setRequestHeader('TIME', timestamp);
  print('timestamp = $timestamp');

  // Create the following XML request body:
  // <?xml version="1.0" encoding="utf-8"?>
  // <list>
  //   <filters>
  //     <fromDateFilter>
  //       <filterValue>2018-09-14T12:12:12+01:00</filterValue>
  //     </fromDateFilter>
  //     <toDateFilter>
  //       <filterValue>2019-04-13T23:59:59+01:00</filterValue>
  //     </toDateFilter>
  //     <hasStatusFilter>
  //       <filterValue>paid</filterValue>
  //     </hasStatusFilter>
  //     <hasTagFilter>
  //       <filterValue>
  //         <tagName>Test</tagName>
  //         <exclude>false</exclude>
  //       </filterValue>
  //     </hasTagFilter>
  //   </filters>
  // </list>

  // Use this online tool to generate the code from sample XML: 
  // Generate Code to Create XML

  final xml = CkXml();
  xml.tag = 'list';
  xml.updateChildContent('filters|fromDateFilter|filterValue', '2018-09-14T12:12:12+01:00');
  xml.updateChildContent('filters|toDateFilter|filterValue', '2019-04-13T23:59:59+01:00');
  xml.updateChildContent('filters|hasStatusFilter|filterValue', 'paid');
  xml.updateChildContent('filters|hasTagFilter|filterValue|tagName', 'Test');
  xml.updateChildContent('filters|hasTagFilter|filterValue|exclude', 'false');
  xml.emitCompact = true;

  final sbXml = CkStringBuilder();
  xml.getXmlSb(sbXml);

  // Build a string-to-sign and sign it using our effectconnect private key
  final sbStringToSign = CkStringBuilder();
  sbStringToSign.appendInt(sbXml.length);
  sbStringToSign.append('POST');
  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');
  http.setRequestHeader('SIGNATURE', crypt.macStringENC(sbStringToSign.getAsString()));

  // Send the POST..
  final resp = CkHttpResponse();
  try {
    http.httpStr('POST', fullUri, xml.getXml(), 'utf-8', 'application/xml', 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());

  // Remove previously set headers (unless we want the same headers for the next request,
  // in which case we may remove or update individual headers by calling SetRequestHeader.
  http.clearHeaders();
}