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

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Crypt2;
import com.chilkatsoft.chilkat2.DateTime;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.StringBuilder;
import com.chilkatsoft.chilkat2.Xml;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example assumes the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        String fullUri = "https://submit.effectconnect.com/orderlist";
        String uri = "/orderlist";
        String apiVersion = "2.0";

        Http 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.
        DateTime dt = new DateTime();
        dt.setFromCurrentSystemTime();
        String timestamp = dt.getAsTimestamp(true);

        http.setRequestHeader("TIME", timestamp);
        System.out.println("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

        Xml xml = new Xml();
        xml.setTag("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.setEmitCompact(true);

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

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

        Crypt2 crypt = new Crypt2();
        crypt.setMacAlgorithm("hmac");
        crypt.setHashAlgorithm("sha512");
        crypt.setEncodingMode("base64");
        // Use your effectconnect private key here:
        crypt.setMacKeyString("PRIVATE_KEY");
        http.setRequestHeader("SIGNATURE", crypt.macStringENC(sbStringToSign.getAsString()));

        // Send the POST..
        HttpResponse resp = new HttpResponse();
        try {
            http.httpStr("POST", fullUri, xml.getXml(), "utf-8", "application/xml", resp);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("response status code = " + resp.getStatusCode());

        // 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.
        Xml xmlResp = new Xml();
        xmlResp.loadXml(resp.getBodyStr());

        System.out.println("response body:");
        System.out.println(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();
    }
}