Sample code for 30+ languages & platforms
React Native 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 React Native Downloads

React Native
import { CkDateTime, Crypt2, Http, HttpResponse, StringBuilder, Xml } from '@chilkat/react-native'

async function chilkatExample() {
  // This example assumes the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const fullUri = 'https://submit.effectconnect.com/orderlist';
  const uri = '/orderlist';
  const apiVersion = '2.0';

  const http = new Http();

  // 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.
  const dt = new CkDateTime();
  dt.setFromCurrentSystemTime();
  const timestamp = dt.getAsTimestamp(true);

  http.setRequestHeader('TIME', timestamp);
  console.log(`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

  const xml = new Xml();
  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;

  const sbXml = new StringBuilder();
  xml.getXmlSb(sbXml);

  // Build a string-to-sign and sign it using our effectconnect private key
  const sbStringToSign = new StringBuilder();
  sbStringToSign.appendInt(sbXml.length);
  sbStringToSign.append('POST');
  sbStringToSign.append(uri);
  sbStringToSign.append(apiVersion);
  sbStringToSign.append(timestamp);

  const crypt = new Crypt2();
  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..
  const resp = new HttpResponse();
  try {
    await http.httpStrAsync('POST', fullUri, xml.getXml(), 'utf-8', 'application/xml', resp);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  console.log(`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.
  const xmlResp = new Xml();
  xmlResp.loadXml(resp.bodyStr);

  console.log('response body:');
  console.log(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();
}