Java
Chilkat2 Java
effectconnect Create or Replace Product Catalog
See more effectconnect Examples
Use this call to create or replace a product catalog in EffectConnect. This is always a purge and replace action for the entire catalog.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Crypt2;
import com.chilkatsoft.chilkat2.DateTime;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpRequest;
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 uri = "/products";
String apiVersion = "2.0";
Http http = new Http();
HttpRequest req = new HttpRequest();
// 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.
DateTime dt = new DateTime();
dt.setFromCurrentSystemTime();
String timestamp = dt.getAsTimestamp(true);
req.addHeader("TIME", timestamp);
System.out.println("timestamp = " + timestamp);
StringBuilder sbXml = new StringBuilder();
sbXml.loadFile("qa_data/xml/effectconnect/effconCreate.xml", "utf-8");
System.out.println("length = " + sbXml.getLength());
req.setHttpVerb("POST");
req.setPath(uri);
req.setContentType("multipart/form-data");
try {
req.addStringForUpload("payload", "effcon.xml", sbXml.getAsString(), "utf-8");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// 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");
req.addHeader("SIGNATURE", crypt.macStringENC(sbStringToSign.getAsString()));
HttpResponse resp = new HttpResponse();
try {
http.httpSReq("submit.effectconnect.com", 443, true, req, 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());
// A sample response:
// <?xml version="1.0" encoding="utf-8"?>
// <ApiResponseContainer>
// <Request>
// <RequestType>Products</RequestType>
// <RequestAction>Create</RequestAction>
// <RequestVersion>2.0</RequestVersion>
// <RequestIdentifier/>
// <ProcessedAt>2019-04-18T15:28:55+02:00</ProcessedAt>
// </Request>
// <Response>
// <Result>Success</Result>
// <ProductsCreateResponseContainer>
// <ProcessID><![CDATA[J048hgS4OkNn0JnH]]></ProcessID>
// </ProductsCreateResponseContainer>
// </Response>
// </ApiResponseContainer>
// Parsing the response...
String RequestType = xmlResp.getChildContent("Request|RequestType");
String RequestAction = xmlResp.getChildContent("Request|RequestAction");
String RequestVersion = xmlResp.getChildContent("Request|RequestVersion");
String ProcessedAt = xmlResp.getChildContent("Request|ProcessedAt");
String Result = xmlResp.getChildContent("Response|Result");
String ProcessID = xmlResp.getChildContent("Response|ProductsCreateResponseContainer|ProcessID");
}
}