React Native
React Native
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 React Native Downloads
import { CkDateTime, Crypt2, Http, HttpRequest, 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 uri = '/products';
const apiVersion = '2.0';
const http = new Http();
const 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.
const dt = new CkDateTime();
dt.setFromCurrentSystemTime();
const timestamp = dt.getAsTimestamp(true);
req.addHeader('TIME', timestamp);
console.log(`timestamp = ${timestamp}`);
const sbXml = new StringBuilder();
sbXml.loadFile('qa_data/xml/effectconnect/effconCreate.xml', 'utf-8');
console.log(`length = ${sbXml.length}`);
req.httpVerb = 'POST';
req.path = uri;
req.contentType = 'multipart/form-data';
try {
req.addStringForUpload('payload', 'effcon.xml', sbXml.getAsString(), 'utf-8');
} catch {
console.log(req.lastErrorText);
return;
}
// 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');
req.addHeader('SIGNATURE', crypt.macStringENC(sbStringToSign.getAsString()));
const resp = new HttpResponse();
try {
await http.httpSReqAsync('submit.effectconnect.com', 443, true, req, 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());
// 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...
const tagPath = '';
const requestType = xmlResp.getChildContent('Request|RequestType');
const requestAction = xmlResp.getChildContent('Request|RequestAction');
const requestVersion = xmlResp.getChildContent('Request|RequestVersion');
const processedAt = xmlResp.getChildContent('Request|ProcessedAt');
const result = xmlResp.getChildContent('Response|Result');
const processID = xmlResp.getChildContent('Response|ProductsCreateResponseContainer|ProcessID');
}